Menu

Expand
Rate this page:

Programmable Chat Message Resource

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.

Message properties

Each Message resource contains these properties.

Resource Properties in REST API format
sid
sid<IM> Not PII

The unique string that we created to identify the Message resource.

account_sid
sid<AC> Not PII

The SID of the Account that created the Message resource.

attributes

The JSON string that stores application-specific data. If attributes have not been set, {} is returned.

service_sid
sid<IS> Not PII

The SID of the Service the Message resource is associated with.

to
sid<CH> Not PII

The SID of the Channel that the message was sent to.

channel_sid
sid<CH> Not PII

The SID of the Channel the Message resource belongs to.

date_created
date_time<iso8601> Not PII

The date and time in GMT when the resource was created specified in ISO 8601 format.

date_updated
date_time<iso8601> Not PII

The date and time in GMT when the resource was last updated specified in ISO 8601 format.

last_updated_by

The Identity of the User who last updated the Message, if applicable.

was_edited
boolean Not PII

Whether the message has been edited since it was created.

from

The Identity of the message's author. The default value is system.

body

The content of the message.

index
integer Not PII

The index of the message within the Channel. Indices may skip numbers, but will always be in order of when the message was received.

type
string Not PII

The Message type. Can be: text or media.

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.

url
url Not PII

The absolute URL of the Message resource.

Create a 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.

Parameters
Parameters in REST API format
service_sid
Path
post sid<IS> Not PII

The SID of the Service to create the Message resource under.

channel_sid
Path
post sid_like<CH> Not PII

The SID of the Channel the new Message resource belongs to. This value can be the Channel resource's sid or unique_name.

from
Optional
post string PII MTL: 30 DAYS

The Identity of the new message's author. The default value is system.

attributes
Optional
post string PII MTL: 30 DAYS

A valid JSON string that contains application-specific data.

date_created
Optional
post date_time<iso8601> Not PII

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.

date_updated
Optional
post date_time<iso8601> Not PII

The date, specified in ISO 8601 format, to assign to the resource as the date it was last updated.

last_updated_by
Optional
post string PII MTL: 30 DAYS

The Identity of the User who last updated the Message, if applicable.

body
Optional
post string PII MTL: 30 DAYS

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.

media_sid
Optional
post sid<ME> Not PII

The SID of the Media to attach to the new Message.

x_twilio_webhook_enabled
Header
post ienum:webhook_enabled_type Not PII

The X-Twilio-Webhook-Enabled HTTP request header

Example 1
Loading Code Sample...
        
        

        Create a Message resource

        Fetch a Message resource

        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.

        Parameters
        Parameters in REST API format
        service_sid
        Path
        get sid<IS> Not PII

        The SID of the Service to fetch the Message resource from.

        channel_sid
        Path
        get sid_like<CH> Not PII

        The SID of the Channel the Message resource to fetch belongs to. This value can be the Channel resource's sid or unique_name.

        sid
        Path
        get sid<IM> Not PII

        The SID of the Message resource to fetch.

        Example 1
        Loading Code Sample...
              
              

              Fetch a Message resource

              Read multiple Message resources

              get
              https://chat.twilio.com/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages

              The {ChannelSid} value can be the Channel resource's sid or unique_name.

              Parameters
              Parameters in REST API format
              service_sid
              Path
              get sid<IS> Not PII

              The SID of the Service to read the Message resources from.

              channel_sid
              Path
              get sid_like<CH> Not PII

              The SID of the Channel the Message resource to read belongs to. This value can be the Channel resource's sid or unique_name.

              order
              Optional
              get enum:order_type Not PII

              The sort order of the returned messages. Can be: asc (ascending) or desc (descending) with asc as the default.

              Example 1
              Loading Code Sample...
                    
                    

                    Read multiple Message resources

                    Update a Message resource

                    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.

                    Parameters
                    Parameters in REST API format
                    service_sid
                    Path
                    post sid<IS> Not PII

                    The SID of the Service to update the Message resource in.

                    channel_sid
                    Path
                    post sid_like<CH> Not PII

                    The SID of the Channel the Message resource to update belongs to. This value can be the Channel resource's sid or unique_name.

                    sid
                    Path
                    post sid<IM> Not PII

                    The SID of the Message resource to update.

                    body
                    Optional
                    post string PII MTL: 30 DAYS

                    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.

                    attributes
                    Optional
                    post string PII MTL: 30 DAYS

                    A valid JSON string that contains application-specific data.

                    date_created
                    Optional
                    post date_time<iso8601> Not PII

                    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.

                    date_updated
                    Optional
                    post date_time<iso8601> Not PII

                    The date, specified in ISO 8601 format, to assign to the resource as the date it was last updated.

                    last_updated_by
                    Optional
                    post string PII MTL: 30 DAYS

                    The Identity of the User who last updated the Message, if applicable.

                    from
                    Optional
                    post string PII MTL: 30 DAYS

                    The Identity of the message's author.

                    x_twilio_webhook_enabled
                    Header
                    post ienum:webhook_enabled_type Not PII

                    The X-Twilio-Webhook-Enabled HTTP request header

                    Example 1
                    Loading Code Sample...
                          
                          

                          Update a Message resource

                          Delete a Message resource

                          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.

                          Parameters
                          Parameters in REST API format
                          service_sid
                          Path
                          delete sid<IS> Not PII

                          The SID of the Service to delete the Message resource from.

                          channel_sid
                          Path
                          delete sid_like<CH> Not PII

                          The SID of the Channel the Message resource to delete belongs to. This value can be the Channel resource's sid or unique_name.

                          sid
                          Path
                          delete sid<IM> Not PII

                          The SID of the Message resource to delete.

                          x_twilio_webhook_enabled
                          Header
                          delete ienum:webhook_enabled_type Not PII

                          The X-Twilio-Webhook-Enabled HTTP request header

                          Example 1
                          Loading Code Sample...
                                
                                

                                Delete a Message resource

                                Rate this page:

                                Need some help?

                                We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

                                Loading Code Sample...
                                      
                                      
                                      

                                      Thank you for your feedback!

                                      Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

                                      Sending your feedback...
                                      🎉 Thank you for your feedback!
                                      Something went wrong. Please try again.

                                      Thanks for your feedback!

                                      thanks-feedback-gif