我是新手,我从故障中使用启动项目。 这是我项目的链接: https://glitch.com/edit/#!/lucky-spandex
你能解释一下如何获取message_broadcast_id以及如何创建它吗?
我创建的正常消息:
function callSendAPI(messageData) {
request({
uri: 'https://graph.facebook.com/v2.6/me/messages',
qs: { access_token: process.env.PAGE_ACCESS_TOKEN },
method: 'POST',
json: messageData
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var recipientId = body.recipient_id;
var messageId = body.message_id;
console.log("Successfully sent generic message with id %s to recipient %s",
messageId, recipientId);
} else {
console.error("Unable to send message.");
console.error(response);
console.error(error);
}
});
}
处理消息:
// Message processing
app.post('/webhook', function (req, res) {
console.log(req.body);
var data = req.body;
// Make sure this is a page subscription
if (data.object === 'page') {
// Iterate over each entry - there may be multiple if batched
data.entry.forEach(function(entry) {
var pageID = entry.id;
var timeOfEvent = entry.time;
// Iterate over each messaging event
entry.messaging.forEach(function(event) {
if (event.message) {
receivedMessage(event);
} else if (event.postback) {
receivedPostback(event);
}else {
console.log("Webhook received unknown event: ", event);
}
});
});
// Assume all went well.
//
// You must send back a 200, within 20 seconds, to let us know
// you've successfully received the callback. Otherwise, the request
// will time out and we will keep trying to resend.
res.sendStatus(200);
}
});
我应该在对象event.message_broadcast_id中获取消息ID吗?
答案 0 :(得分:0)
您需要在广播之前创建消息。
查看“creativeBroadcastMessage”函数
答案 1 :(得分:0)
我在邮件数据中输错了。我写了没有's'的消息而不是消息。