在bot框架对话框和formFlow中实施建议的操作 [英] Implementing suggested actions in bot framework dialog and formFlow

查看:82
本文介绍了在bot框架对话框和formFlow中实施建议的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var reply = activity.CreateReply("I have colors in mind, but need your help to choose the best one.");
reply.Type = ActivityTypes.Message;
reply.TextFormat = TextFormatTypes.Plain;

reply.SuggestedActions = new SuggestedActions()
{
    Actions = new List<CardAction>()
    {
        new CardAction(){ Title = "Blue", Type=ActionTypes.ImBack, Value="Blue" },
        new CardAction(){ Title = "Red", Type=ActionTypes.ImBack, Value="Red" },
        new CardAction(){ Title = "Green", Type=ActionTypes.ImBack, Value="Green" }
    }
};

如何在对话框和Formflow中实现以上代码.在消息控制器中执行此操作非常容易.

How can i implement the above code in a dialog and formflow. Its quite easy doing this in the message controller.

推荐答案

看看我关于您可以在PromptAsyncDelegate中发布带有建议操作的消息.包括您喜欢的任何逻辑以确定是否应使用建议的操作.如果您只想针对一个字段建议采取的措施,则可能看起来像这样:

You can post a message with suggested actions in your PromptAsyncDelegate. Include whatever logic you like in order to determine whether suggested actions should be used or not. If you only want suggested actions for one field, it could look something like this:

/// <summary>
/// Here is the method we're using for the PromptAsyncDelgate.
/// </summary>
private static async Task<FormPrompt> PromptAsync(IDialogContext context, FormPrompt prompt,
    MyClass state, IField<MyClass> field)
{
    var preamble = context.MakeMessage();
    var promptMessage = context.MakeMessage();

    if (field.Name == nameof(ColorField))
    {
        promptMessage.Text =
            "I have colors in mind, but need your help to choose the best one.";

        promptMessage.SuggestedActions = new SuggestedActions()
        {
            Actions = new List<CardAction>()
            {
                new CardAction(){ Title = "Blue", Type=ActionTypes.ImBack, Value="Blue" },
                new CardAction(){ Title = "Red", Type=ActionTypes.ImBack, Value="Red" },
                new CardAction(){ Title = "Green", Type=ActionTypes.ImBack, Value="Green" },
            }
        };
    }
    else
    {
        if (prompt.GenerateMessages(preamble, promptMessage))
        {
            await context.PostAsync(preamble);
        }
    }

    await context.PostAsync(promptMessage);

    return prompt;
}

如本文所述,您可以在表单生成器中包含PromptAsyncDelegate,如下所示:

As seen in the article, you include the PromptAsyncDelegate in your form builder like this:

var builder = new FormBuilder<MyClass>().Prompter(PromptAsync);

这篇关于在bot框架对话框和formFlow中实施建议的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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