- [Jon] In the previous lecture, we discussed what a chatbot is and then learned that Amazon Lex is the service to use to build one. In this lecture, I will demonstrate how to use Lex using the AWS console. Instead of building an entire bot from scratch, I will use a sample. This way, if you want to follow what I do during the demonstration, you can. Let's start at the Lex console. Lex is available in four different Regions, as of today. You can see all of those Regions here. Let's start with creating the bot by clicking Get Started. You can see two main options here, where I can decide to create my own custom bot or use a sample. Let's look at the sample for a few minutes. Here, you can see the definition of the bot. I have BookTrip as my bot name. This bot contains something that we call an "intent." An intent is a particular goal that the user wants to achieve. So, the user sends a few utterances. The utterances are things like, "I'd like to book a hotel." So, the utterance is sent into the bot. The bot will now look at part of all of its utterances and will try to match it to one of those intents. This time, it's pretty easy. It's the BookHotel intent. Next, we don't have all of the information to be able to book a hotel. So, we need to start asking a few more questions toward the user. Well, those questions are sent via something we call a "prompt." This prompt, as you can see, is, "Sure, which city?", will ask the user for that question. The user will now answer that question by saying, "New York City." And then, that will fill something that we call a "slot." A slot is data that the user must provide to fulfill the intent. They are required slots. And then, the bot will need to have the answer to every one of the slots to be able to fulfill this entire intent. Once all of the required slots have been filled, it is now time to ask the user, "Are you sure you want to book the hotel in New York City?" Make sure that we confirm all of those slots that have been filled. If the user answers, "Yes." It's time to fulfill this bot or fulfill this intent. The fulfillment is the business logic required to fulfill your entire goal, your intent, here. So if you have to make a call toward your backend to say, "Hey, I am ready. I'm done with the input of the user. I want to send that toward my backend to book my entire hotel." There are two ways to interact with Lex if you remember our previous lecture. You either send the data as text, or you send it as a spoken statement. When you interact with Lex using speech, it makes use of Amazon Polly to convert prompt and confirmation text to speech. This is why Lex requires a role to allow the service to call Polly. Here's our role. We will discuss roles on week three, so I'm not going to go through it now. The last step to create this bot is to specify if this bot is subject to the Children's Online Privacy Protection Act. In this case, I'm not subject to COPPA. So, I'm going to answer no. Let me show you the create your own options here, the custom bot. You can see here a few more options that aren't asked when I use a sample. Don't worry though, all of those options are configurable in the settings of the sample bot. Here, we can see the language is set to English. That is currently the only language supported by Lex. Next, we have the Output voice option to pick the different English life-like voice that Polly is going to use. There is another option here called "Session timeout." This is used to specify how long the information of the user that was passed as session attributes should be kept. I'll go into more detail about this concept in a later lecture. Let's go back to booking our trip with the sample BookTrip bot. I will answer no to COPPA here, and then I will hit Create. Let me explain the Editor. On the left menu, you can see a list of intents. So, I have BookCar, and I have BookHotel. Below, you can find the slot types. That is a list of custom slot types, which I will discuss later in this lecture. You can also find the Error Handling section below. Let's take a look at it. In the case where the bot can't match the ask of a user to an utterance in an intent, it will retry twice, as you see it right here. By sending the clarification prompt, that you can see at the top here. "Sorry, what can I help you with?" You can add more prompts, and it will randomly select one of them, which makes the bot seem a lot more human. In the case where it can't understand what the user wants to either do by not being able to match it with an utterance in an intent or when a user doesn't provide a valid answer to a prompt, one of the hang-up phrases will be used. In this case, it's, "Sorry, I am not able to assist at this time." Let's go back to the BookCar intent. I will close this prompt here saying the bot was successfully built, and I will remove the screen on the right-hand side so we have more space here. We have three utterances here. You can see make a car reservation, reserve a car, and book a car. You don't need to specify each one of the possibilities as Lex utilizes natural language understanding deep learning algorithms to expand those sample utterances. Sometimes though, you may need to add a few more utterances that the model doesn't associate properly. I'll skip the AWS Lambda piece initialization here, because I will talk about it in week four. Next, we have slots. Let's take a look at the second slot here, PickUpDate. We see that it's required, because there is a check mark next to it, which means that we won't be able to fulfill this intent until this slot is filled. Next, the slot is a type built in amazon.date. There are many built-in slot types, and all will start with the amazon prompt, as you see there. This particular one will take a date entered by a user and transform it to a date that machines can understand. For example, using "tomorrow" and transforming that to 2019-02-21. A machine can understand that. Then, we have the prompt. You can configure what question is asked of the user to fill this slot. Again, you enter a few of them. "What day do you want to start your rental?" Then, Lex will randomly select one. You can specify the maximum amount of retries, as well here, in case the user enters a wrong entry, until Lex returns a hang-up phrase we saw earlier in the error handling. Also, you can specify different utterances here that the user may use to answer the question. Typically, those aren't required for simple answers, like the date. But sometimes, the user may bury the answer into a very long sentence, and Lex can't find it. That's where you will add the utterances here. Let's take a look at another slot here. CarType. It is the last slot. Does that matter? Well, the order is what Lex uses to order the different prompts it will ask to the user. So yes, it does matter. The slot type this time is CarTypeValues. That doesn't start with Amazon. So, it is a custom slot type. Let's take a look at it. CarTypeValues. The slot resolution option is important here. You can specify to restrict values to only the ones you add below. Restrict to slot values and synonyms. You can then add synonyms, which will match back to the original value on the left-hand side. If a user specifies a synonym, the actual value on the left-hand side is what will be sent back as the result or as the fulfillment of this slot. So, that makes it easier on your business logic. Alternatively, you can configure the slot type to expand on the values. Slot values will be used as training data, and the slot is resolved to the value provided by the user if it's singular to the slot values. There are many slots here. As you can see, there are five. It seems like there will be a lot of back and forth between the bot and the user to fulfill every single one of those slots one at a time. What if the user was to provide a few or all of the slots via the utterance? Well, let's check it out via the BookHotel intent to see that example. You can see that the first utterance references some slots this time - nights and location. To do so, you use the curly bracket and the name of the slot in between. Now, that means two less slots to fill with prompts for the user. Isn't that great? When all of the slots are filled, it will be good to confirm with the user that everything that was understood by the model is right. The confirmation prompts provides that. You can see, here again, we are using curly brackets. If the user finds an issue with the answers, they can insert or cancel by saying, "No." Which means we will reply, "Okay, I have canceled your reservation in progress." At that point, the user will have to start again by invoking the intent via its utterance. If everything is fine, the user confirms that everything is right by saying, "Yes." And then, the fulfillment can start. This can either be done via Lambda, which we will discuss later in the course, or by sending back the parameters to the client. Once the client has all of that data, it can be sent to any backend of their choice. Think using JavaScript here to make an Ajax call, with everything that the bot has understood, to your business logic. The response section can be used to pass final messages back to the user or even give them the option to move to another intent at the end of their conversation. We've now created our sample bot. In the next lecture, I will modify the bot and introduce you to versioning and publishing. See you there.