$ 5 a month WhatsApp Chatbot for your business.

Rajesh Rajamani
7 min readJul 8, 2020
A fun take on Chatbots from my favorite Geek Cartoon site https://turnoff.us/

Ok. So chatbots are becoming more and more intelligent and getting integrated into our lives thanks to the (smart ? ) phones that we hold in our hands more than anything else.

Similarly Social Messaging apps too have found a very prominent place in our lives . Social Messaging Apps are often associated with your telephone number which is available to all the businesses that you do business with. Therefore it makes perfect sense to for businesses to integrate their customer-service using Intelligent Chatbots on these social messaging platforms.

Some popular social messaging platforms include .

  1. WhatsApp
  2. Viber
  3. Skype
  4. Telegram
  5. Kik
  6. WeChat

For this article we are going to use WhatsApp as the social messaging platform .

A Chatbot for social messaging platform essentially has 3 components.

  1. A Messaging Middleware that handles the telephony component , essentially messaging to a telephone number associated with the Social-Messaging Platform . Remember that while you can use your social messaging platform on wi-fi you need a phone number to register first . And your phone number becomes your identity.
  2. Chat means text is un-structured data . Hence we need an intelligent Natural Language Processing system that can identify the text thrown at it and come up with interesting things like name ,age , place , date and possibly sentiment too ?
  3. An Orchestrator to do intelligent things based on the interesting things we identified from the customer’s input . Such as Booking a ticket , suggesting a favorite movie by looking up the web , scheduling an appointment for your next haircut or reserving a table at your favorite restaurant may be ?

My Architecture for this article are as follows:

Components in my architecture

Before proceeding I assume that you have some knowledge of Azure Functions and an Azure account .

Let’s get to the steps:

Step 1: Setting up Twilio . This is quite easy if you follow the article below. Twilio provides a free $20 credit if you sign-up with your work email ID . So please see you use a work email not the regular free ones ( at least I couldn’t get through with my GMAIL ID )

https://www.twilio.com/docs/usage/tutorials/how-to-use-your-free-trial-account

Step 2: Create a Dialogflow agent.

a. Login to Dialogflow at

https://dialogflow.cloud.google.com/

b. Select a pre-built agent . This makes life easier .

c. Click on the Restaurant Booking and click on Import

d. Once the agent is ready , proceed to your project and see what’s in there .

It has some Intents which defines the purpose the customer is interacting with the business

and some entities to enable the business know finer details from the intent of the customer.

e. Let’s enable the bot to ensure that the customer provides the minimum information on the number of people and the date and time for the restaurant booking .

To do this you have to mark the entities date-time and people as required and then define the prompts accordingly.

f. Now head to the responses section to add a few default responses . You can further customize this based on the entities . But that’s for later. Observe the second response that uses parameters such as people , venue-type and date-time that Dialogflow intelligently extracted from the conversation with the customer.

f. Now you can quickly test this bot with the Try now area . .

When you simply enter “reserve a table “, it will prompt for the number of guests
When you simply enter “reserve a table for two “, it will prompt for the date and time

d. Get the project ID .

Project ID

e. Get the access key for your project to access it later programmatically with the following steps.

Locate your Dialogflow project in the following URL

https://console.cloud.google.com/home

Click on the Go to project settings

Select Service Accounts

Download the Service Account Key as a json file. This is required when we design the Azure function in the next step.

Now , you have Twilio and DialogFlow configured successfully let’s integrate the two components with Azure Function .

Step 3 :We are going to use a http-function trigger for this task .

If you are not aware of the http-function trigger I recommend you to go through my article below before proceeding further.

Let’s design a simple http trigger function now .

Observe that in line 24 , I have used the Google Dialogflow credentials json file .

Observe that in line 46 , I have stored the incoming customer message in a storage queue . This enables you to further expand your workflow to trigger subsequent activities based on customer inputs.

If you don’t know about storage queue and what you can do with a storage queue here is my article on that too .

It’s time to host the function on Azure now . If you had followed my article it’s a simple click from your VS Code IDE .

Step 4: We need to ensure that we pickup the Azure Function URL and populate in the Twilio Console .

Get the Azure Function URL as follows

Now, populate this on the Twilio Console.

Ensure you click on Whatsapp Beta .

Note: While on a free account , you are not allowed to send messages to any account. So a better idea to register your number as a safe sender as follows

And there in the option “When a message comes in box” populate your function URL.

Now we are ready to test .

Open up Whatsapp and store the Twilio Number that you get as part of the Twilio signup and start conversation.

Observe that we are also able to use WhatsApp supported notation for making responses in Bold letters by enclosing the text in *

Let’s come to the cost working .

Disclaimer:

Now these costs are my approximate derivation and may slightly vary , However I’m confident that given it’s a small to medium business with the volumes not exceeding the table above you can comfortably run your chatbot at the target cost.

You’ll have to signup with WhatsApp for Business to take things further if you plan to deploy this in a business scenario.

Parting thoughts:

Remember we inserted the incoming message from customer into a queue . From there we can do quite a few things to enhance customer experience by multiple folds.

A great article on WhatsApp integration to Twilio. However this article speaks about the old method . You can follow it all the way just before the integration part and use the Azure Function Integration that I have provided .

Stay tuned for more .

--

--