从LUIS意图发送IForm [英] Sending an IForm from a LUIS intent

查看:53
本文介绍了从LUIS意图发送IForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在Visual Studio中运行一个聊天机器人,该聊天机器人使用Microsoft的bot框架以c#语言运行. 我将LUIS集成到该机器人中,我想知道如何制作它,以使FormFlow类似于

I currently have a chatbot running in visual studio using Microsoft's bot framework in the language c#. I integrated LUIS into the bot and I'm wondering how can I make it so that a FormFlow similar to this example appears on a specific intent.

到目前为止,这是我的表单的代码:

So far this is the code for my Form:

internal static IDialog<InfoGroup> MakeRootDialog()
    {
        return Chain.From(() => FormDialog.FromForm(InfoGroup.BuildForm));
    }
public enum GroupOptions
{
    A, B, C, D, E, F, G, H
};
[Serializable]
public class InfoGroup
{
    public GroupOptions? groupId;

    public static IForm<InfoGroup> BuildForm()
    {
        return new FormBuilder<InfoGroup>()
                .Message("Please select an option")
                .Build();
    }
};

我正在尝试通过如下的LUIS intent方法发送它:

And I'm trying to send it form my LUIS intent method like so:

[LuisIntent("SpecificGroup")]
    public async Task SpecificGroupIntent(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
    {
        await context.PostAsync(FormDialog.FromForm(InfoGroup.BuildForm));
        context.Wait(MessageReceived);
        return;
    }

这显然不是调用表单的正确方法,如何使表单显示为直接从我的SpecificGroupIntent()方法调用的响应? 任何帮助将不胜感激. 填写表格后,我要使用用户选择的选项来相应地显示文本.

This is obviously not the correct way to call the form, how can I make it so that a form appears as a response called directly from my SpecificGroupIntent() method? Any help will be greatly appreciated. After the form is filled I want to use the option that the user selected to display text accordingly.

推荐答案

您可以从luis意向方法调用表单流生成器,例如使用context.Call()方法从父对话框调用对话框.您还需要指定一种方法,该方法将在填写表单后执行.

You can invoke the formflow builder from a luis intent method like calling a dialog from a parent dialog using the context.Call() method. You will also need to specify a method that will be executed once the form is filled.

例如: 通过创建InfoGroup(您的表单)类型的FormDialog并指定要在其之后执行的方法来调用formbuilder.

Eg: Calling the formbuilder by creating a FormDialog of InfoGroup(Your form) type and specifying method to be executed after it.

InfoGroup form = new InfoGroup();    
FormDialog<InfoGroup> InfoGroupform = new FormDialog<InfoGroup>(form, InfoGroup.BuildForm, FormOptions.PromptInStart);
context.Call(InfoGroupform, InfoGroupFormSubmitted);

InfoGroupFormSubmitted是填写表单后将调用的方法.之所以需要它,是因为如果您使用context.Call()方法,则需要为其指定一个resumeAfter方法.在此InfoGroupFormSubmitted方法中,您可以仅确认表单是否正确填写,或者如果用户退出,则可以捕获异常并显示用户退出的位置.

InfoGroupFormSubmitted is the method that will be called once your form is filled. You need this because if you are using context.Call() method you need to specify a resumeAfter method for it. In this InfoGroupFormSubmitted method you can just give a confirmation if the form was correctly filled or if the user quit you can just catch the exception and show where the user quit.

public static async Task InfoGroupFormSubmitted(IDialogContext context, IAwaitable<InfoGroup> result)
{
        try
        {
             var query = await result;
             context.PostAsync("Your choice has been recorded.");
        } 
        catch (FormCanceledException<InfoGroup> e)
        {
              string reply;
              if (e.InnerException == null)
              {
                    reply = $"You quit on {e.Last}--maybe you can finish next time!";
              }
              else
              {
                    reply = $"Sorry, I've had a short circuit.  Please try again.";
              }
              context.Done(true);
              await context.PostAsync(reply);
        }
}

这篇关于从LUIS意图发送IForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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