Sitemap
IBM Data Science in Practice

IBM Data Science in Practice is written by data scientists for data scientists to gain hands-on and in-depth learning and to read about inspirational applications and conceptual understanding for challenging topics in the field. Discuss and network: community.ibm.com/datascience

Update your chatbot on WhatsApp with IBM Watson Assistant

--

hand holding a smart phone
Photo by AARN GIRI on Unsplash

Chatbots are everywhere these days, and most businesses aim to use them to increase productivity and provide a better customer experience. In this tutorial,

& I demonstrate how to extend a Watson Assistant chatbot’s capabilities by connecting it to WhatsApp using Twilio. We will be using Twilio’s sandbox to show how this integration works. This tutorial is also published on English and Spanish. You can access the English version here and the Spanish version here.

Prerequisites:

IBM Cloud Account

Twilio Account

In this tutorial, we are assuming that you already know what Watson Assistant is and how it works. We will be only focusing on the integration part with WhatsApp. However, if you haven’t used Watson before then you can get started here.

  1. Go to your Watson Assistant service in IBM Cloud. Let’s first add a dialog skill to our Assistant. Go to this GitHub Repo and download it. It has the dialog skill that we will be using for our assistant. Once it’s downloaded, import the skill in the Assistant.
Uploading an Existing Action or Dialog Skill in Watson Assistant
Uploading an Existing Action or Dialog Skill in Watson Assistant

2. Under Integrations on the right side, choose Add Integration.

Adding 3rd Party Integrations to Watson Assistant
Adding 3rd Party Integrations to Watson Assistant

3. Choose WhatsApp with Twilio and then click Create.

Integrating WhatsApp via Twilio to Watson Assistant
Integrating WhatsApp via Twilio to Watson Assistant

4. Now here we will need to set the Account SID and Auth token that we can get from Twilio. Go to your Twilio account (if you don’t an account, you can create one here) and copy your Account SID and Auth token that are in the home dashboard. (Click on Show to reveal the token).

Copying Twilio Account SID & AUTH Token from Twilio Dashboard
Copying Twilio Account SID & AUTH Token from Twilio Dashboard

5. Go back to your Watson Assistant and fill Account SID and Auth token with the values that you got from Twilio Dashboard.

Setting WhatsApp with Twilio integration in Watson Assistant
Setting WhatsApp with Twilio integration in Watson Assistant

Click Sync Account and wait for it till it shows Synced. Once it’s synced you will see a Webhook URL generated in the WhatsApp Webhook field. Copy this URL and go back to Twilio.

6. Now we need to set up and configure our Twilio sandbox to integrate it with Watson Assistant. In your Twilio Account, click on the icon that represents all products and services (it’s below the home icon) on the left side go to Programmable Messaging from the expanded menu and select Try WhatsApp under the Try it out section.

Setting up Twilio Sandbox for WhatsApp
Setting up Twilio Sandbox for WhatsApp

We will be using this testing sandbox for our integration. Send the given code/message to the number provided by Twilio from your WhatsApp.

Connection between WhatsApp and Twilio
Connection between WhatsApp and Twilio

Once it’s done, you should see Message Received! on Twilio like this image.

Establishing Connection between Twilio & WhatsApp
Establishing Connection between Twilio & WhatsApp

This means that now your phone number is connected to this Twilio-WhatsApp sandbox.

7. Click Next twice (skipping One-Way Messaging, going directly to Two-Way Messaging). Two-Way Messaging is where both the user and the service can send messages which results in a conversation. The service triggers a 24-hour window in which the conversation can take place. Send a reply to the message that you received on WhatsApp and click Next: Configure Your Sandbox.

Setting up Two-Way Messaging for WhatsApp on Twilio
Setting up Two-Way Messaging for WhatsApp on Twilio

8. Paste the webhook URL that you have from Watson Assistant into the When a message comes in field. You should see your number in the sandbox participants and others can enter this sandbox by sending the code mentioned to the sandbox WhatsApp number (In the below image the code is join design-thumb). Once you’re done click Save.

Configuring Twilio Sandbox for WhatsApp with Watson Assistant
Configuring Twilio Sandbox for WhatsApp with Watson Assistant

9. All is set. Now the Assistant is integrated with WhatsApp through Twilio. From your device, send a WhatsApp message to the WhatsApp sandbox number and you will receive the assistant’s response.

Demonstration of WhatsApp and Watson Assistant Integration
Demonstration of WhatsApp and Watson Assistant Integration

In this tutorial, you were able to successfully integrate your Watson Assistant with WhatsApp through Twilio. Since this is a tutorial, we were using WhatsApp-Twilio sandbox to show you how this integration works. If you want to use WhatsApp-Twilio with the Assistant for a real use case, then you will need to have a premium Twilio Account, a Facebook Business Manager ID and apply for permission. You can find more information about this here. You can also check out the video for this tutorial here.

--

--

IBM Data Science in Practice
IBM Data Science in Practice

Published in IBM Data Science in Practice

IBM Data Science in Practice is written by data scientists for data scientists to gain hands-on and in-depth learning and to read about inspirational applications and conceptual understanding for challenging topics in the field. Discuss and network: community.ibm.com/datascience

Mridul Bhandari
Mridul Bhandari

Written by Mridul Bhandari

Platform Engineer - Client Engineering @ 👁️🐝Ⓜ️

Responses (1)