Send WhatsApp Messages with Twilio – Complete 2025 Guide

Send WhatsApp Messages with Twilio – Complete 2025 Guide

Twilio’s WhatsApp Business API lets any developer or small business deliver appointment reminders, dispatch alerts or boarding passes straight to a customer’s WhatsApp inbox. The set-up is shorter than a coffee break and costs less than a London bus fare.

What You Need Before You Start

  • A Twilio account (free trial gives you Ā£12 credit – enough for roughly 1,200 UK WhatsApp messages)
  • A mobile phone with WhatsApp installed (for testing)
  • Python 3.9+ or Node.js 18+ (examples below use Python)

Step 1 – Activate the WhatsApp Sandbox

  1. Log in to console.twilio.com
  2. Choose ā€œExplore Productsā€ → ā€œMessagingā€ → ā€œTry WhatsAppā€
  3. Copy the **sandbox number** (it looks like +1 415 523 8886) and the **join code** (e.g., join abc123)
  4. Open WhatsApp on your phone, send the join code to the sandbox number – this pairs your handset for testing

Step 2 – Grab Your Credentials

Still in the console, note:

  • Account SID (starts AC…)
  • Auth Token (keep this private)

Store them as environment variables so you never hard-code keys:

export TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxx
export TWILIO_AUTH_TOKEN=your_auth_token

Step 3 – Install Twilio’s Helper Library

pip install twilio

Step 4 – Send Your First Message

Create send_whatsapp.py and paste:

import os
from twilio.rest import Client
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token  = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)
message = client.messages.create(
from_="whatsapp:+14155238886",  # sandbox number
to="whatsapp:+447700900123",     # your phone in E.164
body="Hello from Twilio and husham.com!"
)
print(f"Message sent: {message.sid}")

Run:

 

python send_whatsapp.py

Your phone should receive the text within seconds.

Step 5 – Using a Template (Business-Initiated)

Outside the 24-hour ā€œcustomer care windowā€ you must use a Twilio-approved template. In the console:

  1. ā€œMessagingā€ → ā€œTemplatesā€ → ā€œCreate a new templateā€
  2. Example: Your appointment is on {{1}} at {{2}}.
  3. Submit for WhatsApp approval (usually 2–4 minutes in 2025)

Once approved, swap the body for a content_sid call:

message = client.messages.create(
        from_="whatsapp:+14155238886",
        to="whatsapp:+447700900123",
        content_sid="HXb5b62575e6e4ff6129ad7c8efe1f983e",
        content_variables='{"1":"22 July 2026","2":"3:15pm"}'
      )

Pricing Quick View (October 2025)

  • UK – 4.2 p per outbound template message
  • UK – 2.1 p per outbound ā€œsessionā€ message (inside 24-hour window)
  • Incoming messages are free
  • No monthly fee; you only pay for what you send

Common Pitfalls

  • Wrong prefix – always use whatsapp: before the number
  • Non-E.164 – UK mobiles must start +447, not 07
  • Template outside window – WhatsApp will reject free-form text after 24 hours

Going Live (Next Steps)

  1. Buy a real Twilio number (Ā£1/month)
  2. Complete Facebook Business verification (WhatsApp owns the pipes)
  3. Submit your display name for approval (24-hour SLA)
  4. Replace the sandbox number with your own in the code

Bottom Line

With a single API call you can reach customers where open rates exceed 90%. Twilio’s pay-as-you-go model keeps costs predictable, and the sandbox lets you prototype for free. For real-world gotchas, template ideas or billing hacks, jump into the husham.com forum – the thread is updated every time WhatsApp tweaks its policy.

Pricing & policy accurate: 28 October 2025