Blog

Sample Parrot Bot using Node.js with an Express server

Sample Parrot Bot using Node.js with an Express server

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.

We are excited to hear how you are using picky assist , share your experience with us and  get $10 as credit in your picky assist account also your project will be published in our blog similar to this , send your project details to support@pickyassist.com along with the whatsapp number to test your project.

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'));

 

About the contributor 
We are www.inventures.cl a Chilean boutique consulting firm that accelerates digital transformations by developing new products and services with user-centered design and agile development.

Live Demo 
A more elaborated example of this implementation, including integration with dialogflow (to perform the natural language processing) can be found live here: https://api.whatsapp.com/send?phone=56933374001&text=Hola (Spanish Chat Bot)

Leave a Reply


Your email address will not be published. Required fields are marked *

Related Posts


June 6, 2019

Adding Widget Into WordPress

Adding Widget Into WordPress In this guide we will show how can add Picky Assist Chat Widget into a WordPress site in less than 5 minute. Watch Video Login into your WordPress Admin Account From the sidebar menu locate “Appearance” menu and click on it and from sub menu select “Editor” Editor may prompt for

May 29, 2019

Step By Step Getting Start Guide

Step By Step Getting Start Guide This guide will help you to get started with picky assist services , before getting start you must install and configure the picky assist bridge mobile app correctly in your mobile phone where the whatsapp, sms and call automation is required. You can refer following links , if you