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

标签 node.js botframework

任何人都可以帮助我使用 Bot 框架在 Facebook channel 中包含 ListView 吗?我看到了如下所示的示例 List template 。我不知道这是否是我们需要提供附件的确切方式。我也不知道 Bot 框架 v4 中的 sourceEvent 方法的等效项。另一个有用的链接如下FB Messenger Message Template 。请参见下面给出的图像。我需要放置图像的链接,一旦我们单击该链接,它应该打开另一个页面,并且该图像应该是可单击的图像,如 C# Clickable HeroCard images 的示例中所示。使用点击属性。这两个功能都应该有效。我尝试使用HeroCard(但是需要打开的url存在CORS起源问题。我尝试使用Adaptivecard,但Facebook目前不支持它。所以,我想使用 Facebook 的列表模板。有没有办法实现这一点?

This is the actual requirement.

最佳答案

您可以通过 Microsoft BotFramework 将 Facebook 附件添加到事件的 channel 数据来发送 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"
                    }]
                }]
            }
        }
    }
});

希望这有帮助!

关于node.js - 使用Bot框架node.js V4的FB列表模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54663088/

相关文章:

javascript - Gulp 失败并返回 Unhandled 'error' 事件

javascript - NodeJS lambda Epipe错误

c# - 使用可等待附件 FormFlow 从 Bot 框架检索文件?

node.js - Mongoose _id 在保存前受影响

javascript - 具有查找功能的 mongodb 聚合

javascript - 带有 C# 后端的 Electron GUI

c# - 欢迎消息在网络聊天中不可见,但在模拟器中有效

node.js - 如何响应来自Bot Framework(直线客户端)的消息?

botframework - 为 LUIS.AI 创建 API 或使用 .JSON 文件以便为非技术用户训练机器人

javascript - 使用 JavaScript 时向 Bot Framework 添加断行