微软博特Framework与Facebook的Messenger的按键消息 [英] Microsoft Bot Framework messages with buttons in Facebook Messenger

查看:386
本文介绍了微软博特Framework与Facebook的Messenger的按键消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个机器人使用C#微软博特框架工作,我想用行动按钮的Facebook Messenger的发送消息。我已经成功地创建了机器人,它部署并可以通过信使与它沟通,我现在努力改进机器人的反应的出现。我已经能够通过将卡信息到Message.Attachements创造的单卡和旋转木马,但我想还包括操作按钮。信使平台文档描述了按钮,通用模板在他们的发送参考但对我的生活我无法弄清楚如何强制机器人连接器发送按钮使者。这将会是巨大的,如果我可以把发送JSON API进入Message.ChannelData财产,但没有运气。有没有人设法让Messenger来显示来自博特框架按钮?

I'm working on a bot using the C# Microsoft Bot Framework and I'd like to send messages with action buttons to Facebook Messenger. I've successfully created the bot, deployed it and can communicate with it through Messenger and am now trying to refine the appearance of the bot's responses. I have been able to create single cards and carousels by putting the card info into Message.Attachements but I'd like to also include action buttons. The Messenger Platform docs describe button and "generic" templates in their Send API Reference but for the life of me I can't figure out how to coerce the Bot Connector to send buttons to Messenger. It'd be great if I could just put the Send API json into the Message.ChannelData property but no luck. Has anyone managed to get Messenger to show buttons from the Bot Framework?

推荐答案

要按钮添加到您的消息,您可以添加多个动作的附件。每个动作将被映射到通过连接器的按钮。多个附件将被映射到Facebook的Messenger中的旋转木马。下面是添加3个按钮的消息的示例。

To add buttons to your message, you can add multiple actions to the attachment. Each action will be mapped to a button by connector. Multiple attachments will be mapped into a carousel in Facebook messenger. Below is an example of adding 3 buttons to the message.

            var reply = context.MakeMessage();
            reply.Attachments = new List<Attachment>();

            var actions = new List<Microsoft.Bot.Connector.Action>();
            for (int i = 0; i < 3; i++)
            {
                actions.Add(new Microsoft.Bot.Connector.Action
                {
                    Title = $"Button:{i}",
                    Message = $"Action:{i}"
                });
            }

            reply.Attachments.Add(new Attachment
            {
                Title = "Choose one:",
                Actions = actions
            });

            await context.PostAsync(reply);

这篇关于微软博特Framework与Facebook的Messenger的按键消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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