<img alt="" src="https://secure.agile365enterprise.com/790157.png" style="display:none;">

Amazon Lex - Handlling Complex Workflows and Dynamic Slots

author
By Sanjay Rohila Oct 4, 2018
Amazon Lex - Handlling Complex Workflows and Dynamic Slots
Amazon Lex - Handlling Complex Workflows and Dynamic Slots

Amazon Lex is a chatbot framework which allows us to create conversational bot over voice and text. There is a lot of documentation around for AWS Lex, intent fulfillment. But there is not much if we have to change the flow of bot based on previous slot values or create complex workflows in Lex. So In this post, we are gonna through some stuff that I have done for Lex while creating workflows:

Initialization and Validation Code Hook

Amazon Lex provides code configuration which allows us to add lambda on every user input (basically every slot). We can add lambda function and return dialogState from there. We can also add our own custom message with an updated option for the user based on business logic or previous slot values. dialogState is very important for deciding what should be our next slot to elicit or delegate to lex or fulfil and provide slot values by yourself, all based on the use case. We get the intent and current slot values from lex as request and then we can decide what we should ask next. On request, we can also repeat the process but with an updated values of slots. The code example is given below:

Core Controller

To make it more robust and scalable, following is the structure I use (From above code which bit goes in which file, go figure):

So each of the intent files can have JSON structure with slots, other configs and then some interface functions (below). All the controller has to do is play with business logic and call these functions for data whenever required. This data/content can be stored in some workflows management tools or database .

If this makes sense let's jump to our next post, where we are gonna talk about using AWS Cognito for Auth and Translation.

Subscribe to our newsletter