【发布时间】:2018-05-09 01:17:57
【问题描述】:
我想在 Messenger 上为单个用户触发的回发发送多个回复。我一直在关注 Messenger 的 developer documentation 并且真的找不到如何做到这一点。
我的代码结构与他们在网站上提供的教程非常相似,我有一个“handlePostback”函数,用于识别收到的回发并将其与一组预定义的有效负载进行比较以查找'response' JSON 对象。此响应将提供给“callSendAPI”,它将此 JSON 对象转换为将消息发送回 Messenger API 的基本格式。
function handlePostback(sender_psid,receivedPostback)
{ if(payload== 'defined_payload') {
response = {
text: 'Some text'
};
callSendAPI(sender_psid,response);
}
function callSendAPI(sender_psid,response) {
let body = {
recipient: {
id= sender_psid
},
message: response
};
// Followed by code for POST request to the webhook
}
这是基本结构,现在我想发送多条消息作为对一个回发的回复。我做了一些挖掘,我发现解决方案可能是创建一个 message [] 数组。但是我该怎么做呢?因为我的“响应”是通过该函数生成的,消息结构应该是这样的(我认为):
let body = {
recipient: {
id=sender_psid
},
messages: [ {
response1
},
{
response2
}
]
};
我希望我能解释我的问题,如果我能提供更多细节,请告诉我!
【问题讨论】:
标签: json node.js facebook facebook-messenger-bot facebook-chatbot