使用Bot框架node.js V4的FB列表模板
任何人都可以帮助我使用Bot框架在Facebook频道中包含列表视图?我看到这里显示的例子List template。我不知道这是否是我们需要提供附件的确切方式。另外,我不知道Bot framework v4中sourceEvent方法的等价物。另一个有用的链接如下FB Messenger Message Template。请参见下面的图片。我需要为图像添加链接,一旦我们点击链接,它应该打开另一个页面,图像应该是可点击的图像,如使用tap属性的C#Clickable HeroCard images示例中所示。两种功能都应该有效。我尝试使用HeroCard(但需要打开的网址有CORS原因问题。我尝试使用自适应卡但截至目前在Facebook上都不支持。所以,我想在Facebook上使用列表模板。无论如何都有实现这个?
回答如下:您可以通过将Facebook附件添加到活动的频道数据,通过Microsoft BotFramework发送Facebook列表模板。似乎不支持list
模板类型,但您可以将类型设置为generic
并向附件添加多个元素以获得相同的结果。请参阅下面的示例。
await turnContext.sendActivity({
channelData: {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [
{
"title": "Three Strategies for Finding Snow",
"subtitle": "How do you plan a ski trip to ensure the best conditions? You can think about a resort’s track record, or which have the best snow-making machines. Or you can gamble.",
"image_url": "https://static01.nyt/images/2019/02/10/travel/03update-snowfall2/03update-snowfall2-jumbo.jpg?quality=90&auto=webp",
"default_action": {
"type": "web_url",
"url": "https://www.nytimes/2019/02/08/travel/ski-resort-snow-conditions.html",
"messenger_extensions": false,
"webview_height_ratio": "tall"
},
"buttons": [{
"type":"element_share"
}]
},
{
"title": "Viewing the Northern Lights: ‘It’s Almost Like Heavenly Visual Music’",
"subtitle": "Seeing the aurora borealis has become a must-do item for camera-toting tourists from Alaska to Greenland to Scandinavia. On a trip to northern Sweden, the sight proved elusive, if ultimately rewarding.",
"image_url": "https://static01.nyt/images/2019/02/17/travel/17Northern-Lights1/17Northern-Lights1-superJumbo.jpg?quality=90&auto=webp",
"default_action": {
"type": "web_url",
"url": "https://www.nytimes/2019/02/11/travel/northern-lights-tourism-in-sweden.html",
"messenger_extensions": false,
"webview_height_ratio": "tall"
},
"buttons": [{
"type":"element_share"
}]
},
{
"title": "Five Places to Visit in New Orleans",
"subtitle": "Big Freedia’s rap music is a part of the ether of modern New Orleans. So what better authentic travel guide to the city that so many tourists love to visit?",
"image_url": "https://static01.nyt/images/2019/02/17/travel/17NewOrleans-5Places6/17NewOrleans-5Places6-jumbo.jpg?quality=90&auto=webp",
"default_action": {
"type": "web_url",
"url": "https://www.nytimes/2019/02/12/travel/big-freedia-five-places-to-eat-and-visit-in-new-orleans.html",
"messenger_extensions": false,
"webview_height_ratio": "tall"
},
"buttons": [{
"type":"element_share"
}]
}]
}
}
}
});
希望这可以帮助!