我正在看一些像“卫报”一些非常流行的机器人,我注意到,每当你从它得到一个通用的模板回复它也会显示一些快速回复按钮(见附图)。 “卫报机器人”是如何实现这一目标的?他如何将快速回复和通用模板结合起来?它必须涉及两条消息。Facebook信使平台:通用模板与快速回复
0
A
回答
1
我已经实现在对的NodeJS机器人,我使用所谓messenger-bot
节点模块,可以更容易地调用信使机器人API。这里是我的自定义代码,您
const http = require('http')
const https = require('https')
const Bot = require('messenger-bot')
var bot = new Bot({
token: 'your FB app token',
verify: 'VERIFY_TOKEN'
})
bot.on('postback', (payload, reply) => {
var postback = payload.postback.payload;
if (postback == "yes") {
function getQuickReplies() {
console.log("in next function");
var quick_list = {
"text": "Check the next article?",
"quick_replies": [{
"content_type": "text",
"title": "More stories",
"payload": "more stories"
},
{
"content_type": "text",
"title": "Sport",
"payload": "sport"
},
{
"content_type": "text",
"title": "Business",
"payload": "business"
}
]
};
bot.getProfile(payload.sender.id, (err, profile) => {
if (err) throw err
text = quick_list;
bot.sendMessage(payload.sender.id, text) {//this prints quick replies
console.log("sending message");
}
});
}
//calling generic template
var generic_temp = "message": {
"attachment": {
-- - your code-- -
}
}; //generic template refer - https://developers.facebook.com/docs/messenger-platform/send-api-reference/generic-template
bot.getProfile(payload.sender.id, (err, profile) => {
if (err) throw err
bot.sendMessage(payload.sender.id, generic_temp) {//this prints generic template
console.log("sending message");
}
});
//calling the quick replies once the generic template is sent
getQuickReplies(); //to avoid async execution issue, we will have to put this in a function.
}
});
引用 - Generic template,Quick replies,messenger-bot npm
希望这有助于!快速编码;)
0
快速回复通常伴随着一个'文本'属性,在快速回复之前发送文本消息。看起来你可以用任何模板替代它。例如,以下是具有快速回复的通用模板轮播的请求正文:
{
"recipient":{
"id":"{{PSID}}"
},
"messaging_type": "response",
"message":{
"quick_replies": [
{
"content_type":"text",
"title":"Quick Reply 1",
"image_url":"https://raw.githubusercontent.com/fbsamples/messenger-platform-samples/master/images/Messenger_Icon.png",
"payload":"payload1"
},
{
"content_type":"text",
"title":"Quick Reply 2",
"payload":"payload2"
}
],
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"elements":[
{
"title":"This is a generic template",
"subtitle":"Plus a subtitle!",
"image_url":"https://raw.githubusercontent.com/fbsamples/messenger-platform-samples/master/images/Messenger_Icon.png",
"buttons":[
{
"type":"postback",
"title":"Postback Button",
"payload":"<POSTBACK_PAYLOAD>"
}
]
},
{
"title":"Another generic template",
"subtitle":"Plus a subtitle!",
"image_url":"https://raw.githubusercontent.com/fbsamples/messenger-platform-samples/master/images/Messenger_Icon.png",
"buttons":[
{
"type":"postback",
"title":"Postback Button",
"payload":"<POSTBACK_PAYLOAD>"
}
]
},
{
"title":"And another!",
"subtitle":"Plus a subtitle!",
"image_url":"https://raw.githubusercontent.com/fbsamples/messenger-platform-samples/master/images/Messenger_Icon.png",
"buttons":[
{
"type":"postback",
"title":"Postback Button",
"payload":"<POSTBACK_PAYLOAD>"
}
]
}
]
}
}
}
}
相关问题
- 1. Resharper快速修复模板
- 2. 通用模板image_url在Messenger中未加载 - Facebook Messenger平台
- 3. 快速回复
- 4. 在angularjs中使用快速模板
- 5. 快速回复或与沃森对话
- 6. 快速Web应用程序开发ASP.net与开源平台
- 7. Facebook的:如何通过Facebook平台
- 8. 在线交易平台使用PayPal快速结账
- 9. 用于与Android应用程序通信的Web服务平台
- 10. Facebook开发人员JSON格式快速回复
- 11. 快速回复在Messenger Bot欢迎信息中工作吗?
- 12. 回复内联使用Outlook模板
- 13. iOS 8快速Soap Web服务通信
- 14. 快速线程间通信机制
- 15. 通信协议/委托快速错误
- 16. 如何编辑PyDev快速修复模板?
- 17. Facebook喜欢应用平台
- 18. Tizen平台的Facebook访问(使用JS)
- 19. 从字符串快速渲染模板
- 20. 快速报告别名X模板
- 21. “在快速角度节点模板Render
- 22. 线程1:信号SIGABRT与快速segue
- 23. Ruby on Rails与Facebook平台的书籍!
- 24. 我只需要使用快速渲染的模板语言?
- 25. 使用布局呈现玉石模板(无快速)
- 26. Netbeans平台简单的窗口通信
- 27. 跨平台Java中的串口通信?
- 28. 任何人使用Laravel与Facebook Messenger平台API?
- 29. 服务器端渲染与痛饮模板,反应,快速
- 30. Twitter快速回复 - Twitter4J(Java)示例
该博客发布第一个附件,然后是菜单。那么? –
它的工作原理是什么?它首先发送通用模板,然后快速回复?但在快速回复中,您必须指定标题和标题不能为空。 –
那么?他们已经指定了标题:) –