Last active
January 16, 2018 10:23
-
-
Save MarcL/29d80ff5036626d43b1819fea0ccbec8 to your computer and use it in GitHub Desktop.
Example of Node.js + Express server to parse url parameters and respond with Chatfuel text messages
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
const express = require('express'); | |
const app = express(); | |
// Call this from JSON API like this: | |
// | |
// https://myserver.com/united+states+of+america/12345 | |
// | |
app.get('/:country/:productId', (request, response) => { | |
// Get the country and productId | |
// NOTE: There is no error checking here so it assumes that the parameters are always passed | |
const {country, productId} = request.params; | |
// Respond with Chatfuel / Messenger text messages | |
response.json({ | |
messages: [ | |
{text: `Country is ${country}`}, | |
{text: `Product ID is ${productId}`}, | |
] | |
}); | |
}); | |
app.listen(process.env.PORT || 8080, () => { | |
console.log('Your app is listening on port ' + listener.address().port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment