AWS Lex Weather Bot for Beginners from Design to WhatsApp Deployment

Shammy Narayanan
Chatbots Life
Published in
6 min readNov 18, 2020

--

Chatbots had been a gateway for most of the beginners into the world of AI, its simplicity and a trove of easily conceivable use-cases had made it tremendously popular in the developer community. Though my personal favorite had been open source RASA chatbots and previously had made few popular videos and curated blogs on RASA chatbots, the most challenging part in it is the frequent and dynamic design transformations making the learning curve too steep. Fundamentally a good amount of effort gets expended in Learn-Unlearn and Relearn process. So stepping out of my comfort zone wanted to design and deploy a chatbot in AWS and compare these two systems in terms of ease of use as well as usability. Had taken a familiar example of a weather bot and developed it from scratch in Lex.

As a first step, log in to AWS cloud, and from the management console, select LEX, you will land on a similar screen

Hit create and provide a name for your bot (in my case it's WeatherBot), once inside the panel we need to create Intents and utterances. For starters, intent refers to the goal the customer has in mind when typing in a question. Utterances are various ways they can ask that questions, for example, if “Greet” is an intent, utterances can be “Hi”, “Greetings”, etc

Trending Bot Articles:

1.Understanding DialogFlow ES and CX

2.Deploying Transformer Models

3.TensorFlow installation with GPU Support on Python 3.7 in Windows

4.Conversation Designers: who are they and what do they do?

As a chatbot architect or designer, for a superlative user experience, the efforts should be more focused on generating as many utterances and emulating customer natural way of interaction than the technical considerations.

In my chatbot, I have kept it simple with four intents (Greet, Good Bye, InquireWeather, and Weather inquiry). Out of this “Goodbye intent” is part of a few inbuilt intents which come as part of Lex boutique to simplify the development process. However, Lex allows you to append user-defined responses to such inbuilt intents

On Slots (variables in your utterances) Lex scores high as it comes with inbuilt enumerations or lists which cuts down your development work. For example, US_State is an in-built list that validates user inputs against 50 US states. Similar validation in RASA would require us to write our own API and perform the validation (hopefully in future versions of open source Bots it may get integrated !!)

Will leave it to your imagination for designing the number of Intents and its utterances. But there comes a point in your design where we need to interact with an External Datastore, in our Weatherbot we will make use of the Weatherstack website which offers a free API for providing weather information for any given city

Sign in to it and get the API key, we will need it in the fulfillment event.

The next big challenge is to establish the connection from our chatbot to this API to retrieve the weather details for the user-provided city. We accomplish this goal using the AWS lambda function (you can code in Ruby, Java, Python and this list keeps growing…)

Sample Python code to retrieve and communicate response back to Lex

This code is available in https://github.com/shammy45/LexChatbot/blob/main/weatherapi

In the above code snippet Input variable “City” comes from the slot of your chatbot utterances

Once your bot is developed, the remaining phases are Testing and Deployment.

Testing can be done in your local environment on the test pane at the right side of the Lex console

If the city name is not provided, Bot follows a different interaction

With our testing completed, the final stage is deployment. Lex provides an out of box integration with multiple channels as shown below

We will use the Twillio option to integrate with the popular messaging platform -Whatsapp

once you have signed in and completed your two-factor authentication, select WhatsApp sandbox setting under Programmable messaging (as shown in picture)

In the “When A Message Comes In” and the “Status Callback URL” textboxes, we have to provide a callback webhook URL from our Lex chatbot. So we need to generate it from the Integration panel of the Lex console

Alias and Account SID information will be available from your Twilio console as shown in below pic

On clicking activate in the Chatbot channel panel, you will get a call back URL from the LEX panel as shown below

Use this URL to populate the WhatsApp sandbox screen

You are all set now, follow the instruction on your screen to initiate chatbot in WhatsApp

Now you are all set to interact with your weather bot from your WhatsApp

In conclusion, comparing RASA, Lex significantly cuts down the effort and time in “Designing to deployment cycle” of a chatbot, also the environment comes with multiple benefits and flexibilities (choice of program languages, Inbuilt intents, zero lead time to setup environment, out of box integration on popular platform, Serverless, etc) but we also need to remember all this comes with a vendor lockin. Decision is purely based on Lockin vs Learning curve…and our Chatbot journey continues.

Don’t forget to give us your 👏 !

--

--