Posting a file to a chat

Last updated: 2024-01-31Contributors
Edit this page

An important part of communication within the context of collaboration is the sharing of files and images with teammates. Sharing and displaying an image or a file is done by posting the file's contents to a designated endpoint. The code below shows how to post a file to a chat, assuming you already know the chat ID.

platform.on(platform.events.loginSuccess, () => {
    var endpoint = "/team-messaging/v1/files"
    bindata = fs.readFileSync('./cats.png');
    platform.post( endpoint, bindata, {
        name: "cats.png", groupId: '367050754'
    })
        .then( function(resp) {
            var json = resp.json()
            file_id = json[0]['id']
            console.log( "Uploaded file. File ID: " + file_id )
        })
})

This simple script will result in a file being uploaded, and a message being posted to the associated team. It will appear as follows:

Uploading a File

To upload a file, one conducts an HTTP POST to the following URI, using the file's contents as the post body. Developers must be sure to set the content-type properly. They should also post the following parameters in the query string:

Parameter Description
name The name of the file.
groupId The RingCentral chat in which to post this file.

Sample Request

POST /team-messaging/v1/files?name="My file"&groupId=101500
Content-Type: audio/wav
Accept: application/json
Authorization: Bearer {access_token}

/// Binary content

The response will include the file's ID and the URL at which the file can be accessed.

Sample Response

[
    {
        "id": "100500",
        "contentUri": "http://somestorage.com/somefile.wav",
        "name": "My_music"
    }
]

See Also

Rate this page: