Hands-On Chatbot Development with Alexa Skills and Amazon Lex
eBook - ePub

Hands-On Chatbot Development with Alexa Skills and Amazon Lex

Create custom conversational and voice interfaces for your Amazon Echo devices and web platforms

Sam Williams

Share book
  1. 266 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Hands-On Chatbot Development with Alexa Skills and Amazon Lex

Create custom conversational and voice interfaces for your Amazon Echo devices and web platforms

Sam Williams

Book details
Book preview
Table of contents
Citations

About This Book

Build artificial intelligence (AI) powered voice and text conversational interfaces with Amazon

Key Features

  • Develop Alexa Skills to create a working voice user interface (VUI)
  • Integrate Amazon Lex chatbots into Facebook, Slack, and text messages
  • Learn to use AWS Lambda, Alexa Skills Kit, and Amazon Lex

Book Description

Have you ever wondered how Alexa apps are made, how voice-enabled technologies work, or how chatbots function? And why tech giants such as Amazon and Google are investing in voice technologies? A better question is: why should I start developing on these platforms? Hands-On Chatbot Development with Alexa Skills and Amazon Lex covers all features of the Alexa Skills kit with real-world examples that help you develop skills to integrate Echo and chatbots into Facebook, Slack, and Twilio with the Amazon Lex platform.

The book starts with teaching you how to set up your local environment and AWS CLI so that you can automate the process of uploading AWS Lambda from your local machine. You will then learn to develop Alexa Skills and Lex chatbots using Lambda functions to control functionality. Once you've come to grips with this, you will learn to create increasingly complex chatbots, integrate Amazon S3, and change the way Alexa talks to the user. In the concluding chapters, we shift our focus to Amazon Lex and messaging chatbots. We will explore Alexa, learn about DynamoDB databases, and add cards to user conversations.

By the end of this book, you will have explored a full set of technologies that will enable you to create your own voice and messaging chatbots using Amazon.

What you will learn

  • Create a development environment using Alexa Skills Kit, AWS CLI, and Node.js
  • Build Alexa Skills and Lex chatbots from scratch
  • Gain access to third-party APIs from your Alexa Skills and Lex chatbots
  • Use AWS services such as Amazon S3 and DynamoDB to enhance the abilities of your Alexa Skills and Amazon Lex chatbots
  • Publish a Lex chatbot to Facebook Messenger, Twilio SMS, and Slack
  • Create a custom website for your Lex chatbots
  • Develop your own skills for Alexa-enabled devices such as the Echo

Who this book is for

Hands-On Chatbot Development with Alexa Skills and Amazon Lex is for developers who are interested in building conversational bots and Alexa skills with Amazon. Prior experience with JavaScript programming is required.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weā€™ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Hands-On Chatbot Development with Alexa Skills and Amazon Lex an online PDF/ePUB?
Yes, you can access Hands-On Chatbot Development with Alexa Skills and Amazon Lex by Sam Williams in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in JavaScript. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781788992435
Edition
1

Connecting a Lex Bot to DynamoDB

After reading the previous chapter, we know how to create a Lex chatbot. Now we can start building a chatbot that takes the user through a more complex flow. Designing and building larger chatbots is closer to what you are likely to be doing, and we'll look at the best ways to approach the design and setup.
We'll be using our chatbot to get data from S3 as well as getting and writing data to DynamoDB tables. This allows us to persist information about the users' choices and progress through the flow.
The following topics will be covered in this chapter:
  • Creating flow diagrams for a larger, more complex chatbot
  • Creating a Lex chatbot to cover all of the intents and flows
  • Retrieving data from an S3 bucket and performing logic upon it
  • Creating a Dynamo table and using it to store and retrieve information

Technical requirements

In this chapter, we will be creating a Lambda function for our skill, and we'll be creating and deploying it using the local development setup that we created in Chapter 2, Getting Started with AWS and Amazon CLI.
All of the code and data required for this chapter can be found at http://bit.ly/chatbot-ch6.

Designing the flows

The FAQ chatbot that we built in the previous chapter didn't need to have any flows designed as everything was simply a question and an answer. This chatbot will be a lot more complex, with multiple flows, some of which will lead to other intents and flows.

Perfect conversations

As always, we can start to build flow diagrams by starting with perfect conversations. The difference this time is that we will have a few different conversations. We'll have some that go from asking about stock to making a purchase, others will stop before checking out, and some people won't even add anything to their basket. These are all flows that we will need to design and build.
It is good to start with a conversation that goes through the whole process. Here is one such conversation:
Full process conversation
We can also create other conversations that deal with part of the flow. A user could add some items to their basket and then save them for later, while another user will want to ask what is in their cart before checking out. You can probably see that some of these conversations will overlap. This will become more apparent as we progress onto our flow diagrams.

Flow diagrams

As this is a large and complex conversation, we are going to break the flow into sections. This will make it easier to create and visualize.
The first part of the full conversation, as well as the stock-checking conversation, can be used to create a productFind flow diagram:
The productFind flow diagram
As you can see, there is some logic that is similar to the logic that we used in the Car Helper chatbot in Chapter 3, Creating Your First Alexa Skill. By the end of this flow, we know what product the user is asking about.
You may have noticed a new symbol in this flow. This symbol is similar to intentTrigger but this is for starting another flow. Breaking the whole flow into smaller chunks that can call each other is the best way to keep your diagrams organized:
Start another flow
Now that we know what product the user is asking about, we can create a flow for checking stock and asking whether they want to add that to their cart. This starts with a request to S3, and if there is stock and they want it, we add it to their basket in Dynamo:
Stock and cart
The last stage of this conversation is the checkout. This is about getting a few details about the user so we can place the order. This would normally include taking a card payment, but we won't be doing that with this chatbot:
Checkout
The reason that we are breaking the conversation into multiple smaller flow diagrams is so that each flow does a single thing. This means that we can link different flows together. What if we have a user who knows the ID for the item? We can have them skip the productFind flow and start at the lookupAndCart flow.
When we consider a few other conversations, we end up with a web of flows in a master flow diagram:
Master flow diagram
This master flow diagram shows how each of the sub-flows can be connected together to map any conversation. This web of conversation allows the chatbot to deal with the user in a much more human way than older chatbots that had a single path that the user had to follow.

Building the chatbot

With all of the sub-flow diagrams and the master flow diagram, we can start to build the chatbot. Another great thing about having these sub-flows is that they are quite similar to intents.
Before we can start creating intents, we need to set up our Lex bot. In the Lex console, click Create and then follow the process for creating a Custom bot as described in Chapter 5, Building Your First Amazon Lex Chatbot.

Product find

We will start with the most common conversationā€”finding a product. First, we'll create a new intent called productFind.
This intent will deal with users who want to find a product to add to their cart, as well as users just checking the stock levels, so we need to provide utterances to represent this. We also need to deal with user utterances such as, "I want a new jacket" and "Do you have any medium, blue shirts in stock?"
To capture the slot values from the utterances, we can use curly braces around the slot name:
Utterances for productFind
With some utterances created, we need to create the slots and slot types. For the productFind intent, we need quite a few slots: type, size, color, length, and itemNumber. The first four are self-explanatory but itemNumber is less obvious.
We want to include an item number slot so that if a customer wants to buy a product that they already have, they don't need to go through the longer question-answer product-finding flow. These small things are what separate good bots from great bots.
Next, we need to choose a slot type for each of our slots. For the first four slots, we're going to need to create custom slots:
  • Type: We are going to be selling three types of clothing: shirts, jackets, and trousers (pants).
Click the + next to Slot types and choose Create slot type. Name your slot something such as clothingType and select Restrict to Slot values and Synonyms. It is a good idea to be relatively specific with your slot type naming as you can't have two slot types with the same name.
We can now add our values of the shirt, jacket, and trousers. We then need to add synonyms that the user might type. Instead of shirt, they may type blouse, top, or t-shirt. For trousers, they might type a pair of trousers, pants, or a pair of pants. Expand all of the synonyms for all of the values until you can't think of anything else.
  • Size: Size is going to be ...

Table of contents