Skip to content

Instantly share code, notes, and snippets.

@MarcL
Last active January 16, 2018 10:23
Show Gist options
  • Save MarcL/29d80ff5036626d43b1819fea0ccbec8 to your computer and use it in GitHub Desktop.
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
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