Programmable Chat Message Resource
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.
Property name Type PII Description
The unique string that we created to identify the Message resource.
Pattern: ^IM[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Account that created the Message resource.
Pattern: ^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.
Pattern: ^IS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Channel that the message was sent to.
Pattern: ^CH[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Channel the Message resource belongs to.
Pattern: ^CH[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
date_created string<date-time> date_updated string<date-time> The Identity of the User who last updated the Message, if applicable.
Whether the message has been edited since it was created.
The Identity of the message's author. The default value is system
.
The content of the message.
The index of the message within the Channel . Indices may skip numbers, but will always be in order of when the message was received.
The Message type. Can be: text
or media
.
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.
Property name Type Required PII Description
ServiceSid SID<IS> required The SID of the Service to create the Message resource under.
Pattern: ^IS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Channel the new Message resource belongs to. This value can be the Channel resource's sid
or unique_name
.
Property name Type Required PII Description
The Identity of the new message's author. The default value is system
.
A valid JSON string that contains application-specific data.
DateCreated string<date-time> Optional The date, specified in ISO 8601(link takes you to an external page) 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.
DateUpdated string<date-time> Optional LastUpdatedBy string Optional 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.
The SID of the Media to attach to the new Message.
Pattern: ^ME[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
_19 // Download the helper library from https://www.twilio.com/docs/node/install
_19 const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19 // Find your Account SID and Auth Token at twilio.com/console
_19 // and set the environment variables. See http://twil.io/secure
_19 const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19 const authToken = process.env.TWILIO_AUTH_TOKEN;
_19 const client = twilio(accountSid, authToken);
_19 async function createMessage() {
_19 const message = await client.chat.v2
_19 .services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19 .channels("ChannelSid")
_19 .messages.create({ body: "Hello, world!" });
_19 console.log(message.sid);
_18 "sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18 "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18 "service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18 "to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18 "channel_sid": "ChannelSid",
_18 "date_created": "2016-03-24T20:37:57Z",
_18 "date_updated": "2016-03-24T20:37:57Z",
_18 "last_updated_by": "system",
_18 "body": "Hello, world!",
_18 "url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
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
.
Property name Type Required PII Description
ServiceSid SID<IS> required The SID of the Service to fetch the Message resource from.
Pattern: ^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.
Pattern: ^IM[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
_20 // Download the helper library from https://www.twilio.com/docs/node/install
_20 const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20 // Find your Account SID and Auth Token at twilio.com/console
_20 // and set the environment variables. See http://twil.io/secure
_20 const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20 const authToken = process.env.TWILIO_AUTH_TOKEN;
_20 const client = twilio(accountSid, authToken);
_20 async function fetchMessage() {
_20 const message = await client.chat.v2
_20 .services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20 .channels("ChannelSid")
_20 .messages("IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20 console.log(message.sid);
_18 "sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18 "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18 "service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18 "to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18 "channel_sid": "ChannelSid",
_18 "date_created": "2016-03-24T20:37:57Z",
_18 "date_updated": "2016-03-24T20:37:57Z",
_18 "last_updated_by": null,
_18 "url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
GET https://chat.twilio.com/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages
The {ChannelSid}
value can be the Channel resource's sid
or unique_name
.
Property name Type Required PII Description
ServiceSid SID<IS> required The SID of the Service to read the Message resources from.
Pattern: ^IS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Channel the Message resource to read belongs to. This value can be the Channel resource's sid
or unique_name
.
Property name Type Required PII Description
Order enum<string> Optional The sort order of the returned messages. Can be: asc
(ascending) or desc
(descending) with asc
as the default.
How many resources to return in each list page. The default is 50, and the maximum is 1000.
Minimum: 1
Maximum: 1000
The page index. This value is simply for client state.
Minimum: 0
The page token. This is provided by the API.
_19 // Download the helper library from https://www.twilio.com/docs/node/install
_19 const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19 // Find your Account SID and Auth Token at twilio.com/console
_19 // and set the environment variables. See http://twil.io/secure
_19 const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19 const authToken = process.env.TWILIO_AUTH_TOKEN;
_19 const client = twilio(accountSid, authToken);
_19 async function listMessage() {
_19 const messages = await client.chat.v2
_19 .services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19 .channels("ChannelSid")
_19 .messages.list({ limit: 20 });
_19 messages.forEach((m) => console.log(m.sid));
_54 "first_page_url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages?PageSize=50&Page=0",
_54 "previous_page_url": null,
_54 "url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages?PageSize=50&Page=0",
_54 "next_page_url": null,
_54 "sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_54 "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_54 "service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_54 "to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_54 "channel_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_54 "date_created": "2016-03-24T20:37:57Z",
_54 "date_updated": "2016-03-24T20:37:57Z",
_54 "last_updated_by": null,
_54 "url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_54 "sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_54 "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_54 "service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_54 "to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_54 "channel_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_54 "date_created": "2016-03-24T20:37:57Z",
_54 "date_updated": "2016-03-24T20:37:57Z",
_54 "last_updated_by": null,
_54 "sid": "MEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_54 "size": 99999999999999,
_54 "content_type": "application/pdf",
_54 "filename": "hello.pdf"
_54 "url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
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
.
Property name Type Required PII Description
ServiceSid SID<IS> required The SID of the Service to update the Message resource in.
Pattern: ^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.
Pattern: ^IM[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
Property name Type Required PII Description
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.
DateCreated string<date-time> Optional The date, specified in ISO 8601(link takes you to an external page) 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.
DateUpdated string<date-time> Optional LastUpdatedBy string Optional The Identity of the User who last updated the Message, if applicable.
_20 // Download the helper library from https://www.twilio.com/docs/node/install
_20 const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20 // Find your Account SID and Auth Token at twilio.com/console
_20 // and set the environment variables. See http://twil.io/secure
_20 const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20 const authToken = process.env.TWILIO_AUTH_TOKEN;
_20 const client = twilio(accountSid, authToken);
_20 async function updateMessage() {
_20 const message = await client.chat.v2
_20 .services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20 .channels("ChannelSid")
_20 .messages("IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20 .update({ body: "This will be the body of the new message!" });
_20 console.log(message.sid);
_18 "sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18 "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18 "service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18 "to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_18 "channel_sid": "ChannelSid",
_18 "attributes": "{ \"foo\": \"bar\" }",
_18 "date_created": "2015-12-16T22:18:37Z",
_18 "date_updated": "2015-12-16T22:18:38Z",
_18 "last_updated_by": "username",
_18 "body": "This will be the body of the new message!",
_18 "url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
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
.
Property name Type Required PII Description
ServiceSid SID<IS> required The SID of the Service to delete the Message resource from.
Pattern: ^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.
Pattern: ^IM[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
_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 // 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 async function deleteMessage() {
_18 .services("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_18 .channels("ChannelSid")
_18 .messages("IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")