-
-
Save andreas-optimizely/bfc774c7c8817b79ac8bc2f80b74fdea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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