Chatbots should work with audio or text and Lex is no different. Being able to process a text conversation doesn't take much work. You have to set the delegate on the interaction kit and implement it. Each step of the interaction has text from the server and the related slot. Set the text based on that and continue.
- [Instructor] Alright so that was awesome, I know you agree And you might be saying to yourself, Bear my friend, what about text? Well no worries, we can handle that, it's actually pretty easy. So we registered an interaction kit here, we want to get that interaction kit back out, set its delegate to self, we'll implement a couple of methods for it, and then we'll start off the conversation. So the first thing we're going to do is after we register the kit on line 44, we're going to get it back on line 45 with AWS Lex Integration Kit open paren for key and we're going to pass in the key that we used on that line for registration AWSLexVoiceButtonKey And then we'll just add .interactiondelegate set that to self, we don't implement that but we will soon, and then on the next line, line 46, we're going to get it again with AWSLexInegrationKit for key AWSLexVoiceButtonKey and we're going to set the text, this is going to start the conversation so we'll use one of our utterances, we'll use feed me. Now it's saying we don't implement this protocol, but that's no problem, we can do it, we just get the AWSLexIntegrationDelegate protocol name and on line 13 after the other LexVoiceButtonDelegate protocol, we add comma AWSLexIntegrationDelegate now we don't implement that so we're going to fix that with adding the stubs for the error, that's the only one that's required, so on line 14 it adds that and on line 15, we'll print out the error localized description. The other function that we want to implement is the one that has the switch mode input. So on line 18 we'll add that and then we implement it, now the switch mode input is going to come in with a dialogue state if it's confirm the intent, we want to say yes, if it's ready for fulfillment, then we want to print out all the slots or do anything else that we need for fulfillment. There's also another function that's another callback that has on dialogue ready for fulfillment for intent, we could handle it there as well, we'll just print out the slots. On our switch mode input function, we're going to first guard to make sure that the switch mode input dialogue state is not equal to ready for fulfillment, if it is we're just going to return, we'll let the other function handle that. We also want to check to see if it's confirm intent, so on line 20 we write guard switchmodeinput.dialoguestate not equal to confirm intent else and for this one, we're going to set on the interaction kit that the text is yes, so we're going to actually confirm that we're ready. For the rest of the cases of dialogue state, we want to look for the slot that they're asking for and return the appropriate text for that. On line 25 we'll add let slot equal switchmodeinput.elicitslot and then we're going to do a switch on that slot. And we'll add switch.slot on line 26 and the first pattern will be food, that's the name of our first slot that we created in Lex and if they are asking for food, we'll set the integration kit text to pizza and then we're going to add a couple more cases, we'll have restaurant and drop-off location. So on line 29 case restaurant, and we'll just put in a name of a restaurant, we'll put Bear's and then on line 31, we'll have case drop off loc, or whatever you named your various slots and we'll put lobby and then for the default we'll just print default since cases have to be exhaustive. Now in each of these cases, the slots should get their fulfilled text set on the interaction kit and then once we're going to confirm it, we'll send back yes and if we're ready for fulfillment we'll just return and let that get handled in this function over here. So I'll set a couple of break points, fire up the app, we're starting off the interaction by setting the text to feed me, OK so we got our first break point and now I'm just going to execute it from there. And we see that we get the fulfillment with the slots. Now if we want to see it as it happens, we can look at the actual response that's being passed back by printing out the switch mode input output text. And for each of these, we'll see the prompts to the user and then the fulfillment in the slots. And we can see down here in the debug console what would you like to order? From where would you like to order? And where would you like to meet the delivery driver? In each case, we're passing back the appropriate response and then once we have all the slots, we get this callback, it's printing out the slots that we got information for and our app can handle it accordingly however it needs to be fulfilled. Now isn't that great, we did audio, we did text, I think we're almost ready for protection, we just need to find a restaurant called Bear's that we can order some pizza from for people.
- Introducing Amazon Lex
- Lex API and CLI
- Creating the bot
- Testing the bot
- Defining slot types
- Configuring input and confirmation prompts
- Designing responses
- Publishing the bot
- Creating and connecting lambdas