您好,我正在尝试在Bot Framework V4的C#代码上执行此模板。 这是来自facebook的代码。
"payload": {
"template_type":"button",
"text":"<MESSAGE_TEXT>",
"buttons":[
<BUTTON_OBJECT>,
<BUTTON_OBJECT>,
...
]
}
这是我的尝试。我无法调试错误,因为它仅在Messenger上有效。任何帮助将不胜感激,谢谢。
Activity reply = stepContext.Context.Activity.CreateReply();
reply.ChannelData = JObject.FromObject(
new
{
attachment = new
{
type = "template",
payload = new
{
template_type = "button",
text = "xx",
buttons = new[]
{
new
{
type = "web_url",
title = "take test",
url = "xx",
messenger_extensions="true",
webview_height_ratio = "tall",
},
},
},
},
});
await stepContext.Context.SendActivityAsync(reply);
答案 0 :(得分:0)
您的代码看起来不错。确保Whitelist用于Facebook的所有URL。请注意,它们必须是https
URL。另外,除非将网站配置为Webview,否则您不需要按钮中的messenger_extensions和webview_height_ratio属性。
var reply = turnContext.Activity.CreateReply();
var attachment = new
{
type = "template",
payload = new
{
template_type = "button",
text = "Sign up for our mailing list!",
buttons = new[]
{
new
{
type = "web_url",
url = "https://mybot.azurewebsites.net/",
title = "Sign Up!"
},
},
},
};
reply.ChannelData = JObject.FromObject(new { attachment });
await turnContext.SendActivityAsync(reply, cancellationToken);
有关更多详细信息,请参见Button Templates上的Messengers文档。
希望这会有所帮助!