When to use
Use this skill when you send at volume, across multiple numbers or regions, or need Twilio to manage sender selection, opt-outs, and scaling for you. A Messaging Service (an MG... SID) is a container that holds a pool of senders (long codes, toll-free numbers, short codes, WhatsApp senders) plus routing and compliance settings, and you send with MessagingServiceSid instead of a single From.
Reach for it when a single number is not enough: you want sticky sender per recipient, area-code geomatch, throughput scaling across the pool, or centralized STOP/START handling.
Not for: one-off sends from a single number (send with From per twilio-messaging-overview), choosing whether SMS/WhatsApp/RCS is right (use twilio-messaging-channel-advisor), or handling the inbound/status webhooks the service triggers (use twilio-messaging-webhooks).
Method
- Create the service.
POST https://messaging.twilio.com/v1/Services with FriendlyName. You get back an MG... SID. Set InboundRequestUrl and StatusCallback here to apply defaults to every sender in the pool.
- Add senders to the pool. Attach phone numbers via
POST /v1/Services/{ServiceSid}/PhoneNumbers (body PhoneNumberSid=PN...), short codes via /ShortCodes, and other channel senders via their respective sub-resources.
- Choose sender-selection behavior. Decision point: enable Sticky Sender (
StickySender=true) so a given recipient always sees the same number; enable Area Code Geomatch (AreaCodeGeomatch=true) so recipients get a local-area-code sender when one exists in the pool.
- Configure scaling and fallback. Decision point: enable
ScaleToLongCodes behavior / Smart Encoding, and set a fallback so that if a primary sender type is unavailable the service falls back to a long code in the pool.
- Turn on opt-out management. Set
Usecase and enable Advanced Opt-Out so the service auto-handles STOP/HELP/START keywords and maintains the opt-out list per sender, returning 21610 on blocked recipients.
- Link A2P 10DLC. Decision point (US long codes): associate the service with a registered A2P campaign via TrustHub, or long-code traffic is filtered (30007). Toll-free senders need toll-free verification instead.
- Send. Call
POST /Messages.json with MessagingServiceSid=MG... and no From; Twilio picks the sender from the pool per your rules.
- Sync / inspect.
GET /v1/Services/{ServiceSid} and its sub-resources to audit pool membership and settings.
Example
Create a service, attach a number, then send through it (Python helper lib):
from twilio.rest import Client
client = Client(account_sid, auth_token)
svc = client.messaging.v1.services.create(
friendly_name="Alerts",
sticky_sender=True,
area_code_geomatch=True,
inbound_request_url="https://example.com/incoming",
status_callback="https://example.com/status",
)
client.messaging.v1.services(svc.sid).phone_numbers.create(
phone_number_sid="PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
msg = client.messages.create(
to="+15558675310",
messaging_service_sid=svc.sid, # no from_; pool selects the sender
body="System back online.",
)
print(msg.sid, msg.status)
Pitfalls
- Do not pass both
From and MessagingServiceSid. Use exactly one; MessagingServiceSid delegates sender choice to the pool.
- Empty pool = no send. A service with zero senders cannot deliver; add at least one number/short code first.
- Sticky Sender needs pool diversity. With one number in the pool, sticky/geomatch are no-ops.
- Opt-out is per-sender by default. A recipient who sent STOP to one number may still be reachable from another unless Advanced Opt-Out centralizes it.
- Message-level
StatusCallback overrides the service default. If you set it per message, the service-level callback URL is ignored for that message.
- 10DLC registration is asynchronous. A newly created campaign is not active immediately; sending before approval still gets filtered.
Output format
This skill produces a configured MG... Messaging Service (SID, pool membership, selection flags, opt-out and callback settings) and outbound message resources sent through it. Each send returns a Message resource (SM... SID + status) whose sender was chosen from the pool.
Reference
- Service CRUD:
GET|POST https://messaging.twilio.com/v1/Services and .../Services/{ServiceSid}.
- Pool sub-resources:
.../Services/{ServiceSid}/PhoneNumbers, /ShortCodes, /AlphaSenders.
- Key service properties:
StickySender, AreaCodeGeomatch, SmartEncoding, InboundRequestUrl, InboundMethod, StatusCallback, Usecase, UseInboundWebhookOnNumber.
- Send with the service:
POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages.json with MessagingServiceSid=MG....
- Throughput: US long-code A2P MPS depends on the registered campaign's trust score / Twilio number type; toll-free supports higher throughput once verified; short codes are highest (~100+ MPS). Twilio queues excess and drains at the allowed rate; a large backlog can hit the validity period and expire.
- Compliance: A2P 10DLC brand + campaign registration via TrustHub for US long codes; toll-free verification for toll-free senders. Errors: 21610 (recipient opted out), 30007 (filtered), 21408 (region not enabled).
1---2name: twilio-messaging-services3version: 1.0.04description: Configure and send through a Twilio Messaging Service (MG SID) — sender pool, sticky sender, geomatch, scaling, opt-out, and fallback.5author: matrixx00706tags: [twilio, messaging-service, sms, a2p, scaling]7capabilities: []8metadata:9 source: https://skillmd.com/skills/matrixx0070/twilio-messaging-services10---1112## When to use1314Use this skill when you send at volume, across multiple numbers or regions, or need Twilio to manage sender selection, opt-outs, and scaling for you. A Messaging Service (an `MG...` SID) is a container that holds a pool of senders (long codes, toll-free numbers, short codes, WhatsApp senders) plus routing and compliance settings, and you send with `MessagingServiceSid` instead of a single `From`.1516Reach for it when a single number is not enough: you want sticky sender per recipient, area-code geomatch, throughput scaling across the pool, or centralized STOP/START handling.1718**Not for:** one-off sends from a single number (send with `From` per `twilio-messaging-overview`), choosing whether SMS/WhatsApp/RCS is right (use `twilio-messaging-channel-advisor`), or handling the inbound/status webhooks the service triggers (use `twilio-messaging-webhooks`).1920## Method21221. Create the service. `POST https://messaging.twilio.com/v1/Services` with `FriendlyName`. You get back an `MG...` SID. Set `InboundRequestUrl` and `StatusCallback` here to apply defaults to every sender in the pool.232. Add senders to the pool. Attach phone numbers via `POST /v1/Services/{ServiceSid}/PhoneNumbers` (body `PhoneNumberSid=PN...`), short codes via `/ShortCodes`, and other channel senders via their respective sub-resources.243. Choose sender-selection behavior. Decision point: enable Sticky Sender (`StickySender=true`) so a given recipient always sees the same number; enable Area Code Geomatch (`AreaCodeGeomatch=true`) so recipients get a local-area-code sender when one exists in the pool.254. Configure scaling and fallback. Decision point: enable `ScaleToLongCodes` behavior / Smart Encoding, and set a fallback so that if a primary sender type is unavailable the service falls back to a long code in the pool.265. Turn on opt-out management. Set `Usecase` and enable Advanced Opt-Out so the service auto-handles STOP/HELP/START keywords and maintains the opt-out list per sender, returning 21610 on blocked recipients.276. Link A2P 10DLC. Decision point (US long codes): associate the service with a registered A2P campaign via TrustHub, or long-code traffic is filtered (30007). Toll-free senders need toll-free verification instead.287. Send. Call `POST /Messages.json` with `MessagingServiceSid=MG...` and no `From`; Twilio picks the sender from the pool per your rules.298. Sync / inspect. `GET /v1/Services/{ServiceSid}` and its sub-resources to audit pool membership and settings.3031## Example3233Create a service, attach a number, then send through it (Python helper lib):3435```python36from twilio.rest import Client37client = Client(account_sid, auth_token)3839svc = client.messaging.v1.services.create(40 friendly_name="Alerts",41 sticky_sender=True,42 area_code_geomatch=True,43 inbound_request_url="https://example.com/incoming",44 status_callback="https://example.com/status",45)4647client.messaging.v1.services(svc.sid).phone_numbers.create(48 phone_number_sid="PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"49)5051msg = client.messages.create(52 to="+15558675310",53 messaging_service_sid=svc.sid, # no from_; pool selects the sender54 body="System back online.",55)56print(msg.sid, msg.status)57```5859## Pitfalls6061- Do not pass both `From` and `MessagingServiceSid`. Use exactly one; `MessagingServiceSid` delegates sender choice to the pool.62- Empty pool = no send. A service with zero senders cannot deliver; add at least one number/short code first.63- Sticky Sender needs pool diversity. With one number in the pool, sticky/geomatch are no-ops.64- Opt-out is per-sender by default. A recipient who sent STOP to one number may still be reachable from another unless Advanced Opt-Out centralizes it.65- Message-level `StatusCallback` overrides the service default. If you set it per message, the service-level callback URL is ignored for that message.66- 10DLC registration is asynchronous. A newly created campaign is not active immediately; sending before approval still gets filtered.6768## Output format6970This skill produces a configured `MG...` Messaging Service (SID, pool membership, selection flags, opt-out and callback settings) and outbound message resources sent through it. Each send returns a `Message` resource (`SM...` SID + `status`) whose sender was chosen from the pool.7172## Reference7374- Service CRUD: `GET|POST https://messaging.twilio.com/v1/Services` and `.../Services/{ServiceSid}`.75- Pool sub-resources: `.../Services/{ServiceSid}/PhoneNumbers`, `/ShortCodes`, `/AlphaSenders`.76- Key service properties: `StickySender`, `AreaCodeGeomatch`, `SmartEncoding`, `InboundRequestUrl`, `InboundMethod`, `StatusCallback`, `Usecase`, `UseInboundWebhookOnNumber`.77- Send with the service: `POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages.json` with `MessagingServiceSid=MG...`.78- Throughput: US long-code A2P MPS depends on the registered campaign's trust score / Twilio number type; toll-free supports higher throughput once verified; short codes are highest (~100+ MPS). Twilio queues excess and drains at the allowed rate; a large backlog can hit the validity period and expire.79- Compliance: A2P 10DLC brand + campaign registration via TrustHub for US long codes; toll-free verification for toll-free senders. Errors: 21610 (recipient opted out), 30007 (filtered), 21408 (region not enabled).