Book Image

Hands-On Chatbots and Conversational UI Development

By : Srini Janarthanam
Book Image

Hands-On Chatbots and Conversational UI Development

By: Srini Janarthanam

Overview of this book

Conversation as an interface is the best way for machines to interact with us using the universally accepted human tool that is language. Chatbots and voice user interfaces are two flavors of conversational UIs. Chatbots are real-time, data-driven answer engines that talk in natural language and are context-aware. Voice user interfaces are driven by voice and can understand and respond to users using speech. This book covers both types of conversational UIs by leveraging APIs from multiple platforms. We'll take a project-based approach to understand how these UIs are built and the best use cases for deploying them. We'll start by building a simple messaging bot from the Facebook Messenger API to understand the basics of bot building. Then we move on to creating a Task model that can perform complex tasks such as ordering and planning events with the newly-acquired-by-Google Dialogflow and Microsoft Bot framework. We then turn to voice-enabled UIs that are capable of interacting with users using speech with Amazon Alexa and Google Home. By the end of the book, you will have created your own line of chatbots and voice UIs for multiple leading platforms.
Table of Contents (11 chapters)

Building a two-way chatbot

So far, we have built a bot that can send SMS notifications to users at set time intervals. Although proactive, it is only communicating one way. The user is not able to send any request to the bot to change the nature or content of the message it is sending. Let's work on that.

To build a chatbot that can communicate both ways we need to do two things: build the chatbot into the web app and modify setup configurations in Twilio. To do these, follow these steps:

  1. Create an index.js file in the root directory of the project.
  2. Install the express and body-parser libraries. These libraries will be used to make a web app:
npm install body-parser --save
npm install express --save
  1. Create a web app in index.js:
// Two-way SMS Bot

const express = require('express')
const bodyParser = require('body-parser')
const twilio = require(...