AWS Lex Weather Bot for Beginners from Design to WhatsApp Deployment
By: Shammy Narayanan
Tags: Weather Bot, Chatbot, Bots, AWS, Cloud

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 👏 !