In a previous article,https://smartlake.ch/onboarding-virtual-assistant-for-banking-adding-product-recommendations/, we have shown the integration of product recommendation in a simple onboarding dialogue. In this article we are going to show how we built this simple experiment using various cloud-based services.
Defining Intents and Utterances
In order for the virtual assistant to interpret what a user wants to do, we must define user intents. One example of an intent is opening an account. Once we have created the intent, we need to define how the user will express his intent. In this case, we need to input utterances, i.e. variations of possible user statements for the intent. The screenshot below shows possible examples:
Defining a response
After we have defined the intent and the utterances, we need to define a response and the next action. In this case, we will ask the user if he is a country national or a resident. This will branch the dialogue directly to the next intent which is to input the nationality of the user.
Now we want to identify if the user is a national or a resident, Lex allows us to identify so-called slots in sentences, which represent variable we want to capture during the dialogue. The user will for example say ‘ I am a National’ or ‘ I am a resident’, hence we need to detect one of the 2 options. Therefore, we will define a new variable type ‘ residentType’ that usually comes after ‘I am’.
Keeping the Context using AWS Lambda
Once the resident type has been entered, we need to keep this information for further processing. This starts to be a little bit more complicated than a simple chatbot, we need to implement a real dialog manager using AWS Lambda. So once the reply from the user has been recognized ( or fulfilled) , we are asking Lex to call a so-called lambda function. In our case, we will name the function ‘ OnBoardingFunction’.
Using AWS Lambda
AWS Lambda function is called directly from Lex with various input parameters that allow us to manage the dialogue. In our case we have written the lambda in Python 3.
In the code below, we see that the function checks if it can find the slot we have defined earlier ‘countryOfResidence’ and checks if it is Switzerland in order to proceed, if not it does not allow the user to proceed.
You can notice also that it keep the country of residence in the output attributes. This will allow us to check this attribute also later on in the dialogue.
What is next
In the next article, we will go a bit deeper into the dialog management and see how we implemented the simple classifier function to recommend a product.