如何在bot框架中分别使用Dialog和Form Flow中的建议动作 [英] How to use Suggested actions in Dialog and form flow respectively in bot framework

查看:99
本文介绍了如何在bot框架中分别使用Dialog和Form Flow中的建议动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
    var cli = new ConnectorClient(new Uri(activity.ServiceUrl));
    var activity = await result as IMessageActivity;

    await context.PostAsync($"{activity.Text}");

    activity.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" }
        }
    };

    await context.PostAsync(activity);

    context.Wait(MessageReceivedAsync);
}

我想让机器人向用户建议操作,我需要在对话框中执行此操作,有时还需要在表单流程中执行此操作.我一直无法弄清楚.当我在消息控制器中尝试时,它实际上起作用了.

I want to make the bot suggest action to user, i need to do this in the dialog and also sometimes in form flow. i have not been able to figure it out. It actually worked when i tried in the message controller.

推荐答案

尝试创建如下答复:

    var activity = await result as Activity;
    var reply = activity.CreateReply("I have colors in mind, but need your help to choose the best one.");

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

    await context.PostAsync(reply);

    context.Wait(MessageReceivedAsync);

您应该可以将其粘贴到您的MessageReceivedAsync方法中,并且应该可以使用.您也不需要创建ClientConnector.

you should be able to paste this into you MessageReceivedAsync method and it should work. You also do not need to create your ClientConnector.

这篇关于如何在bot框架中分别使用Dialog和Form Flow中的建议动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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