How to use Suggested actions in Dialog and form flow respectively in bot framework

对着背影说爱祢 提交于 2019-12-11 07:58:00

问题


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.


回答1:


Try creating a reply like:

    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);

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



来源:https://stackoverflow.com/questions/54311964/how-to-use-suggested-actions-in-dialog-and-form-flow-respectively-in-bot-framewo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!