无法在Onturnasync方法中使用CancelAllDialogsAsync方法 [英] Unable to use CancelAllDialogsAsync method in Onturnasync method

查看:143
本文介绍了无法在Onturnasync方法中使用CancelAllDialogsAsync方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#使用框架v4制作了漫游器.我在其中集成了用于退出功能的luis,在我的机器人中,每当用户键入exit时,它将使您退出对话,并且整个bot将从存在开始.我的案例机器人可以退出,但无法从存在开始.我以为我可以使用CancelallDialogAsync方法,但无法在为退出功能编写代码的onturnasync方法中访问它.

I have bot made using framework v4 using c#. I have integrated luis in it for exit feature, in my bot when ever user type exit it will take you out from the conversation and the entire bot will start from beinging. I my case bot is able to exit but not able to start from beinging. I thought i can use CancelallDialogAsync method but i am not able make it accessible in onturnasync method where i have written code for exit feature.

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);
    }

推荐答案

在执行bot功能时,我有些困难,但是我相信您需要 dialog 上下文.我的机器人结构与您的机器人结构不同,但是我有一个onMessage函数,该函数调用我的意图分派器并传递turnContext.我正在使用DialogSet(来自botbuilder-dialogs)通过(nodejs)创建对话框上下文

I'm having a bit of a hard time following your bot function, but I believe you need a dialog context. My bot structure is different than yours, but I have an onMessage function which calls my intent dispatcher and passes the turnContext. I am using DialogSet (from botbuilder-dialogs) to create the dialog context via (nodejs)

this.dialogs = new DialogSet(this.dialogState) // in constructor

const dc = await this.dialogs.createContext(turnContext) // in function called from onMessage

await dc.cancelAllDialogs(); // from wherever I want to cancel

我在创建对话框上下文的任何地方都看不到,所以这可能就是为什么您无法从onTurn处理程序调用此方法的原因.可能是可行的,但在我调用cancelAllDialogs()的任何地方,要么是从此对话框上下文开始,要么是在瀑布对话框中,我正在使用步骤上下文并通过stepContext.parent.cancelAllDialogs()在父级取消.

I don't see anywhere where you have created a dialog context, so that may be why you are unable to call this method from your onTurn handler. It may be possible, but everywhere I call cancelAllDialogs() it's either from this dialog context, or from within a waterfall dialog I'm using the step context and cancelling at the parent level via stepContext.parent.cancelAllDialogs().

这篇关于无法在Onturnasync方法中使用CancelAllDialogsAsync方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆