Facebook Messenger中的共享按钮 [英] Share Button In Facebook Messenger
问题描述
是否可以在botframework中创建CardAction(按钮),使其在Facebook Messenger中用作共享按钮?
Is it possible to create a CardAction (button) in botframework which works as a share button in Facebook Messenger?
推荐答案
从Ezequiel提供的信息中ggy带,
Piggybacking off of the information provided by Ezequiel,
我创建了一个可工作的C#机器人,该机器人利用ChannelData
属性在Facebook Messenger上发送共享按钮.
I have created a working C# bot that utilizes the ChannelData
property to send a Share Button over Facebook Messenger.
请随时在此处查看存储库.
Models
目录包含所有类定义,这些类定义将用作Facebook Messenger共享按钮
The Models
directory contains all the class definitions that will act as the proper JSON format for a Facebook Messenger Share Button as is documented here.
然后,您只需使用所有组合的Model类创建一个新对象,并将其分配给对话框中新回复的ChannelData
属性,如下所示:
Then you just create a new object using all of your combined Model classes and assign it to the ChannelData
property of a new reply in your dialog like so:
来自ShareButtonDialog.cs
:
namespace Azure_Bot_Generic_CSharp
{
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Builder.Dialogs;
using Models;
[Serializable]
public class ShareButtonDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(this.MessageReceivedAsync);
}
public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
var message = await argument;
//create a reply message
var reply = context.MakeMessage();
//create a channel data object to act as a facebook share button
reply.ChannelData = new FacebookChannelData()
{
Attachment = new FacebookAttachment()
{
Payload = new FacebookGenericTemplate()
{
Elements = new object[]
{
new FacebookGenericTemplateContent()
{
Buttons = new[]
{
new FacebookShareButton()
}
}
}
}
}
};
//send message
await context.PostAsync(reply);
var reply2 = context.MakeMessage();
reply2.Text = "This is a message after the Share Button template.";
await context.PostAsync(reply2);
//wait for more messages to be sent here
context.Wait(MessageReceivedAsync);
}
}
}
这将产生所需的输出:
请注意,如果您打算使用该项目,则需要在Web.config文件中填写自己的Bot应用ID和密码.
这篇关于Facebook Messenger中的共享按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!