Create a WhatsApp Bot with Twilio

WhatsApp is set to roll out the Bot API for developers but currently is in beta for select verified businesses. If you are eager to build and try a WhatsApp Bot then you can try Gupshup or Twilio Sandbox.

Remember to use this for testing purposes only.

In this post, we are going to see Twilio WhatsApp sandbox, and we will build a sample bot too.

Get Started

To get started, go to and click on Try the Sandbox today button.


After clicking the try button, you will be redirected to the login page. Login or Sign Up there.

Once you get login, you will able to see your Twilio Console Dashboard.

From Dashboard go to Programmable SMS and then WhatsApp or visit this URL

Now you will see a screen something like below.

You will get a WhatsApp mobile number and a sandbox joining code. Save the mobile number to your phone and send the join code to the Twilio sandbox.

join <your_join_code>

After sending the message to the sandbox, it will get received to the console showing message “waiting for your message”.

If you receive Message Received! in the console, it means you are now connected with your app using the sandbox.

Now let’s try to send some messages to the connected clients from the console. To do that click on the Next: Send One-Way Message button.

Next, you will see a dashboard to send a one-way message. To do that click on any of the three built-in messages to try and after the message loads click on the Make Request button.

After making the request from the console, you will receive a sample order notification message.

Similarly, you can try Two-way Messages next.

Use your Backend to send messages

Twilio allows you to send WhatsApp messages from your server using their Twilio API.

To configure your server go to Sandbox from the sidebar menu or and enter your server URL where the requests to be sent from Twilio.

To set up your server install the required Twilio SDK compatible with your programming language. I have used Python SDK here for the demo.

For SDK code and examples visit this URL and choose your preferred programming language get started.

Here is a sample Python code below from Docs

# Download the helper library from
from import Client

# Your Account Sid and Auth Token from
account_sid = 'your_account_sid_here'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)

message = client.messages.create(
                              body='Hello there!',


If you don’t want to use Twilio SDK, then you can return the responses in the form of TwiML XML. It will be parsed and sent by Twilio.

Learn more about TwiML here

That’s it. We are done building our own WhatsApp Bot using Twilio WhatsApp Sandbox.

Thank you for reading. Try making a WhatsApp bot now. ????