Skip to contentSkip to navigationSkip to topbar
On this page

Using Messaging Services with Content Template Builder


Using a Messaging Service is not only a prerequisite of using the Content Templates, but also a great tool to organize your account and reduce complexity as your messaging application grows. To learn more about Messaging Services, click here. To create a messaging service, navigate to the Messenger section of your console.

MSGSER1.

Send Messages with a Messaging Service in the "From" field

send-messages-with-a-messaging-service-in-the-from-field page anchor

There are multiple ways to send a template created with the Content Template Builder. One way is to add a Sender to a Messaging Service's Sender Pool and specify the Messaging Service Sid (MGXXXX...XXXX) in the send request's "From" field.

How to Add Channel Specific Senders to a Sender Pool

how-to-add-channel-specific-senders-to-a-sender-pool page anchor

To add a specific channel's sender to a Messaging Service's Sender Pool, go to the Messaging Service and click edit. In the edit screen, there is a "Sender Pool" Section with the following options to add.

  1. Phone Number
  2. Short Code
  3. Alpha Sender
  4. WhatsApp Number
  5. Facebook Messenger (Public Beta) - If you do not see this option, file a support ticket asking to enable the feature for your account: Enable the FBM messaging service setting to add FBM Senders to your existing Messaging Service. For more information read our Facebook Messenger documentation.
MSGSER2.
Send a message with a Messaging Service SID in the From fieldLink to code sample: Send a message with a Messaging Service SID in the From field
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createMessage() {
11
const message = await client.messages.create({
12
contentSid: "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
13
from: "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
14
to: "whatsapp:+15551234567",
15
});
16
17
console.log(message.body);
18
}
19
20
createMessage();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"api_version": "2010-04-01",
4
"body": "Hello! 👍",
5
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
6
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
7
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
8
"direction": "outbound-api",
9
"error_code": null,
10
"error_message": null,
11
"from": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
12
"num_media": "0",
13
"num_segments": "1",
14
"price": null,
15
"price_unit": null,
16
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
17
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"status": "queued",
19
"subresource_uris": {
20
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
21
},
22
"tags": {
23
"campaign_name": "Spring Sale 2022",
24
"message_type": "cart_abandoned"
25
},
26
"to": "whatsapp:+15551234567",
27
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
28
}

Send Messages with a Phone Number in the "From" field

send-messages-with-a-phone-number-in-the-from-field page anchor

Another way to send messages is to use the phone number in the from field and specify a MessagingServiceSid field. This allows you to dedicate a "From" field for compliance or any other reason. If you would like to utilize this method, you do not have to add the channel sender to the messaging service's sender pool, but a valid messaging service is still required.

Send a message with a phone number or channel address in the From fieldLink to code sample: Send a message with a phone number or channel address in the From field
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createMessage() {
11
const message = await client.messages.create({
12
contentSid: "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
13
from: "whatsapp:+15559991111",
14
messagingServiceSid: "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
15
to: "whatsapp:+15551234567",
16
});
17
18
console.log(message.body);
19
}
20
21
createMessage();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"api_version": "2010-04-01",
4
"body": "Hello! 👍",
5
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
6
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
7
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
8
"direction": "outbound-api",
9
"error_code": null,
10
"error_message": null,
11
"from": "whatsapp:+15559991111",
12
"num_media": "0",
13
"num_segments": "1",
14
"price": null,
15
"price_unit": null,
16
"messaging_service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
17
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"status": "queued",
19
"subresource_uris": {
20
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
21
},
22
"tags": {
23
"campaign_name": "Spring Sale 2022",
24
"message_type": "cart_abandoned"
25
},
26
"to": "whatsapp:+15551234567",
27
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
28
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.