Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Trying Out WhatsApp with Conversations


This tutorial shows you how to use Twilio Conversations with Twilio's Sandbox for WhatsApp. Twilio controls a dedicated WhatsApp phone number that you can use to test WhatsApp messaging in Conversations.


Prerequisites

prerequisites page anchor

Before you begin, make sure you have the following:

Note: This tutorial shows both the Conversations API approach and a more basic Messages API alternative. If you're having issues with Conversations, try the Messages API method first.


Step 1: Opt in to the Twilio Sandbox for WhatsApp

step-1-opt-in-to-the-twilio-sandbox-for-whatsapp page anchor

You can test your application in a developer environment by connecting to the Twilio Sandbox for WhatsApp.

Go to the Conversations > Try it out(link takes you to an external page) section in the Twilio Console. Choose a use case, then send the "join <your Sandbox keyword>" WhatsApp message from your device to the Twilio Sandbox for a WhatsApp phone number to connect to your sandbox.

Instructions to connect to Twilio WhatsApp sandbox by sending a message or scanning a QR code.

Once you've joined Twilio WhatsApp Sandbox, you'll receive a confirmation message. To disconnect from the sandbox, you can reply to the message from WhatsApp with the word "stop".

Important: Note down your Sandbox WhatsApp number (typically starts with +1415). You'll need this for the next steps.


Step 4: Create a conversation

step-4-create-a-conversation page anchor

After you have your Twilio Sandbox for WhatsApp configured, create your first Conversation.

Let's make a Conversation using the Twilio CLI (but remember that you can choose another tool for making the API requests):

1
# Install the twilio-cli from https://twil.io/cli
2
3
twilio api:conversations:v1:conversations:create \
4
--friendly-name "whatsapp-sandbox-test"

Copy the Conversation SID that starts with CHXXXXXXX. You'll use this value in the next steps.

If this command fails, verify:

  • Twilio CLI is installed and authenticated (twilio profiles:list)
  • Your account has Conversations enabled

Step 5: Add a WhatsApp participant to the conversation

step-5-add-a-whatsapp-participant-to-the-conversation page anchor

You've created a Conversation, which you can think of as a virtual space that users can join using a channel of their choice.

Next, you'll add yourself as a WhatsApp Participant. The following code sample does this for you. You'll need to replace the following information:

  • CHXXXXXXXXXXX: the Conversation SID.
  • YOUR_WHATSAPP_NUMBER: your own mobile phone number in E.164 format.
  • TWI_SANDBOX_WA_NUMBER: the Twilio Sandbox WhatsApp phone number in E.164 format.
1
# Install the twilio-cli from https://twil.io/cli
2
3
twilio api:conversations:v1:conversations:participants:create \
4
--conversation-sid CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
5
--messaging-binding.address whatsapp:YOUR_WHATSAPP_NUMBER \
6
--messaging-binding.proxy-address whatsapp:TWI_SANDBOX_WA_NUMBER

Troubleshooting: If you get an error about the proxy address, verify:

  • You're using the correct Sandbox number
  • You've successfully joined the Sandbox
  • The numbers are in E.164 format

Step 6: Add a chat participant to the conversation

step-6-add-a-chat-participant-to-the-conversation page anchor

For this step, you'll add a chat Participant to the Conversation (remember that you can also add an SMS Participant).

The following code sample does this for you. You'll need to replace the following information:

  • CHXXXXXXXXXX: the Conversation SID.
  • <Chat_User_Identity>: the identity of your chat user. In this tutorial, you will use "chat-user".
1
# Install the twilio-cli from https://twil.io/cli
2
3
twilio api:conversations:v1:conversations:participants:create \
4
--conversation-sid CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
5
--identity "chat-user"

Conversation created. Two participants added.

You can start communicating.


Step 7: Send a message from WhatsApp to the Sandbox number

step-7-send-a-message-from-whatsapp-to-the-sandbox-number page anchor

Send a WhatsApp message to your Sandbox number. You should see it appear in the Conversation.

WhatsApp chat with business notification and first message saying 'Hello, it's from WA'.

Step 8: Reply via Conversations API

step-8-reply-via-conversations-api page anchor

Reply to the WhatsApp message using the Conversations API:

1
twilio api:conversations:v1:conversations:messages:create \
2
--conversation-sid CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
3
--author "chat-user" \
4
--body "Hello from the Conversations API"

Replace CHXXXXXXX with your Conversation SID and add the content of the message that you'd like to send.

WhatsApp chat showing a message from WA and a reply with a waving hand emoji.

Alternative: Using Messages API directly

alternative-using-messages-api-directly page anchor

If you're having issues with the Conversations approach, you can send messages directly using the Messages API:

1
# Using Twilio CLI
2
twilio api:core:messages:create \
3
--to whatsapp:YOUR_WHATSAPP_NUMBER \
4
--from whatsapp:TWILIO_SANDBOX_NUMBER \
5
--body "Direct message via Messages API"
6
7
# Or using curl
8
curl 'https://api.twilio.com/2010-04-01/Accounts/YOUR_ACCOUNT_SID/Messages.json' -X POST \
9
--data-urlencode 'To=whatsapp:YOUR_WHATSAPP_NUMBER' \
10
--data-urlencode 'From=whatsapp:TWILIO_SANDBOX_NUMBER' \
11
--data-urlencode 'Body=Direct message via Messages API' \
12
-u YOUR_ACCOUNT_SID:YOUR_AUTH_TOKEN

Step 9: Monitor your conversations

step-9-monitor-your-conversations page anchor

To verify messages are flowing through Conversations, check Monitor > Logs > Messaging(link takes you to an external page) in the Console.

Messages tab showing two entries from WhatsApp and chat user.

Troubleshooting common issues

troubleshooting-common-issues page anchor

"Conversation not found" errors

conversation-not-found-errors page anchor
  • Verify your Conversation SID is correct
  • Check that the Conversation was created successfully

WhatsApp messages not appearing

whatsapp-messages-not-appearing page anchor
  • Ensure you've joined the Sandbox correctly
  • Verify the webhook URL is cleared in Sandbox settings
  • Check that participants were added successfully
  • Verify your Account SID and Auth Token
  • Ensure Twilio CLI is authenticated: twilio profiles:list

Participant creation failures

participant-creation-failures page anchor
  • Double-check phone number format (E.164)
  • Verify you're using the correct Sandbox number
  • Ensure you've joined the Sandbox

You have learned how to connect Twilio Sandbox for WhatsApp with Conversations. Next steps: