Here it goes the example of how to implement a very simple “parrot” bot (that replies exactly what has been said to it) using Node.js with an Express server:
The below sample code is shared by one of the picky assist customer based in Chile.
constbodyParser=require('body-parser');constexpress=require('express');constapp=express();// enable extended to let nested POSTapp.use(bodyParser.urlencoded({extended:true}));// webhook set up// on production authenticate each POST - you could add a token to the URLapp.post('/webhook/', (req, res) => {// for development only - console log the post contentconsole.log(req.body);// builds the answer replicating the message sentlet reply = {'message-out':req.body['message-in'],'delay':0, };// Sends the reply - ENSURE a JSON response add JSON.stringfy just to be saferes.status(200).send(JSON.stringify(reply));});// Sets server port and logs message on successapp.listen(process.env.PORT||6000, () =>console.log('server is listening'));