The difference between chat.postMessage
and chat.sendMessage
is that chat.sendMessage
allows for passing a value for _id
and the other one doesn't. Also, chat.sendMessage
only sends it to one channel whereas the other one allows for sending to more than one channel at a time.
Note: You can only send alias and avatar properties if your user has the message-impersonate permission
. We implemented this rule to avoid users impersonating other users. By default, only the bot role has this permission, but that can be changed in Administration -> Permissions -> message-impersonate.
Change Log
Version | Description |
---|---|
6.8.0 | Allow custom fields in messages |
6.4.0 | Add previewUrls param |
2.4.0 | Added validation on user's identity |
0.60.0 | Added |
The authToken
of the authenticated user.
The userId
of the authenticated user.
Some important things to note about the previewUrls
parameter include:
- If the
previewUrls
array is empty, no URL will be previewed. - If the
previewUrls
parameter isn't sent, all URLs (up to a maximum of five external URLs) will be previewed. - If the message contains attachments or quotes, no URL is previewed.
- Internal URLs are not considered in the
previewUrls
array. - A maximum of five external URLs is previewed per message. If there are more than 5 external URLs, no URL is previewed.
URLs that include the same text as the Site URL are referred to as Internal URLs.
{
"message": {
"rid": "Xnb2kLD2Pnhdwe3RH",
"msg": "Sample message",
"alias": "Gruggy",
"emoji": ":smirk:",
"avatar": "http://res.guggy.com/logo_128.png",
"attachments": [
{
"color": "#ff0000",
"text": "Yay for gruggy!",
"ts": "2016-12-09T16:53:06.761Z",
"thumb_url": "http://res.guggy.com/logo_128.png",
"message_link": "https://google.com",
"collapsed": false,
"author_name": "Bradley Hilton",
"author_link": "https://rocket.chat/",
"author_icon": "https://avatars.githubusercontent.com/u/850391?v=3",
"title": "Attachment Example",
"title_link": "https://youtube.com",
"title_link_download": true,
"image_url": "http://res.guggy.com/logo_128.png",
"audio_url": "http://www.w3schools.com/tags/horse.mp3",
"video_url": "http://www.w3schools.com/tags/movie.mp4",
"fields": [
{
"short": true,
"title": "Test",
"value": "Testing out something or other"
},
{
"short": true,
"title": "Another Test",
"value": "[Link](https://google.com/) something and this and that."
}
]
}
]
}
}
{
"message": {
"rid": "GENERAL",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Text example* Normal message `code` here"
}
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Field 1*"
},
{
"type": "mrkdwn",
"text": "Field 2"
}
]
}
]
}
}
{
"message": {
"rid": "64f0f82c2c26843a68c1f7ba",
"msg": "This is a list of links! https://google.com https://hola.org/ https://www.usepayday.com/ https://www.getbumpa.com/ https://www.atlassian.com/software/jira http://localhost:3000/"
},
"previewUrls": [
"https://google.com",
"http://localhost:3000/",
"https://hola.org/",
"https://www.usepayday.com/",
"https://www.getbumpa.com/",
"https://www.atlassian.com/software/jira"
]
}
The message type e.g. e2e
The room ID where the message is to be sent.
The message text to send, it is optional because of attachments.
This will cause the message's name to appear as the given alias, but your username will still be displayed. Requires the impersonate-other-user
permission
If provided, the avatar will be displayed as the emoji.
If provided, the avatar will be displayed as the provided image url. Requires the impersonate-other-user
permission.
The attachment is an array of objects with any of the following properties. One attachment can have many sections, including:
- General
- Author Information
- Title Information
- Image
- Audio
- Video
- Table/Fields
Displays a tiny icon to the left of the author's name.
Providing this makes the author name clickable and points to this link.
Name of the author.
Causes the image, audio, and video sections to be displayed as collapsed when set to true.
Whether this field should be a short field.
The title of this field.
The value of this field, displayed underneath the title value.
The image to display, will be big and easy to see.
Only applicable if the ts
parameter is provided, as it makes the time clickable to this link.
The text to display for this attachment, it is different than the message's text.
An image that displays to the left of the text, looks better when this is relatively small.
Title to display for this attachment, displays under the author.
Providing this makes the title clickable, pointing to this link.
When this is true, a download icon appears and clicking this saves the link to file.
Displays the time next to the text portion.
The message ID to create a thread.
Used when replying in a thread. Message will be sent in channel also if value is true
A message block is an array of objects with any of the following properties. Blocks can have many sections:
- type
- text
- fields
You can add custom fields for messages. For example, set priorities for messages.
You must enable this option and define the validation in the workspace settings. See the Message settings for further information.
An array to define which URL previews should be retrieved from each message.
OK
{
"message": {
"rid": "GENERAL",
"msg": "123456789",
"ts": "2018-03-01T18:02:26.825Z",
"u": {
"_id": "i5FdM4ssFgAcQP62k",
"username": "rocket.cat",
"name": "test"
},
"unread": true,
"mentions": [],
"channels": [],
"_updatedAt": "2018-03-01T18:02:26.828Z",
"_id": "LnCSJxxNkCy6K9X8X"
},
"success": true
}
Bad Request
{
"success": false,
"error": "The \"message\" parameter must be provided. [error-invalid-params]",
"errorType": "error-invalid-params"
}
{
"success": false,
"error": "The 'rid' property on the message object is missing."
}
{
"success": false,
"error": "error-invalid-room"
}
Unauthorized
{
"status": "error",
"message": "You must be logged in to do this."
}