Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Post endpoint to receive requests from Facebook
app.post('/webhook/', (req, res) => {
messaging_events = req.body.entry[0].messaging
for (i = 0; i < messaging_events.length; i++) {
event = req.body.entry[0].messaging[i];
// Check to see if the event was a message from
if (event.message && event.message.text) {
text = event.message.text
console.log(‘Heres\’s what the user said , text);
continue
}
// Check to see if the event was a postback for a Facebook event - https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/messaging_postbacks/
console.log(‘Hey this was a postback!)
continue
}
}
res.sendStatus(204);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment