Menu

Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Messages Resource

The Message resource of Programmable Chat represents a single message within a Channel in a Service instance. POSTing to the Messages resource of a Channel allows you to send messages to the Channel via the REST API.

Properties

Each message has these properties:

Names in Java format
sid
sid<IM> Not PII

A 34 character string that uniquely identifies this resource.

accountSid
sid<AC> Not PII

The unique id of the Account responsible for this message.

attributes

A string metadata field you can use to store any data you wish. The string value must contain structurally valid JSON if specified.

serviceSid
sid<IS> Not PII

The unique id of the Service this message belongs to.

to
sid<CH> Not PII

The unique id of the Channel this message was sent to.

channelSid
sid<CH> Not PII

dateCreated
date_time<iso8601> Not PII

The date that this resource was created.

dateUpdated
date_time<iso8601> Not PII

The date that this resource was last updated. null if the message has not been edited.

lastUpdatedBy

Field to specify the Identity of the User that last updated the Message (if relevant)

wasEdited
boolean Not PII

true if the message has been updated since it was created. false if it has not changed.

from

The identity of the message's author. Defaults to system.

body

The contents of the message.

index
integer Not PII

The index of the message within the Channel

type
string Not PII

Message type. Can be text or media currently, representing if it's text message or media message accordingly.

media
object Not PII

If a Media resource instance (file) is attached to the Message, this will contain the Media object for the attached Media. null if no Media is attached to the Message. See the table below for the details.

url
url Not PII

An absolute URL for this message.

Media resource object properties:

name description
sid A 34 character string that uniquely identifies this resource.
content_type MIME content type which reflects uploaded file type. For example: video/mp4, image/jpeg, etc.
filename Optional — provided filename for the file uploaded. May be null.
size Uploaded file size in bytes

List All Messages in a Channel

GET /Services/{Service SID}/Channels/{Channel SID}/Messages

Parameters

Names in Java format
pathServiceSid
Required
get sid<IS> Not PII

Sid of the Service this message belongs to.

pathChannelSid
Required
get sid_like<CH> Not PII

Key of the Channel this message belongs to. Could be Sid or UniqueName

order
Optional
get enum:order_type Not PII

Specifies sorting order for messages list, possible values are: asc or desc. If no value is specified, then asc is used as the default.

        
        
        
        

        Send a Message to a Channel

        POST /Services/{Service SID}/Channels/{Channel SID}/Messages
        

        Parameters

        Names in Java format
        pathServiceSid
        Required
        post sid<IS> Not PII

        Sid of the Service this message belongs to.

        pathChannelSid
        Required
        post sid_like<CH> Not PII

        Key of the Channel this message belongs to. Could be Sid or UniqueName

        from
        Optional
        post string PII MTL: 120 DAYS

        The identity of the message's author. Defaults to system.

        attributes
        Optional
        post string PII MTL: 120 DAYS

        An string metadata field you can use to store any data you wish. The string value must contain structurally valid JSON if specified. Note that this will always be null for resources returned via LIST GET operations, but will be present for single GET operations.

        dateCreated
        Optional
        post date_time<iso8601> Not PII

        The ISO8601 time specifying the datetime the Message should be set as being created. Will be set to the current time by the Chat service if not specified. Note that this should only be used in cases where a Chat's history is being recreated from a backup/separate source.

        dateUpdated
        Optional
        post date_time<iso8601> Not PII

        The ISO8601 time specifying the datetime the Message should be set as having been last updated. Will be set to the null by the Chat service if not specified. Note that this should only be used in cases where a Chat's history is being recreated from a backup/separate source and where a Message was previously updated.

        lastUpdatedBy
        Optional
        post string PII MTL: 120 DAYS

        Specify the Identity of the User that last updated the Message (if relevant)

        body
        Optional
        post string PII MTL: 120 DAYS

        A string message to send to this channel. You can also send structured data by serializing it into a string. May be empty string or null, will be set as empty string as a result in this cases.

        mediaSid
        Optional
        post sid<ME> Not PII

        The Media Sid to be attached to this Message.

              
              
              
              

              Retrieve a Message from a Channel

              GET /Services/{Service SID}/Channels/{Channel SID}/Messages/{Message SID}
              
                    
                    
                    
                    

                    Update an existing Message

                    POST /Services/{Service SID}/Channels/{Channel SID}/Messages/{Message SID}
                    

                    Parameters

                    Names in Java format
                    pathServiceSid
                    Required
                    post sid<IS> Not PII

                    Sid of the Service this message belongs to.

                    pathChannelSid
                    Required
                    post sid_like<CH> Not PII

                    Key of the Channel this message belongs to. Could be Sid or UniqueName

                    pathSid
                    Required
                    post sid<IM> Not PII

                    Key that uniquely defines the message to update.

                    body
                    Optional
                    post string PII MTL: 120 DAYS

                    The message body string. You can also send structured data by serializing it into a string. May be updated to empty string or null, will be set as empty string as a result in this cases.

                    attributes
                    Optional
                    post string PII MTL: 120 DAYS

                    A string metadata field you can use to store any data you wish. The string value must contain structurally valid JSON if specified. Note that this will always be null for resources returned via LIST GET operations, but will be present for single GET operations.

                    dateCreated
                    Optional
                    post date_time<iso8601> Not PII

                    The ISO8601 time specifying the datetime the Message should be set as being created.

                    dateUpdated
                    Optional
                    post date_time<iso8601> Not PII

                    The ISO8601 time specifying the datetime the Message should be set as having been last updated.

                    lastUpdatedBy
                    Optional
                    post string PII MTL: 120 DAYS

                    Specify the Identity of the User that last updated the Message (if relevant)

                    from
                    Optional
                    post string PII MTL: 120 DAYS

                    The identity of the message's author.

                          
                          
                          
                          

                          Delete a Message from a Channel

                          DELETE /Services/{Service SID}/Channels/{Channel SID}/Messages/{Message SID}
                          
                                
                                
                                
                                

                                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 browsing the Twilio tag on Stack Overflow.