Node JS
Sample Code in Node JS with Express Server
const bodyParser = require('body-parser');
const express = require('express');
const app = express();
// enable extended to let nested POST
app.use(bodyParser.urlencoded({extended: true}));
// webhook set up
// on production authenticate each POST - you could add a token to the URL
app.post('/webhook/', (req, res) => {
// for development only - console log the post content
console.log(req.body);
// builds the answer replicating the message sent
let reply = {
'message-out': req.body['message-in'],
'delay': 0,
};
// Sends the reply - ENSURE a JSON response add JSON.stringfy just to be safe
res.status(200).send(JSON.stringify(reply));
});
// Sets server port and logs message on success
app.listen(process.env.PORT || 6000, () => console.log('server is listening'));Node Js - Push API -Http method
Node Js - Unirest
Last updated
Was this helpful?