【问题标题】:Cancel Or Exit from PromptDialog.Choice Flow in Microsoft Bot Framework在 Microsoft Bot Framework 中取消或退出 PromptDialog.Choice 流
【发布时间】:2018-05-30 08:28:58
【问题描述】:

我有 4 个选项的提示,最后一个选项是用户可以退出提示, 我想实现一些代码,以便机器人退出提示

Image

   PromptDialog.Choice(context, this.OnOptionSelected, new List<string>() { FlightsOption, HotelsOption, TrainOption, GobackOption }, "Sure..! Tell me what booking would like to make..?", "Not a valid option", 3);

在上图中,我已经实现了退出选项,如果用户选择退出,它将转到切换退出的情况。

我也尝试过 context.quit 但它会抛出错误

private async Task OnOptionSelected(IDialogContext context, IAwaitable<string> result)
    {
        try
        {
            string optionSelected = await result;

            switch (optionSelected)
            {
                case FlightsOption:
                    context.Call(new FlightDialog(), this.ResumeAfterOptionDialog);
                    break;

                case HotelsOption:
                    context.Call(new HotelsDialog(), this.ResumeAfterOptionDialog);
                    break;
                case TrainOption:
                    context.Call(new TrainDialog(), this.ResumeAfterOptionDialog);
                    break;
                case GobackOption:
                    //want some code here to quit the form
                    break;


            }
        }

【问题讨论】:

  • 请记住我们不在你的机器上:添加你的代码和一个明确的问题
  • 我编辑了我的代码,请看一下

标签: frameworks botframework bots


【解决方案1】:

首先,这不是表单流。这是及时的。 现在您可以执行类似的操作,或者像这样从堆栈中退出对话框

try
        {
            string optionSelected = await result;

            switch (optionSelected)
            {
                case FlightsOption:
                    context.Call(new FlightDialog(), this.ResumeAfterOptionDialog);
                    break;

                case HotelsOption:
                    context.Call(new HotelsDialog(), this.ResumeAfterOptionDialog);
                    break;
                case TrainOption:
                    context.Call(new TrainDialog(), this.ResumeAfterOptionDialog);
                    break;
                case GobackOption:
                    context.Done<object>(null);
                    break;


            }
        }

或者, 你可以告诉一些事情,然后在同一个对话框中等待其他消息,就像这样

 try
    {
        string optionSelected = await result;

        switch (optionSelected)
        {
            case FlightsOption:
                context.Call(new FlightDialog(), this.ResumeAfterOptionDialog);
                break;

            case HotelsOption:
                context.Call(new HotelsDialog(), this.ResumeAfterOptionDialog);
                break;
            case TrainOption:
                context.Call(new TrainDialog(), this.ResumeAfterOptionDialog);
                break;
            case GobackOption:
            await context.PostAsync("Ok, you came back. Now tell something new.");
            context.Wait(MessageReceivedAsync);
            break;
        }
    }

下一条消息会放在这里

public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
        {
            var message = await result;
            context.Wait(MessageReceivedAsync);
        }

【讨论】:

    猜你喜欢
    • 2017-04-27
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 2016-09-05
    • 2023-03-11
    • 1970-01-01
    • 2017-04-10
    • 1970-01-01
    相关资源
    最近更新 更多