C# 无法在Onturnasync方法中使用CancelAllDialogsSync方法

C# 无法在Onturnasync方法中使用CancelAllDialogsSync方法,c#,asp.net,botframework,azure-language-understanding,qnamaker,C#,Asp.net,Botframework,Azure Language Understanding,Qnamaker,我已经使用c#使用FrameworkV4创建了bot。我在it中集成了luis for exit功能,在我的机器人中,每当用户键入exit时,它都会将您从对话中带出来,整个机器人都会从beinging开始。我的案例机器人可以退出,但不能从beinging开始。我想我可以使用CancelallDialogAsync方法,但我无法在onturnasync方法中访问它,因为我已经为退出特性编写了代码 public override async Task OnTurnAsync(ITurnContext

我已经使用c#使用FrameworkV4创建了bot。我在it中集成了luis for exit功能,在我的机器人中,每当用户键入exit时,它都会将您从对话中带出来,整个机器人都会从beinging开始。我的案例机器人可以退出,但不能从beinging开始。我想我可以使用CancelallDialogAsync方法,但我无法在onturnasync方法中访问它,因为我已经为退出特性编写了代码

public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
    {
        var activity = turnContext.Activity;
       // var activity = turnContext.Activity;
        var recognizerResult = await _botServices.Dispatch.RecognizeAsync(turnContext, cancellationToken);

        // Top intent tell us which cognitive service to use.
        var topIntent = recognizerResult.GetTopScoringIntent();

        var attachments = new List<Attachment>();
        var reply = MessageFactory.Attachment(attachments);
        reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;


        // First, we use the dispatch model to determine which cognitive service (LUIS or QnA) to use.

        if (string.IsNullOrWhiteSpace(activity.Text) && activity.Value != null)
        {
            activity.Text = JsonConvert.SerializeObject(activity.Value);
        }
        if (turnContext.Activity.Text == "Yes")
        {

            await turnContext.SendActivityAsync($"Good bye. I will be here if you need me. ", cancellationToken: cancellationToken);
            await turnContext.SendActivityAsync($"Say Hi to wake me up.", cancellationToken: cancellationToken);
        }
        else  if (topIntent.intent == "OrderStatusintent")
            {
                reply.Attachments.Add(Cards.GetHeroCard6().ToAttachment());
                await turnContext.SendActivityAsync(reply, cancellationToken);
            }
        else if (topIntent.intent == "Exitintent")
        {
            await turnContext.SendActivityAsync($"Good bye. Say Hi if you need more help.", cancellationToken: cancellationToken);

        }

        else if (activity.ChannelId != "webchat")
        {
            await base.OnTurnAsync(turnContext, cancellationToken);
        }
        await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
        await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
    }
public override async Task OnTurnAsync(ITurnContext turnContext,CancellationToken CancellationToken=default(CancellationToken))
{
var activity=turnContext.activity;
//var activity=turnContext.activity;
var recognizerResult=wait _botServices.Dispatch.RecognizeAsync(turnContext,cancellationToken);
//Top intent告诉我们使用哪种认知服务。
var topIntent=recognizerResult.getTopScoringContent();
var attachments=新列表();
var reply=MessageFactory.Attachment(附件);
reply.AttachmentLayout=attachmentlayoututypes.Carousel;
//首先,我们使用分派模型来确定使用哪种认知服务(LUIS或QnA)。
if(string.IsNullOrWhiteSpace(activity.Text)&&activity.Value!=null)
{
activity.Text=JsonConvert.SerializeObject(activity.Value);
}
如果(turnContext.Activity.Text==“是”)
{
等待turnContext.SendActivityAsync($“再见,如果您需要我,我会在这里。”,cancellationToken:cancellationToken);
Wait turnContext.SendActivityAsync($“打招呼叫醒我。”,cancellationToken:cancellationToken);
}
else if(topIntent.intent==“OrderStatusintent”)
{
reply.Attachments.Add(Cards.GetHeroCard6().ToAttachment());
等待turnContext.SendActivityAsync(回复、取消令牌);
}
else if(topIntent.intent==“存在”)
{
Wait turnContext.SendActivityAsync($“再见,如果需要更多帮助,请打招呼。”,cancellationToken:cancellationToken);
}
else if(activity.ChannelId!=“webchat”)
{
wait base.OnTurnAsync(turnContext,cancellationToken);
}
等待ConversationState.SaveChangesSync(turnContext,false,cancellationToken);
等待UserState.SaveChangesSync(turnContext,false,cancellationToken);
}

我很难理解您的bot功能,但我相信您需要一个对话框上下文。我的bot结构与您的不同,但我有一个onMessage函数,它调用我的intent调度器并传递turnContext。我正在使用DialogSet(来自botbuilder对话框)通过(nodejs)创建对话框上下文

this.dialogs=newdialogset(this.dialogState)//在构造函数中
const dc=wait this.dialogs.createContext(turnContext)//在从onMessage调用的函数中
等待dc.cancelAllDialogs();//从任何我想取消的地方

我看不到您在哪里创建了对话框上下文,所以这可能就是您无法从onTurn处理程序调用此方法的原因。这可能是可能的,但无论我在哪里调用
cancelAllDialogs()
它要么来自此对话框上下文,要么来自瀑布式对话框,我正在使用步骤上下文并通过
stepContext.parent.cancelAllDialogs()
在父级取消,我没有这样做,但听起来您可以使用主动消息传递和基于计时器的功能来实现这一点。有些人可能有他们用于此的模板,但如果您可以尝试一个解决方案,然后让我们知道您在实现它时遇到了什么困难,那么您将有更多的机会得到响应。您好,我无法在onturnasync方法上使用它…他们有办法做到这一点吗@billovertonI我不确定,我只在onMessage上成功地做到了这一点