Programmable Chat has been deprecated and is no longer supported. Instead, we'll be focusing on the next generation of chat: Twilio Conversations. Find out more about the EOL process here.
If you're starting a new project, please visit the Conversations Docs to begin. If you've already built on Programmable Chat, please visit our Migration Guide to learn about how to switch.
The Message resource of Programmable Chat represents a single message within a Channel in a Service instance. Creating a new Message resource sends a message to the Channel. Fetching and Reading Message resources provide information about previously sent messages.
Each Message resource contains these properties.
The unique string that we created to identify the Message resource.
^IM[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Account that created the Message resource.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The JSON string that stores application-specific data. If attributes have not been set, {}
is returned.
The SID of the Service the Message resource is associated with.
^IS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Channel that the message was sent to.
^CH[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Channel the Message resource belongs to.
^CH[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The date and time in GMT when the resource was created specified in ISO 8601 format.
The date and time in GMT when the resource was last updated specified in ISO 8601 format.
The Identity of the User who last updated the Message, if applicable.
The Identity of the message's author. The default value is system
.
The index of the message within the Channel. Indices may skip numbers, but will always be in order of when the message was received.
0
An object that describes the Message's media, if the message contains media. The object contains these fields: content_type
with the MIME type of the media, filename
with the name of the media, sid
with the SID of the Media resource, and size
with the media object's file size in bytes. If the Message has no media, this value is null
.
The absolute URL of the Message resource.
POST https://chat.twilio.com/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages
The {ChannelSid}
value can be the Channel resource's sid
or unique_name
.
Creating a new Message resource in a Channel sends a message to the Channel.
The X-Twilio-Webhook-Enabled HTTP request header
true
false
The SID of the Service to create the Message resource under.
^IS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
application/x-www-form-urlencoded
The Identity of the new message's author. The default value is system
.
A valid JSON string that contains application-specific data.
The date, specified in ISO 8601 format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. This parameter should only be used when a Chat's history is being recreated from a backup/separate source.
The date, specified in ISO 8601 format, to assign to the resource as the date it was last updated.
The Identity of the User who last updated the Message, if applicable.
The message to send to the channel. Can be an empty string or null
, which sets the value as an empty string. You can send structured data in the body by serializing it as a string.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createMessage() {11const message = await client.chat.v212.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.channels("ChannelSid")14.messages.create({ body: "Hello, world!" });1516console.log(message.sid);17}1819createMessage();
1{2"sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",6"channel_sid": "ChannelSid",7"attributes": null,8"date_created": "2016-03-24T20:37:57Z",9"date_updated": "2016-03-24T20:37:57Z",10"last_updated_by": "system",11"was_edited": false,12"from": "system",13"body": "Hello, world!",14"index": 0,15"type": "text",16"media": null,17"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"18}
GET https://chat.twilio.com/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}
The {ChannelSid}
value can be the Channel resource's sid
or unique_name
.
The SID of the Service to fetch the Message resource from.
^IS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Channel the Message resource to fetch belongs to. This value can be the Channel resource's sid
or unique_name
.
The SID of the Message resource to fetch.
^IM[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function fetchMessage() {11const message = await client.chat.v212.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.channels("ChannelSid")14.messages("IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")15.fetch();1617console.log(message.sid);18}1920fetchMessage();
1{2"sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",6"channel_sid": "ChannelSid",7"date_created": "2016-03-24T20:37:57Z",8"date_updated": "2016-03-24T20:37:57Z",9"last_updated_by": null,10"was_edited": false,11"from": "system",12"attributes": "{}",13"body": "Hello",14"index": 0,15"type": "text",16"media": null,17"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"18}
GET https://chat.twilio.com/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages
The {ChannelSid}
value can be the Channel resource's sid
or unique_name
.
The SID of the Service to read the Message resources from.
^IS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The sort order of the returned messages. Can be: asc
(ascending) or desc
(descending) with asc
as the default.
asc
desc
How many resources to return in each list page. The default is 50, and the maximum is 1000.
1
Maximum: 1000
The page token. This is provided by the API.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function listMessage() {11const messages = await client.chat.v212.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.channels("ChannelSid")14.messages.list({ limit: 20 });1516messages.forEach((m) => console.log(m.sid));17}1819listMessage();
1{2"meta": {3"page": 0,4"page_size": 50,5"first_page_url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages?PageSize=50&Page=0",6"previous_page_url": null,7"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages?PageSize=50&Page=0",8"next_page_url": null,9"key": "messages"10},11"messages": [12{13"sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",14"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",15"service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",16"to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",17"channel_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",18"date_created": "2016-03-24T20:37:57Z",19"date_updated": "2016-03-24T20:37:57Z",20"last_updated_by": null,21"was_edited": false,22"from": "system",23"attributes": "{}",24"body": "Hello",25"index": 0,26"type": "text",27"media": null,28"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"29},30{31"sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",32"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",33"service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",34"to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",35"channel_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",36"date_created": "2016-03-24T20:37:57Z",37"date_updated": "2016-03-24T20:37:57Z",38"last_updated_by": null,39"was_edited": false,40"from": "system",41"attributes": "{}",42"body": "Hello",43"index": 0,44"type": "media",45"media": {46"sid": "MEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",47"size": 99999999999999,48"content_type": "application/pdf",49"filename": "hello.pdf"50},51"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"52}53]54}
POST https://chat.twilio.com/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}
The {ChannelSid}
value can be the Channel resource's sid
or unique_name
.
The X-Twilio-Webhook-Enabled HTTP request header
true
false
The SID of the Service to update the Message resource in.
^IS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Channel the Message resource to update belongs to. This value can be the Channel resource's sid
or unique_name
.
The SID of the Message resource to update.
^IM[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
application/x-www-form-urlencoded
The message to send to the channel. Can be an empty string or null
, which sets the value as an empty string. You can send structured data in the body by serializing it as a string.
A valid JSON string that contains application-specific data.
The date, specified in ISO 8601 format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. This parameter should only be used when a Chat's history is being recreated from a backup/separate source.
The date, specified in ISO 8601 format, to assign to the resource as the date it was last updated.
The Identity of the User who last updated the Message, if applicable.
The Identity of the message's author.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function updateMessage() {11const message = await client.chat.v212.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.channels("ChannelSid")14.messages("IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")15.update({ body: "This will be the body of the new message!" });1617console.log(message.sid);18}1920updateMessage();
1{2"sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",6"channel_sid": "ChannelSid",7"attributes": "{ \"foo\": \"bar\" }",8"date_created": "2015-12-16T22:18:37Z",9"date_updated": "2015-12-16T22:18:38Z",10"last_updated_by": "username",11"was_edited": true,12"from": "fromUser",13"body": "This will be the body of the new message!",14"index": 0,15"type": "text",16"media": null,17"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"18}
DELETE https://chat.twilio.com/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}
The {ChannelSid}
value can be the Channel resource's sid
or unique_name
.
The X-Twilio-Webhook-Enabled HTTP request header
true
false
The SID of the Service to delete the Message resource from.
^IS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Channel the Message resource to delete belongs to. This value can be the Channel resource's sid
or unique_name
.
The SID of the Message resource to delete.
^IM[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function deleteMessage() {11await client.chat.v212.services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.channels("ChannelSid")14.messages("IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")15.remove();16}1718deleteMessage();