Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Send Messages with Messaging Services


Using a Messaging Service improves your customers' SMS or WhatsApp messaging experience with routing intelligence and content features that you can control from the Twilio Console(link takes you to an external page). With Messaging Service features, you can localize outgoing phone numbers, distribute bulk text messaging across multiple senders, lock one number to a customer, and much more. A default Messaging Service is automatically generated for your Account upon creation.

This guide covers what a Messaging Service can do for your business and shows you how to set up a Service to send messages in your application.

To run any of the code samples found here, you can run the code samples in your local development environment, use the Twilio CLI, or use curl commands in your terminal.

For instructions on setting up your local environment select your programming language of choice below:

  • Ruby
  • Python
  • PHP
  • Node.js
  • Java
  • C#
  • Go

Let's get started!


Why use a Messaging Service?

why-use-a-messaging-service page anchor

Sending messages at a high volume and/or at a global scale quickly balloons in complexity. That's why Twilio Programmable Messaging encourages the use of Messaging Services to manage your senders, maintain compliance with local carrier regulations, and create a smooth and consistent messaging experience for your end users.

Some Messaging Service features include:

  • Sticky Sender : Use the same From phone number to message a given customer for a consistent experience
  • Smart Encoding : Save space (and money!) by automatically converting hard-to-catch Unicode characters to UCS-2 compliant characters
  • MMS Converter : Automatically convert links to media files for areas in which MMS is not supported
  • Advanced Opt-Out : Manage your opt-out, opt-in, and help keywords and messages
  • Sender ID pre-registration alert : Get notifications when you are sending messages in countries that require pre-registration of your Alphanumeric Sender ID
  • ...and more!

For more information, check out the Messaging Service Overview page.


Create and Configure a Messaging Service

create-and-configure-a-messaging-service page anchor

An auto-generated default Messaging Service has been created for you, or you can create a Messaging Service through the Twilio Console(link takes you to an external page) or using the REST API with the following code:

Create a Messaging Service

create-a-messaging-service page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.messaging.v1.services
_10
.create({friendlyName: 'My First Messaging Service'})
_10
.then(service => console.log(service.sid));

Output

_33
{
_33
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_33
"sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_33
"date_created": "2015-07-30T20:12:31Z",
_33
"date_updated": "2015-07-30T20:12:33Z",
_33
"friendly_name": "My First Messaging Service",
_33
"inbound_request_url": "https://www.example.com/",
_33
"inbound_method": "POST",
_33
"fallback_url": "https://www.example.com",
_33
"fallback_method": "GET",
_33
"status_callback": "https://www.example.com",
_33
"sticky_sender": true,
_33
"smart_encoding": false,
_33
"mms_converter": true,
_33
"fallback_to_long_code": true,
_33
"scan_message_content": "inherit",
_33
"area_code_geomatch": true,
_33
"validity_period": 600,
_33
"synchronous_validation": true,
_33
"usecase": "marketing",
_33
"us_app_to_person_registered": false,
_33
"use_inbound_webhook_on_number": true,
_33
"links": {
_33
"phone_numbers": "https://messaging.twilio.com/v1/Services/MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/PhoneNumbers",
_33
"short_codes": "https://messaging.twilio.com/v1/Services/MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ShortCodes",
_33
"alpha_senders": "https://messaging.twilio.com/v1/Services/MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/AlphaSenders",
_33
"messages": "https://messaging.twilio.com/v1/Services/MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages",
_33
"us_app_to_person": "https://messaging.twilio.com/v1/Services/MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Compliance/Usa2p",
_33
"us_app_to_person_usecases": "https://messaging.twilio.com/v1/Services/MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Compliance/Usa2p/Usecases",
_33
"channel_senders": "https://messaging.twilio.com/v1/Services/MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ChannelSenders"
_33
},
_33
"url": "https://messaging.twilio.com/v1/Services/MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_33
}

Take note of the Messaging Service SID (a string starting with MGXX) that the code prints to your console: you need this SID in future steps in this guide.


Purchase an SMS capable phone number

purchase-an-sms-capable-phone-number page anchor

Sending SMS messages requires an SMS capable phone number. You can search for and purchase available phone numbers(link takes you to an external page) in the Console. When you search, make sure that the number you choose is SMS capable. Check the appropriate box in the search UI to filter available numbers to those that are SMS capable.

Search for SMS Capable Number.Rate this page:

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.