- [Jon] In our previous lecture, we used Lambda to validate slot values. I will continue from that example to discuss fulfillment and session attributes. I'll start by interacting with the bot and fill all of the slots this time. Book a hotel. "What city will you be staying in?" I will select Chicago. "What day do you want to check in?" Tomorrow. "How many nights will you be staying?" Five nights. "What type of room would you like, queen, king, or deluxe?" Queen. I'm now getting a prompt configuration, but something has changed here from the time where we didn't have Lambda integrated. If you look, a price is provided for this hotel. Don't worry, though, it's just a generated price randomly. It's not that expensive to stay in Chicago. Well, I hope not! To understand how this happened, you will need to understand another concept called "session attributes." They contain application-specific information that is passed between a bot and the client application during a session. Amazon Lex passes session attributes to all Lambda functions configured for a bot. If a Lambda function adds or updates session attributes, Amazon Lex passes the new information back to the client application. Session attributes can also be used to add more information in the prompts to the user, as you can see it here. How long are those sessions being kept? Well, if we go under the Settings of our bot, under General, you will find the Session timeout here. We can see that it's currently set to 10 minutes. You may also be wondering what constitutes a user to Lex. Well, when a request is sent to Lex, a user ID is also passed, and that's what Lex will use as its key to associate all of the session's attributes until the timeout is reached. Your application is responsible for generating it. When testing with the Management Console, it is generated automatically for you. That's why we never had to worry about it. Back to our interaction with the bot, we just sent the last piece of information to Lex. That was the last slot to fill, which looks like the following. As you can see, it is a POST for queen as my bed, but you can also see the user ID right here. That's what I meant by the user IDs being sent into Lex. Lex then sends that information to Lambda. The Lambda function will need to realize that all of the slots have been filled, as you can see it right here. And it will need to use a session attribute called currentReservationPrice, it's up to the Lambda function to decide that, to store the price of the hotel. Lambda will send back that data to Lex as you can see it. It uses the Delegate function to let Lex continue with its processing, provides all of the slots again. But, there's something a little bit different here. The sessionAttributes is currently set to currentReservationPrice: 1195, $1,195 dollars, which is what we saw in our prompt. Let's take a look at the prompt that we'll be using this information here. Back into our Editor, I will go towards the Confirmation prompt. Clicking on the little gear icon, I can see the price of this night - amount of night night stay in the Location, from checkInDate, is [currentReservationPrice]. As you can see, there are two prompts. One of them makes use of those square brackets, referring to that currentReservationPrice. This is the way to invoke session attributes within a prompt. The client can now confirm that the entry is correct at that point. So, I will type Yes here. The input data for this is going to look like the following. As you can see it, inputText: Yes. This time, Lex will invoke the Lambda function with a different invocation source, as you can see it here - invocationSource: FullfillmentCodeHook. That is how Lambda knows that it's supposed to fulfill this. It can use all of the slot's data to do the booking in the backend system. Lambda will need to send one last dialog action back, and that is of type: Close, with the fulfillmentState set to Fulfilled. A message can also be supplied, or the Response section of the bot will be utilized. In this case, we use the message. Lex will send that message back to the user and then now our interaction with our bot is now finished. However, the session is still alive. It's set to 10 minutes. And if the user wanted to continue booking a car, there are some slots that are already filled from our previous interaction with the bot during our book hotel. Let's test that out. Let me book a car. As you can see, it asks me a question: "Is this car rental for your 5 night stay in Chicago" around that date? Huh, it found that information. If I look at the Summary, it even figured out the PickUpCity Chicago, and it figured out my PickUpDate and my ReturnDate, and did the math for me. This is done using the Lambda function and the session attributes that can be passed between all of the different intents. I'm inviting you to explore the code to see how this was done, if you're familiar with Python. Soon, you'll put to use everything you have learned about Lex into an exercise. Thanks for watching.