如何在我每次键入exit或cancel时中断formflow? [英] How to break formflow in every moment i type exit or cancel?

查看:175
本文介绍了如何在我每次键入exit或cancel时中断formflow?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用BotFramework在.Net C#中创建一个聊天机器人.在我的一个对话框中,当我开始填写表格流时,直到我将填写所有流程时,我才能从流程表退出.是否存在退出和离开表格的可能性?

I'm creating a chatbot in .Net C# using BotFramework. In one of my dialog when i start to fill a form flow i cannot exit from flowform till in the moment i will fill all the flow . Exist any possibility to exit and to leave form ?

这是我的代码:

LuisDialog.cs:

LuisDialog.cs :

      [LuisIntent("balance")]
      public async Task balance(IDialogContext context, LuisResult result)
     {

        var balanca = new FormDialog<BalanceForm>(
                    new BalanceForm(),
                    BalanceForm.BuildForm,
                    FormOptions.PromptInStart,
                    result.Entities);
        context.Call<BalanceForm>(balanca, BalanceCompleted);

BalanceForm.cs

BalanceForm.cs

namespace BasicMultiDialog
{

[Serializable]
public class BalanceForm
{

    [Prompt("What is your contract number?")]
    public string contract;

    public static IForm<BalanceForm> BuildForm()
    {
        OnCompletionAsyncDelegate<BalanceForm> wrapUpRequest = async 
    (context, state) =>
        {




                        string wrapUpMessage = "Dear " + house.Firstname + "," + "your  balance is " + house.Balance;
                        await context.PostAsync(wrapUpMessage);


            }
        };
        return new FormBuilder<BalanceForm>().Message
        ("We have to ask you some information")


            .Field(nameof(contract), validate: async (state, response) =>
            {

                var result = new ValidateResult();


                    return result;

                }
            })

            .OnCompletion(wrapUpRequest)
            //.Confirm("Are you sure: Yes or No ")
            .Build();
          }

         }
      }

推荐答案

实际上,取消表单非常容易.如果键入"help"或"choices",则可以看到内置的表单命令列表,其中之一是"quit".您可以使用许多术语来退出,例如完成"或再见".如果要定义自己的术语,可以配置如下形式的命令:

Actually it's quite easy to cancel a form. If you type "help" or "choices" you can see a list of builtin form commands, and one of these is "quit." There are many terms you can use to quit such as "finish" or "bye." If you want to define your own terms, you can can configure the form commands like this:

var builder = new FormBuilder<BalanceForm>().Message
("We have to ask you some information")
    .Field(nameof(contract), validate: async (state, response) =>
    {
        var result = new ValidateResult();
        return result;
    })
    .OnCompletion(wrapUpRequest)

// Set the command term configuration on its own line
builder.Configuration.Commands[FormCommand.Quit].Terms = new[] { "exit", "cancel" };

return builder.Build();

请记住,取消表单时,将抛出FormCanceledException<T>.如果您不希望此消息显示抱歉,我的机器人代码有问题"之类的消息,则可以捕获如下异常:

Keep in mind that when a form is canceled, a FormCanceledException<T> is thrown. If you don't want this to display a message like "Sorry, my bot code is having an issue," you can catch the exception like this:

var balanca = new FormDialog<BalanceForm>(
            new BalanceForm(),
            BalanceForm.BuildForm,
            FormOptions.PromptInStart,
            result.Entities)
    .Catch<BalanceForm, FormCanceledException<BalanceForm>>((dialog, ex) =>
    {
        // Handle the cancellation here and return an IDialog<BalanceForm>
    });

这篇关于如何在我每次键入exit或cancel时中断formflow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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