📲 Integrating Twilio into your project: Part 2 - Setting up the Sandbox and Handling Webhooks
Nico Montiel

Nico Montiel @nicolasmontielf

About: I enjoy crafting concise articles on specific topics, perfect for a quick two-minute read. Short and sweet 👾 If you have a cool project and need help, let me know!

Location:
Asunción, Paraguay
Joined:
Oct 15, 2020

📲 Integrating Twilio into your project: Part 2 - Setting up the Sandbox and Handling Webhooks

Publish Date: May 27
0 0

1. Joining the Twilio Sandbox

Before you can start receiving messages via Webhook, you need to join the WhatsApp Sandbox.

Here's how:

  1. In your Twilio Console, navigate to Messaging > Try it Out > Send a WhatsApp message.
  2. You’ll see a Sandbox section.
  3. Send the provided code (something like "join magic-pizza") to the given WhatsApp number. In my case, it was "join control-type".

✅ Done! Your phone is now linked to the Sandbox.

Image of Twilio sandbox

Important:
Only registered numbers can send and receive messages in the Sandbox. If you change phones or SIMs, you’ll need to register again.

2. Setting up your Webhook URL

Next, you’ll tell Twilio where to send incoming messages.

In the Sandbox settings, set your Webhook URL for incoming messages (e.g., https://yourdomain.com/webhook).

You can do this on the same page, under the "Sandbox Settings" tab.

Image of Twilio sandbox

Make sure your server can accept POST requests from Twilio.

Now, every time that phone number receives a WhatsApp message, Twilio will send the message to your webhook so you can handle the incoming message.

Twilio will send a payload like this:

{
    "SmsMessageSid": "SMc8df133659ef2ca4251da5b1ac5453cdg",
    "NumMedia": "0",
    "ProfileName": "John Smith",
    "MessageType": "text",
    "SmsSid": "SMc8df133659ef2ca4251da5b1ac5453cdg",
    "WaId": "+157822787582693",
    "SmsStatus": "received",
    "Body": "The body of the message that you are receiving",
    "To": "whatsapp:+157822787584443",
    "NumSegments": "1",
    "ReferralNumMedia": "0",
    "MessageSid": "SMc8df133659ef2ca4251da5b1ac5453cdg",
    "AccountSid": "youraccountId",
    "From": "whatsapp:+157822787582693",
    "ApiVersion": "2010-04-01"
}
Enter fullscreen mode Exit fullscreen mode

We'll code a real webhook handler in the next part 😉

Comments 0 total

    Add comment