我想在Messenger上针对单个用户触发的回发发送多个回复.我一直在关注Messenger的开发者文档,但无法真正找到如何做到这一点.
我的代码结构与他们在网站上给出的教程非常相似,我有一个' handlePostback '函数,用于标识收到的回发并将其与一组预定义的有效负载进行比较,以找到' 响应 '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
}
Run Code Online (Sandbox Code Playgroud)
这是基本结构,现在我想发送多条消息作为回复一个回发.我做了一些挖掘,我发现解决方案可能是创建一个message []数组.但是我该怎么做?因为我的'响应'是通过该函数生成的,并且消息结构应该看起来像这样(我认为):
let body = {
recipient: {
id=sender_psid
},
messages: [ {
response1
},
{
response2
}
]
};
Run Code Online (Sandbox Code Playgroud)
我希望我能解释一下我的问题,如果我能提供更多细节,请告诉我!
json facebook node.js facebook-chatbot facebook-messenger-bot