As a beginner using a starter project from glitch, I have a project set up at this link:
I need help understanding how to obtain the message_broadcast_id and how to create it.
This is how I usually create a normal message:
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);
}
});
}
Handling messages:
// Message processing
app.post('/webhook', function (req, res) {
console.log(req.body);
var data = req.body;
// Ensure page subscription
if (data.object === 'page') {
// Iterate over each entry - can 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);
}
});
});
// Send back a 200 status code within 20 seconds to confirm receipt of callback
res.sendStatus(200);
}
});
Is the message id accessible via object event.message_broadcast_id?