Requirements
Twilio
Set up Twilio for calls, SMS/MMS and the notify service, including A2P 10DLC registration.
This document describes how to set up Twilio for SMS/MMS and Call functionality in the application.
Overview
The application uses Twilio's Voice API to receive calls and forward them to operators. and Twilio's Messaging and Notify API to send SMS messages to users. Twilio Notify provides a messaging pool that automatically distributes messages across multiple phone numbers to improve deliverability and throughput.
Note: The phone numbers you buy for hotlines (to make and receive calls) should not form part of the sender pool for the notify service.
You will need:
- One phone numbers per hotline for Calls (can also send SMS).
- One Notify service
- Many phone numbers that can be added to the Notify services' Sender Pool to distribute messages across multiple numbers. The number here depends on how large your audience is.
Environment Configuration
Once you have followed the steps below, you will add the following credentials
to your .env file:
# Twilio Configuration
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TWILIO_AUTH_TOKEN=your_auth_token_here
TWILIO_NOTIFY_SERVICE_SID=ISxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TWILIO_DEBUG=False
TWILIO_NOTIFY_SERVICE_SID must be a Notify Service SID, which starts with
IS. It is not the Messaging Service SID (MG…). The two are different
resources and it is easy to grab the wrong one — a Notify Service references a
Messaging Service, and only the Notify Service SID belongs in this variable.
Step 5 walks through creating both.
Setting Up From the Dashboard (Recommended)
Most of what follows can be done for you. Once TWILIO_ACCOUNT_SID and
TWILIO_AUTH_TOKEN are set and the app is running, sign in as a dashboard admin
and visit:
/d/admin/twilio/
That page checks every item below and offers a one-click fix for each thing it can do itself — creating the Notify and Messaging Services, adding numbers to the sender pool, buying new numbers, and repairing hotline webhook URLs. Values it provisions are saved to the database, so no redeploy is needed.
Two things it cannot do, which you must still do by hand in the Console:
- A2P 10DLC brand and campaign registration (Step 3) — there is no API for it on the Twilio SDK version this project pins.
- Setting
TWILIO_ACCOUNT_SID/TWILIO_AUTH_TOKEN, which are supplied by the environment and are never collected in the app. The page reports whether they work, but changing them means changing the environment and redeploying.
The rest of this document is the manual path, and remains the reference for what
the setup page is doing on your behalf. You can also run the same checks from a
shell with just preflight --twilio.
Prerequisites
- A valid payment method (credit card)
- Business information (.e.g. EIN) for A2P 10DLC registration.
- An explanation of your hotlines' use case and sample messages.
Step 1: Sign Up for Twilio
NOTE: We recommend singing up with your organization's email and adding additional billing/admin users.
- Navigate to twilio.com/try-twilio
- Click Sign up and complete the registration form
- Verify your email address by clicking the link in the confirmation email
- Verify your phone number when prompted
- Complete the onboarding questionnaire about your use case
Trial Account Notes:
- Trial accounts receive free credits for testing
- Trial accounts can only send messages to verified phone numbers
- You'll need to upgrade to a paid account for production use
Step 2: Set Up Billing
- Log in to the Twilio Console
- Navigate to Billing from the left sidebar or account dropdown
- Click Upgrade if you're on a trial account
- Select Pay As You Go (recommended for most applications)
- Click Add Payment Method
- Enter your credit card information and billing address
- Review and accept the terms of service
- Click Submit
Set Up Billing Alerts (Recommended)
- In the Billing section, click Billing Alerts
- Click Create Alert
- Set a threshold amount (e.g., $50 or $100)
- Enter email addresses to receive alerts
- Click Save
Step 3: Register an A2P Campaign
Important: In the United States and Canada, all application-to-person (A2P) messaging requires campaign registration under the 10DLC (10-Digit Long Code) program. This process can take 1-2 weeks for approval.
Register Your Business
- In the Twilio Console, navigate to Messaging > Regulatory Compliance
- Click Brands or Get Started under A2P 10DLC
- Click Create a Brand
- Select your business type:
- Sole Proprietor - For individuals or small businesses
- Standard - For registered businesses (requires EIN/Tax ID)
- Fill out the business information form:
- Legal business name
- Business address
- Business type and industry
- Tax ID (EIN) for standard brands
- Website URL
- Business contact information
- Review and submit the brand registration
- Wait for approval (typically 1-5 business days)
Create a Campaign
Once your brand is approved:
- Navigate to Messaging > Regulatory Compliance > Campaigns
- Click Create a Campaign
- Select your approved brand
- Fill out the campaign details:
- Campaign Use Case - Select the category that best matches your usage (e.g., "Marketing", "Account Notifications", "2FA")
- Campaign Description - Describe how you'll use SMS (e.g., "Order confirmations and delivery updates")
- Sample Messages - Provide 2-3 example messages you'll send
- Message Flow - Describe when/how users opt in to receive messages
- Call to Action - Describe any actions users can take
- Terms and Privacy Policy URLs - Links to your T&C and privacy policy
- Review opt-in and opt-out compliance requirements
- Submit the campaign for review
- Wait for approval (typically 1-2 weeks)
Pricing: Campaign registration typically costs $4/month per campaign after initial registration fees.
Step 4: Buy a Phone Number
Once your A2P campaign is approved, you can purchase phone numbers.
Guidelines for Choosing a Local Number
Best Practices:
- Match your users' area codes - Users are more likely to engage with local numbers
- Buy multiple numbers - Distribute message volume across numbers for better deliverability
- Consider toll-free - Toll-free numbers (800, 888, etc.) can be used for branded messaging
- Check carrier approval - Ensure numbers support SMS/MMS on major carriers
Purchase Your First Number
- Navigate to Phone Numbers > Manage > Buy a number
- Select your country (default: United States)
- Filter by capabilities:
- Check SMS (required)
- Check MMS if sending images
- Optionally check Voice if needed for calls
- Search by area code or region:
- Enter your local area code (e.g., "415" for San Francisco)
- Or select a state/city from the dropdown
- Browse available numbers and click Buy next to your chosen number
- Confirm the purchase
Associate Number with Your Campaign
- After purchasing, you'll be prompted to associate the number with your A2P campaign
- Select your approved campaign from the dropdown
- Click Confirm
- Wait for the association to be processed (can take a few minutes)
Pricing: Local phone numbers typically cost $1.15/month, with message costs around $0.0079 per SMS segment.
Step 5: Create a Messaging Service and a Notify Service
This step creates two resources, and they are easy to confuse:
| Resource | SID prefix | What it does |
|---|---|---|
| Messaging Service | MG… |
Holds the sender pool — the numbers outbound SMS is sent from |
| Notify Service | IS… |
The broadcast API this app calls; it points at a Messaging Service |
The app sends broadcasts through Notify, so TWILIO_NOTIFY_SERVICE_SID must
be the IS… value. The MG… value is not used directly by the app — the Notify
Service knows about it.
The setup page at
/d/admin/twilio/creates both of these correctly with two clicks and stores the result. The manual steps below are the equivalent.
Create the Messaging Service (MG…)
- Navigate to Messaging > Services in the Twilio Console
- Click Create Messaging Service
- Enter a friendly name for your service (e.g., "Production SMS Service")
- Select Notify my users as the use case
- Click Create Messaging Service
- Copy the Messaging Service SID (starts with
MG...) — you will need it in the next step
Create the Notify Service (IS…)
- Navigate to Explore Products > Notify > Services
- Click Create Notify Service (or Create Service)
- Enter a friendly name (e.g., "Production Notify")
- Under Messaging Service SID, select the
MG…service you just created - Click Save
- Copy the Service SID — it starts with
IS.... This is the value forTWILIO_NOTIFY_SERVICE_SIDin your.envfile
If you put an MG… SID into TWILIO_NOTIFY_SERVICE_SID, the app will start
normally but every broadcast will fail, because it looks the SID up against the
Notify API. The setup page detects this specific mistake and names it.
Add Phone Numbers to the Service Pool
- In your Messaging Service, click the Sender Pool tab
- Click Add Senders
- Select Phone Number as the sender type
- Check the boxes next to the phone numbers you want to add
- Click Add Phone Numbers
Important: Numbers in the sender pool will be used for outbound SMS only.
Configure the Messaging Service
- Click the Integration tab
- Ensure Process Inbound Messages is configured if you need to handle replies
- Configure webhook URLs if needed for delivery status callbacks
- Click Save
Buy Additional Numbers for the Pool (Recommended)
For production applications, it's recommended to have multiple numbers in your sender pool:
- Purchase 3-5 additional phone numbers following Step 4
- Associate each number with your A2P campaign
- Add all numbers to your Notify service sender pool
Benefits of Multiple Numbers:
- Improved message throughput
- Better deliverability rates
- Reduced carrier filtering
- Load balancing across carriers
Important: Do Not Use Primary Numbers for Calls
Critical: Phone numbers added to a Notify service sender pool should be dedicated to SMS only. Do not use these numbers for voice calls or as your primary contact numbers.
Why?
- Notify automatically rotates numbers for message delivery
- You cannot control which number sends a specific message
- Users may save and try to call these numbers
- Incoming calls to pooled numbers may not route as expected
Recommendation: If you need a number for voice calls (customer support, verification calls, etc.), purchase a separate dedicated number that is NOT added to the Notify sender pool.
Finding Your Credentials
Account SID and Auth Token:
- Navigate to the Twilio Console Dashboard
- Your Account SID is displayed in the "Account Info" section
- Your Auth Token is hidden by default - click Show to reveal it
- Click the copy icon to copy each value
Notify Service SID (the value for TWILIO_NOTIFY_SERVICE_SID):
- Navigate to Explore Products > Notify > Services
- Click on your Notify service
- Copy the Service SID — it starts with
IS
Do not use the Messaging Service SID (MG…) here; see Step 5 for why they are
different.
Debug Mode
Set TWILIO_DEBUG=True during development to enable detailed logging. Always
set to False in production to avoid logging sensitive information.
Testing Your Configuration
Send a Test Message via Console
- Navigate to Messaging > Services > Your Service
- Click Try it Out
- Enter a phone number to send to (must be in E.164 format: +1234567890)
- Enter a test message
- Click Send Test SMS
Verify Number Pool Distribution
After sending several test messages, check the messaging logs:
- Navigate to Monitor > Logs > Messaging
- Verify messages are being sent from different numbers in your pool
- Check delivery status for any failures
Best Practices
Message Content
- Always include opt-out instructions (e.g., "Reply STOP to unsubscribe")
- Keep messages concise and relevant
- Include your brand name in messages
- Avoid spam trigger words (FREE, WINNER, ACT NOW, etc.)
Compliance
- Obtain explicit opt-in consent before sending messages
- Honor opt-out requests immediately
- Maintain opt-in/opt-out records
- Don't share phone numbers with third parties
- Send messages only during reasonable hours (8am-9pm local time)
Rate Limiting
- Respect Twilio's rate limits (1 message per second per number by default)
- The Notify service automatically handles rate limiting across your number pool
- Monitor your messaging logs for throttling errors
Cost Management
- Monitor your SMS usage regularly
- Set up billing alerts to avoid unexpected charges
- Consider message segmentation - messages over 160 characters cost more
- Use appropriate campaign types to get the best throughput rates
Troubleshooting
"Unable to create record: Your trial account doesn't have access..."
- You need to upgrade to a paid account
- Navigate to Billing and upgrade your account
"Unverified phone number"
- Trial accounts can only send to verified numbers
- Upgrade to a paid account for unrestricted sending
Messages Not Sending or Delayed
- Verify your A2P campaign is approved and active
- Check that phone numbers are associated with your campaign
- Ensure numbers are added to the Notify service sender pool
- Review messaging logs for specific error codes
"Invalid Phone Number" Errors
- Phone numbers must be in E.164 format (+1234567890)
- Verify the number includes country code
- Check for special characters or spaces
Campaign Rejected
- Review rejection reason in the console
- Ensure your use case matches your sample messages
- Provide clear opt-in/opt-out procedures
- Update and resubmit with corrections