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

Message Scheduling


(information)

Info

The Message Scheduling feature is only available for use with Messaging Services.

With the Programmable Messaging API, you can schedule SMS, MMS, and WhatsApp messages to be sent at a fixed time in the future.

Message Scheduling is included in Engagement Suite. Scheduling a message is free; you'll only pay for a message once it is sent. For information on Engagement Suite pricing, see the pricing pages for SMS/MMS or WhatsApp.


Before you begin

You first need to understand how to send outgoing, non-scheduled messages with Messaging Services. If you haven't done so, check out How to Send SMS with Messaging Services before you proceed.

If you want to schedule WhatsApp messages, you must have an approved WhatsApp sender added to your Messaging Service's Sender Pool. You also need to have pre-approved WhatsApp templates.


Schedule an outgoing message

A "scheduled message" is a Message resource with a Status of scheduled.

When you want to send a normal (non-scheduled) message via the Programmable Messaging API, you create a Message resource. You also need to create a Message resource when creating a scheduled message, but with the addition of two parameters: ScheduleType and SendAt.

Required parameters

The parameters required to create a scheduled message are listed below.

Required parameterRequired valueAdditional information
ScheduleTypefixedThis parameter/value combination indicates to Twilio that the message should be sent at a fixed time in the future.
SendAtA datetime string in ISO-8601 format (e.g., 2021-11-30T20:36:27Z)This is the date and time at which the message will be sent.

Messages must be scheduled at least 15 minutes before the intended send time. This means that the POST request that creates the Message resource must be sent at least 15 minutes before the SendAt value.

Messages must be scheduled no more than 35 days before the intended send time. This means that the POST request that creates the Message resource must be sent no more than 35 days before the SendAt value.
MessagingServiceSidThe Messaging Service SID from which the message will be sentNote: Without a MessagingServiceSid, Twilio treats the message as a non-scheduled message and the message is sent immediately.
Body or MediaUrl or ContentSidThe content of the scheduled message (e.g., "This is a scheduled message.")
ToThe recipient's phone number (e.g., +15558885333)

or

the recipient's channel address (e.g., whatsapp:+15558675310)

Create a scheduled message

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_22
// Download the helper library from https://www.twilio.com/docs/node/install
_22
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_22
_22
// Find your Account SID and Auth Token at twilio.com/console
_22
// and set the environment variables. See http://twil.io/secure
_22
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_22
const authToken = process.env.TWILIO_AUTH_TOKEN;
_22
const client = twilio(accountSid, authToken);
_22
_22
async function createMessage() {
_22
const message = await client.messages.create({
_22
body: "This is a scheduled message",
_22
messagingServiceSid: "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_22
scheduleType: "fixed",
_22
sendAt: new Date("2021-11-30 20:36:27"),
_22
to: "+15558675310",
_22
});
_22
_22
console.log(message.body);
_22
}
_22
_22
createMessage();

Output

_25
{
_25
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_25
"api_version": "2010-04-01",
_25
"body": "This is a scheduled message",
_25
"date_created": "Mon, 29 Nov 2021 22:40:10 +0000",
_25
"date_sent": null,
_25
"date_updated": "Mon, 29 Nov 2021 22:40:10 +0000",
_25
"direction": "outbound-api",
_25
"error_code": null,
_25
"error_message": null,
_25
"from": null,
_25
"messaging_service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_25
"num_media": "0",
_25
"num_segments": "0",
_25
"price": null,
_25
"price_unit": null,
_25
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_25
"status": "queued",
_25
"subresource_uris": {
_25
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
_25
},
_25
"tags": null,
_25
"to": "+15558675310",
_25
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
_25
}

Twilio's response

Twilio's response to your POST request indicates whether or not your message was scheduled successfully.

  • If your POST request to create the scheduled Message resource was valid, Twilio returns a 201 (scheduled) HTTP status code.
  • If your request was invalid, Twilio returns a 400 HTTP status code.

A scheduled Message resource has a Status of scheduled. You can check the status in the body of the response from Twilio, or by fetching the Message resource.

Note: No status callback event is emitted when a message is scheduled.

You should save the SID of the scheduled Message resource in case you need to cancel sending the message. This is found via the sid property of Twilio's response.

Below is an example of a response from Twilio, with the status and sid properties highlighted.


_24
{
_24
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_24
"api_version": "2010-04-01",
_24
"body": "This is a scheduled message",
_24
"date_created": "Mon, 29 Nov 2021 22:40:10 +0000",
_24
"date_sent": null,
_24
"date_updated": "Mon, 29 Nov 2021 22:40:10 +0000",
_24
"direction": "outbound-api",
_24
"error_code": null,
_24
"error_message": null,
_24
"from": null,
_24
"messaging_service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_24
"num_media": "0",
_24
"num_segments": "0",
_24
"price": null,
_24
"price_unit": null,
_24
"sid": "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_24
"status": "scheduled",
_24
"subresource_uris": {
_24
"media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media.json"
_24
},
_24
"to": "+15558675310",
_24
"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json"
_24
}


Send-time failures

Sometimes, a Message is successfully created with a Status of scheduled, but the message fails at the SendAt time. Two of these cases are covered below.

User-opt outs

User opt-outs do not automatically cancel scheduled messages. Scheduled messages to users who have opted out fail at the SendAt time.

If a user opts out of receiving messages, you can cancel the remaining scheduled messages to that user. See the "Cancel a scheduled message" section below for more information.

WhatsApp template validation failures

WhatsApp requires that business-initiated notifications sent by your application be templated and pre-registered, with the exception of messages sent as a reply to a user-initiated message. Check out Twilio's WhatsApp docs for more information.

Validation of pre-registered templates occurs at the SendAt time, not when the Message resource is created. Messages that don't use a pre-approved WhatsApp template fail at send time.


Cancel a scheduled message

To cancel a scheduled message, update the Message resource so that the Status is canceled.

A canceled status callback event is emitted when a Message resource's status transitions to canceled.

An example API request to cancel a scheduled message is shown below.

Cancel a scheduled message

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function updateMessage() {
_18
const message = await client
_18
.messages("SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_18
.update({ status: "canceled" });
_18
_18
console.log(message.to);
_18
}
_18
_18
updateMessage();

Output

_26
{
_26
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_26
"api_version": "2010-04-01",
_26
"body": "Hello World!",
_26
"date_created": "Fri, 24 May 2019 17:18:27 +0000",
_26
"date_sent": null,
_26
"date_updated": "Fri, 24 May 2019 18:18:28 +0000",
_26
"direction": "outbound-api",
_26
"error_code": null,
_26
"error_message": null,
_26
"from": null,
_26
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_26
"num_media": "0",
_26
"num_segments": "1",
_26
"price": null,
_26
"price_unit": "USD",
_26
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_26
"status": "canceled",
_26
"subresource_uris": {
_26
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMb7c0a2ce80504485a6f653a7110836f5/Media.json",
_26
"feedback": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMb7c0a2ce80504485a6f653a7110836f5/Feedback.json"
_26
},
_26
"tags": {},
_26
"to": "+18182008801",
_26
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMb7c0a2ce80504485a6f653a7110836f5.json"
_26
}


Maximum number of scheduled messages

Each Account (including Subaccounts) are allowed up to 500,000 scheduled messages (i.e. Message resources with scheduled statuses) at any given time. Subaccount limits are separate from the parent Account and do not consume the parent Account's allocation.


Additional resources


Rate this page: