Skip to content

Instantly share code, notes, and snippets.

@aminubakori
Last active June 7, 2017 19:51
Show Gist options
  • Save aminubakori/1802410e8d549a8dc3fa404631580493 to your computer and use it in GitHub Desktop.
Save aminubakori/1802410e8d549a8dc3fa404631580493 to your computer and use it in GitHub Desktop.
Webhook Example Node Server for Payant.ng
{
"name": "node-webhook-example",
"version": "1.0.0",
"description": "Webhook Example Node Server for Payant.ng",
"main": "webhook.js",
"scripts": {
"start": "node webhook.js"
},
"author": "Payant Support <[email protected]>",
"license": "ISC",
"dependencies": {
"body-parser": "^1.17.2",
"express": "^4.15.3"
}
}
/**
* Webhook Server
*
* @author Payant Support <[email protected]>
* @version 1.0.0
*/
const express = require('express');
const bodyParser = require('body-parser');
let app = express();
app.use(bodyParser.json());
app.get('/webhook', (req, res) => {
if(req.query.type === 'subscribe' && req.query.verify_token === 'VerifyToken') {
console.log("Token validation successful.");
res.status(200).send(req.query.challenge);
}else {
console.error("Token validation failed. Make sure the validation tokens match.");
res.sendStatus(403);
}
});
app.post('/webhook', (req, res) => {
var data = req.body;
console.log("Data received: ", data);
//Lastly send back a 200
res.sendStatus(200);
})
app.listen(process.env.PORT || 8005);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment