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:

  1. One phone numbers per hotline for Calls (can also send SMS).
  2. One Notify service
  3. 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.

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.

  1. Navigate to twilio.com/try-twilio
  2. Click Sign up and complete the registration form
  3. Verify your email address by clicking the link in the confirmation email
  4. Verify your phone number when prompted
  5. 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

  1. Log in to the Twilio Console
  2. Navigate to Billing from the left sidebar or account dropdown
  3. Click Upgrade if you're on a trial account
  4. Select Pay As You Go (recommended for most applications)
  5. Click Add Payment Method
  6. Enter your credit card information and billing address
  7. Review and accept the terms of service
  8. Click Submit
  1. In the Billing section, click Billing Alerts
  2. Click Create Alert
  3. Set a threshold amount (e.g., $50 or $100)
  4. Enter email addresses to receive alerts
  5. 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

  1. In the Twilio Console, navigate to Messaging > Regulatory Compliance
  2. Click Brands or Get Started under A2P 10DLC
  3. Click Create a Brand
  4. Select your business type:
    • Sole Proprietor - For individuals or small businesses
    • Standard - For registered businesses (requires EIN/Tax ID)
  5. 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
  6. Review and submit the brand registration
  7. Wait for approval (typically 1-5 business days)

Create a Campaign

Once your brand is approved:

  1. Navigate to Messaging > Regulatory Compliance > Campaigns
  2. Click Create a Campaign
  3. Select your approved brand
  4. 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
  5. Review opt-in and opt-out compliance requirements
  6. Submit the campaign for review
  7. 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

  1. Navigate to Phone Numbers > Manage > Buy a number
  2. Select your country (default: United States)
  3. Filter by capabilities:
    • Check SMS (required)
    • Check MMS if sending images
    • Optionally check Voice if needed for calls
  4. 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
  5. Browse available numbers and click Buy next to your chosen number
  6. Confirm the purchase

Associate Number with Your Campaign

  1. After purchasing, you'll be prompted to associate the number with your A2P campaign
  2. Select your approved campaign from the dropdown
  3. Click Confirm
  4. 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…)

  1. Navigate to Messaging > Services in the Twilio Console
  2. Click Create Messaging Service
  3. Enter a friendly name for your service (e.g., "Production SMS Service")
  4. Select Notify my users as the use case
  5. Click Create Messaging Service
  6. Copy the Messaging Service SID (starts with MG...) — you will need it in the next step

Create the Notify Service (IS…)

  1. Navigate to Explore Products > Notify > Services
  2. Click Create Notify Service (or Create Service)
  3. Enter a friendly name (e.g., "Production Notify")
  4. Under Messaging Service SID, select the MG… service you just created
  5. Click Save
  6. Copy the Service SID — it starts with IS.... This is the value for TWILIO_NOTIFY_SERVICE_SID in your .env file

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

  1. In your Messaging Service, click the Sender Pool tab
  2. Click Add Senders
  3. Select Phone Number as the sender type
  4. Check the boxes next to the phone numbers you want to add
  5. Click Add Phone Numbers

Important: Numbers in the sender pool will be used for outbound SMS only.

Configure the Messaging Service

  1. Click the Integration tab
  2. Ensure Process Inbound Messages is configured if you need to handle replies
  3. Configure webhook URLs if needed for delivery status callbacks
  4. Click Save

For production applications, it's recommended to have multiple numbers in your sender pool:

  1. Purchase 3-5 additional phone numbers following Step 4
  2. Associate each number with your A2P campaign
  3. 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:

  1. Navigate to the Twilio Console Dashboard
  2. Your Account SID is displayed in the "Account Info" section
  3. Your Auth Token is hidden by default - click Show to reveal it
  4. Click the copy icon to copy each value

Notify Service SID (the value for TWILIO_NOTIFY_SERVICE_SID):

  1. Navigate to Explore Products > Notify > Services
  2. Click on your Notify service
  3. 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

  1. Navigate to Messaging > Services > Your Service
  2. Click Try it Out
  3. Enter a phone number to send to (must be in E.164 format: +1234567890)
  4. Enter a test message
  5. Click Send Test SMS

Verify Number Pool Distribution

After sending several test messages, check the messaging logs:

  1. Navigate to Monitor > Logs > Messaging
  2. Verify messages are being sent from different numbers in your pool
  3. 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

Additional Resources

Previous
Requirements
Next
Email