37,19 €
Build over 8 chatbots and conversational user interfaces with leading tools such as Chatfuel, Dialogflow, Microsoft Bot Framework, Twilio, Alexa Skills, and Google Actions and deploying them on channels like Facebook Messenger, Amazon Alexa and Google Home
This book is for developers who are interested in creating interactive conversational UIs/Chatbots. A basic understanding of JavaScript and web APIs is required.
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.
This is a practical book, where each chapter focuses on a chatbot project. The chapters take a step-by-step approach to help you build intelligent chatbots that act as personal assistants.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 264
Veröffentlichungsjahr: 2017
BIRMINGHAM - MUMBAI
Copyright © 2017 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: December 2017
Production reference: 1261217
ISBN 978-1-78829-466-9
www.packtpub.com
Author
Srini Janarthanam
Copy Editor
Safis Editing
Reviewer
Vamsi Venigalla
Project Coordinator
Sheejal Shah
Commissioning Editor
Kunal Chaudhari
Proofreader
Safis Editing
Acquisition Editor
Siddharth Mandal
Indexer
Pratik Shirodkar
Content Development Editor
Arun Nadar
Production Coordinator
Melwyn D'sa
Technical Editor
Prajakta Mhatre
Srini Janarthanam is an expert in conversational systems and has been working in the field for over 15 years. He has led and worked on several projects, building conversational systems for a variety of domains including tourism, healthcare, and education. He obtained doctorate in Philosophy (PhD) from the University of Edinburgh for his work in Artificial Intelligence and Natural Language Processing. He is currently the co-founder and director of Chatomate, a UK brand building tailored chatbots, AI, and automation solutions for businesses. Previously, he worked as a research associate at Heriot-Watt University and the University of Edinburgh. He has published over 50 articles and papers in online chatbot magazines, journals, and international research conferences.
Vamsi Venigalla is a technology leader with over 12 years of experience in building technology organizations, strategic planning, rolling out multiple transformational platforms/products, IT program and project management, strategy and transformation (business, people, process, and technology), and delivering results for various business functions across mobile, sourcing, financial systems, HR, retail and supply chain in the food production and manufacturing domains. Vamsi graduated with a master's degree in computer science from North Carolina State University, NC.
For support files and downloads related to your book, please visit www.PacktPub.com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/dp/1788294661.
If you'd like to join our team of regular reviewers, you can e-mail us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products!
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
Introduction
Conversational user interfaces
A brief history of chatbots
Recent developments
Architecture of a conversational user interface
Classification
Applications
Developer's toolkit
Mockup tools
Channels
Chatbot development tools
Analytics
Natural Language understanding
Directory services
Monetization
Benefits
Chatbots are here to stay
Lets get started!
References
Tour Guide for Your City
Getting started
Building your first bot
Basic building blocks
Blocks
Cards
Buttons
Plugins
Attributes
Default blocks
Next steps
More cards
Image
Audio
Video
Quick replies
Gallery
List
Navigation
Buttons
Go to block cards
Managing context
User input cards
Setting user attributes
Default contextual variables
Understanding natural language
Default block
Backend processing
Broadcasting
Bot templates
Analytics
Summary
References
Let's Talk Weather
Conversational tasks
Conversational design
Backend tasks
Getting weather data
Getting the API key
Trying your key
Building the backend interface
Implementing the chatbot
Creating a chatbot web service
Publishing on Facebook Messenger
Creating a Facebook Page
Creating a username
Creating a Facebook App
Creating a Facebook interface web app
Connecting the Facebook App and interface app
Testing your chatbot
Adding more testers
Making it public
More Facebook message formats
Content types
Image attachments
Audio attachments
Video attachments
Files
Templates
Button template
List template
Generic template
Summary
References
Building a Persona Bot
Introducing Dialogflow
Setting up Dialogflow
Creating a basic agent
Deploying the chatbot
Website integration
Facebook integration
Context
Entities
System entities
Rich response formats
Importing and exporting agents
Exporting, restoring, and importing agents
Exporting and importing intents and entities
Fulfillments
Summary
References
Let's Catch a Train
Exploring Transport API
Creating a developer account
Exploring the dataset
Train stations near you
Response
Trains in the area
Response
Live departures
Response
Station timetables
Response
Service timetables
Response
Conversational design
Nearest station
Next train
Time of arrival
Building a simple SMS bot
Getting started
Setting up the dashboard
Simple Message Sender
My train notifier
Scheduling tasks
Building a two-way chatbot
Understanding users' utterances
Creating an API.AI agent
Create a Node.js interface to the API.AI agent
Integrating API.AI agent to SMS chatbot
Summary
References
Restaurant Search
MS Bot Framework
Channel emulator
Building a bot
Deploying your bot
More message types
Sending more than one message per turn
Prompting users for information
Rich messages
Conversation flow
Responding to user utterances
Keeping context intact
Context switching
Contextual NLU
Ending the conversation
Conversational state
Getting started with Zomato
Getting data from Zomato
Restaurant search bot
Connecting to Skype
Summary
References
The News Bot
Getting started with the Twitter app
Building your first Twitter bot
Exploring the Twitter SDK
Updating your status
Retweet to your followers
Searching for tweets
Exploring a news data service
Setting up NewsAPI
Building a Twitter news bot
Building a personalized news bot
Creating a database of user interests
Accessing the user interests database
Informing the bot of user interests
Summary
References
My TV Guide
Amazon Alexa
Warming up with a quotes bot
Configuring your skill
Interaction model
Conversation manager - quotes
Test on Alexa
My TV guide
Building the interaction model
Setting up the TV skill server
Testing the TV skill
Built-in intents and slot types
Summary
References
My Man Friday
Todoist
Getting the key
Adding a task
Retrieving all tasks for the day
Building an action
Building a Dialogflow agent
Creating a web app
Testing the agent on Dialogflow
Integrating with Google Assistant
Test on Google Home
Summary
Conclusion
References
More Resources
Articles
List of conferences
List of magazines
Groups on social media
Building chatbots is fun. Although chatbots are just another kind of software, they are very different in terms of the expectations that they create in users. Chatbots are conversational. This ability to process language makes them project a kind of human personality and intelligence, whether we as developers intend it to be so or not. To develop software with a personality and intelligence is quite challenging and therefore interesting.
This is a book for programmers who are interested in exploring the world of conversational user interfaces. This book is organized as eight chatbot projects that will introduce the ecosystem of tools, techniques, concepts, and even gadgets relating to conversational interfaces. We will start exploring basic chatbots using button interfaces and move toward using text utterances and finally voice. We will begin with a no-code platform to build our first chatbot and move on to exploring libraries and services to program the modules ourselves. Every chapter is a unique project with the objective of building a conversational interface to a data source. We will seek to understand the data, identify conversational tasks, carry out conversation design, and finally follow step-by-step instructions to implement the interface.
Chapter 1, Introduction, begins by teaching you what conversational user interfaces are, and their history and recent developments. We will then explore their basic architecture, applications, and benefits, and some factors that suggest why conversational interfaces are here to stay.
Chapter 2, Tour Guide for Your City, explores how to build chatbots without having to code. We will explore a development and hosting platform called Chatfuel, using which we will develop a tour guide for your city. We will design and build a simple button-based chatbot and learn how to deploy the chatbot to Facebook Messenger, one of the most popular channels for chatbots.
Chapter 3, Let's Talk Weather, follows on to build a chatbot for the same channel, but by building it from scratch this time, using Java and Node.js. We will build a chatbot that can tell us about the weather using an open data source called OpenWeatherAPI, host it as a Cloud application, and link it to a Facebook App that connects to a Facebook Page. We will explore Facebook Pages and the Messenger SDK from the perspective of building and deploying chatbots.
Chapter 4, Building a Persona Bot, moves away from button-based chatbots to ones that can understand natural language. We will explore a popular tool called API.AI (now known as Dialogflow) which can be used to build chatbots that can understand natural language. We will build a persona bot that emulates a popular personality, Albert Einstein. We will then take a look at how to integrate the chatbot into a website and Facebook Messenger.
Chapter 5, Let's Catch a Train, delves into a more traditional channel of communication—Short Messaging Service (SMS). We will analyze how to build a chatbot for the SMS channel. Using a data service called Transport API, we will build a chatbot that can talk about train schedules over SMS. We will also integrate an API.AI module for the chatbot in order to allow it to understand what the user says.
Chapter 6, Restaurant Search, seeks to build a chatbot using Microsoft Bot Builder. This is fast becoming a popular tool for building bots and can be used to design an efficient conversation manager, rather than building it from scratch, as we did previously. We will build a chatbot to search for restaurants using a data service called Zomato. This will then be exposed on the Skype channel.
Chapter 7, The News Bot, explains a totally different channel of engagement—Twitter. We will develop a Twitter bot that can listen to the tweets of users, understand their interests, and send them personalized news on an hourly basis by connecting to a data source called the News API.
Chapter 8, My TV Guide, seeks to understand the rise of voice-activated bots like Alexa. We will then build an Alexa skill to talk about your TV schedule. We will build a skill that can access the TV schedule data from the TVMaze data service and respond to user requests made over Amazon Echo.
Chapter 9, My Man Friday, continues working on voice bots and builds a Google Assistant action. This action will allow users to manage their to-do list using their Google Home device. We will build a Cloud app that will integrate with the Todoist online service to create tasks and retrieve pending tasks.
Appendix, More Resources, explains various articles, list of magazines, list of conferences and so on to gain more knowledge about the chatbots.
Here are some tools that we use extensively throughout the book. I recommend that you get them installed on your computer and get acquainted with them, as that will help you as we move through the projects:
Heroku
: Heroku is a cloud platform that allows you to host your web apps in the cloud. To get started, sign up to a free account at
www.heroku.com
and install the Heroku command-line tool from
https://devcenter.heroku.com/articles/heroku-cli
. You may also want to learn how to deploy apps on Heroku. I recommend that you go through some of the tutorials at
https://devcenter.heroku.com/start
.
Git
: Git is a version control tool that you might be familiar with. We will use Git extensively as it is part of the Heroku process. You will have to install the Git command line on your system. You should be able to find it at
https://git-scm.com/downloads
.
Node.js
: Node.js is a JavaScript runtime that we need to build web apps in most of our projects. You can find it at
https://nodejs.org/en/download/
.
Java SDK and Eclipse
: Java 1.8 is used to build the chatbot in
Chapter 3
,
Let's Talk Weather
. You need to install the Java SDK and the development environment called Eclipse to follow the instructions in the chapter. Alternatively, you can try to code the chatbot using Node.js or another programming language supported by Heroku. You can find Java 1.8 at
http://www.oracle.com/technetwork/java/javase/downloads/index.html
and Eclipse at
https://www.eclipse.org/downloads/
.
This book is for developers who are interested in creating interactive conversational UIs/chatbots. You need to be able to program in Node.js and Java. Experience in using Node.js libraries such as request and express, and a basic understanding of tools such as Git and Heroku CLI will be helpful.
Feedback from our readers is always welcome. Let us know what you think about this book--what you liked or disliked. Reader feedback is important to us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply email [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you. You can download the code files by following these steps:
Log in or register to our website using your e-mail address and password.
Hover the mouse pointer on the
SUPPORT
tab at the top.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box.
Select the book for which you're looking to download the code files
Choose from the drop-down menu where you purchased this book from.
Click on
Code Download
.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR / 7-Zip for Windows
Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Hands-On-Chatbots-and-Conversational-UI-Development. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code--we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at [email protected] with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.
The age of intelligent machines has arrived, and conversational interfaces are leading the charge. Over the past couple of years, we have been swarmed by a number of new kinds of machines and software collectively known as bots. Bots are automated hardware or software machines that are powered by the advances in Artificial Intelligence (AI) technologies. Recent developments in machine learning algorithms, such as deep learning and deep reinforcement learning, have improved the performance of AI tasks such as Automatic Speech Recognition (ASR), Natural Language Understanding (NLU), Text to Speech Synthesis (TTS), and Image Recognition. This has accelerated humankind's journey toward the technological singularity, the point in time when AI surpasses natural human intelligence by leaps and bounds.
One of the long-term goals in the field of AI is to build computer systems that can have human-like conversations with users. With recent advances in AI technologies, we are now one step closer to achieving this goal. Now, it is no longer fictional that we are able to interact with devices and gadgets in our homes and offices using nothing but voice. We still have a long way to go toward creating standards and building digital beings that are capable of seamless natural language conversation. However, a recent surge in interests and massive investments in pursuing these ideas suggest that we are on track toward evolving such a global standard. If you are excited about the recent developments in AI and automation technologies, this book is for you. We will embark on a journey toward a point in time in the future that the design guru Mark Curtis calls conversational singularity, when conversational devices disappear and conversation between man and machine is seamless and natural.
This is a book for programmers beginning to build conversational interfaces. Today, basic button-based chatbots can be built without even having to write a single line of code. In this book, that is where we will start. We will gradually move toward more complex and flexible architectures, and we will explore channels to use, such as Facebook Messenger, SMS, and Twitter. We will also be exploring tools for understanding natural language and conversation management as we proceed. Finally, we will end our journey by building voice-enabled bots on platforms such as Amazon Alexa and Google Assistant.
Conversational user interfaces are as old as modern computers themselves. ENIAC, the first programmable general-purpose computer, was built in the year 1946. In 1950, Alan Turing, a British computer scientist, proposed to measure the level of intelligence in machines using a conversational test called the Turing test. The test involved having the machine compete with a human as a dialogue partner to a set of human judges (yet another human). The judges would interact with each of the two participants (the human and the machine) using a text type interface that is not unlike most of the modern messaging chat applications. Over chat, the judges were supposed to identify which of the two participants was the machine. If at least 30% of the judges couldn't differentiate between the two participants, the machine was considered to have passed the test. This was one of the earliest human thoughts on conversational interfaces and their bearing on the intelligence levels of machines that have such capabilities. However, attempts to build such interfaces have not been very successful for several following decades.
For about 35 years, since the 1980s, Graphical User Interfaces (GUI) have been dominating the way in which we have been interacting with machines. With recent developments in AI and growing constraints such as the shrinking size of gadgets (from laptops to mobile phones), reducing on-screen real estates (smart watches), and the need for interfaces to become invisible (smart home and robots), conversational user interfaces are once again becoming a reality. For instance, the best way to interact with mobile robots that are distributed gadgets in smart homes would be using voice. The system should, therefore, be able to understand the users' requests and responses in natural human language. Such capabilities of systems can reduce human effort in learning and understanding current complex interfaces.
Conversational user interfaces have been known under several names: natural language interfaces, spoken dialogue systems, chatbots, intelligent virtual agents, virtual assistants, and so on. The actual difference between these systems is in terms of the backend integrations (for example, databases, and task/control modules), modalities (for example, text, voice, and visual avatars), and channels they get deployed on. However, one of the common themes among these systems is their ability to interact with users in a conversational manner using natural language.
The origins of modern chatbots can be traced back to 1964 when Joseph Weizenbaum at Massachusetts Institute of Technology (MIT) developed a chatbot called Eliza. It used simple rules of conversation and rephrased most of what the users said to simulate a Rogerian therapist. While it showed that naive users may be fooled into thinking that they are talking to an actual therapist, the system itself did not understand the user's problem. Following this, in 1991, the Loebner prize was instituted to encourage AI researchers to build chatbots that can beat the Turing test and advance the state of AI. Although no chatbots beat the test until 2014, many notable chatbots won prizes for winning other constrained challenges. These include ALICE, JabberWacky, Rose, and Mitsuku. However, in 2014, in a Turing test competition to mark the 60th anniversary of Alan Turing's death, a chatbot called Eugene Goostman, portraying a 13 year old kid, managed to fool 33% of the judges—thereby beating the test. Artificial Intelligence Markup Language (AIML) and ChatScript were developed as a way to script the knowledge and conversational content for most of these chatbots. Scripts developed using these scripting languages can then be fed into interpreters to create conversational behavior. Chatbots developed to beat the Turing test were largely chatty with just one objective—to beat the Turing test. This was not considered by many as advancement in AI or toward building useful conversational assistants.
On the other hand, research in artificial intelligence, specifically in machine learning and natural language processing, gave rise to various conversational interfaces such as question answering systems, natural language interfaces to databases, and spoken dialogue systems. Unlike chatbots built to beat the Turing test, these systems had very clear objectives. Question answering systems processed natural language questions and found answers in unstructured text datasets. Natural Language Interfaces to Database Systems (NLIDBS) were interfaces to large SQL databases that interpreted database queries posed in a natural language such as English, converted them into SQL, and returned the hits as response. Spoken Dialogue Systems (SDS) were systems that could maintain contextful conversations with users to handle conversational tasks such as booking tickets, controlling other systems, and tutoring learners. These were the precursors of modern chatbots and conversational interfaces.
In 2011, Apple released an intelligent assistant called Siri as part of their iPhones. Siri was modeled to be the user's personal assistant, doing tasks such as making calls, reading messages, and setting alarms and reminders. This is one of the most significant events in the recent past that rebooted the story of conversational interfaces. During the initial days of Siri, users used it only a few times a month to perform tasks such as searching the internet, sending SMS, and making phone calls. Although novel, Siri was treated as a work in progress with a lot more features to be added in the following years. In the early days, Siri had many clones and competition on Android and other smartphone platforms. Most of these were modeled as assistants and were available as mobile apps.
In the same year (2011), IBM introduced Watson, a question answering system that participated in a game show called Jeopardy and won it against previous human winners, Brad Rutter and Ken Jennings. This marked a milestone in the history of AI as Watson was able to process open domain natural language questions and answer them in real time. Since then, Watson has been refashioned into a toolkit with an array of cognitive service tools for natural language understanding, sentiment analysis, dialogue management, and so on.
Following Siri and Watson, the next major announcement came from Microsoft in 2013, when they introduced Cortana as a standard feature on Windows phones and later in 2015 on Windows 10 OS. Like Siri, Cortana was a personal assistant that managed tasks such as setting reminders, answering questions, and so on.
In November 2014, Amazon invited its Prime members to try out its very own personal assistant called Alexa. Alexa was made available on Amazon's own product called Echo. Echo was a first-of-its-kind smart speaker that housed within it an assistant like a "ghost" in the machine. Although called a speaker, it was actually a tiny computer with the voice as its only interface, unlike smartphones, tablets, and personal computers. Users can speak to Alexa using voice, ask her to do tasks such as setting reminders, playing music, and so on.
Recently, in April 2016, Facebook announced that it is opening up its popular Messenger platform for chatbots. This was a radically different approach to conversational interfaces compared to Siri, Alexa, and Cortana. Unlike these personal assistants, Facebook's announcement led to the creation of custom built and branded chatbots. These bots are very much like Siri, Cortana, and Alexa, but can be custom tuned to the requirements of the business building them. Chatbots are now poised to disrupt several markets, including customer service, sales, marketing, technical support, and so on. Many messaging platforms, such as Skype, Telegram, and others, also opened up to chatbots around the same time.
In May 2016, Google announced Assistant, its version of a personal chatbot that was accessible on multiple platforms such as Allo app and Google Home (a smart speaker like Echo). All assistants like Siri, Cortana, Alexa, and Google Assistant have also opened up as channels for third-party conversational capabilities. So, it is now possible to make your Alexa and Google Assistant personalized by adding conversational capabilities (called skills or actions
