使用Bot框架node.js V4的FB的列表模板

时间:2019-02-13 05:24:26

标签: node.js botframework

有人可以帮助我使用Bot框架在Facebook Channel中添加列表视图吗?我看到了示例,如此处List template所示。我不知道这是否是我们提供附件的确切方法。我也不知道Bot框架v4中的sourceEvent方法的等效项。另一个有用的链接如下FB Messenger Message Template。请参见下面的图像。我需要放置图像的链接,一旦我们单击链接,它应该打开另一个页面,图像也应该是可单击的图像,如 C# Clickable HeroCard images的示例,使用 tap属性。两种功能都应该起作用。我尝试使用 HeroCard (但是需要打开的网址存在CORS来源问题。我尝试使用自适应卡,但目前Facebook尚不支持。) ,我想使用Facebook的列表模板。总有办法实现吗?

This is the actual requirement.

1 个答案:

答案 0 :(得分:1)

通过将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.com/images/2019/02/10/travel/03update-snowfall2/03update-snowfall2-jumbo.jpg?quality=90&auto=webp",
                    "default_action": {
                      "type": "web_url",
                      "url": "https://www.nytimes.com/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.com/images/2019/02/17/travel/17Northern-Lights1/17Northern-Lights1-superJumbo.jpg?quality=90&auto=webp",
                    "default_action": {
                      "type": "web_url",
                      "url": "https://www.nytimes.com/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.com/images/2019/02/17/travel/17NewOrleans-5Places6/17NewOrleans-5Places6-jumbo.jpg?quality=90&auto=webp",
                    "default_action": {
                      "type": "web_url",
                      "url": "https://www.nytimes.com/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"
                    }]
                }]
            }
        }
    }
});

希望这会有所帮助!