Fuselage
Send Message
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.

IMPORTANT

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.
URL
Requires Auth
HTTP Method
/api/v1/chat.sendMessage
yes
POST

Payload

Argument
Example
Required
Description
message._id
ByehQjC44FwMeiLbX
Optional
The _id of message.
message.rid
ByehQjC44FwMeiLbX
Required
The room id of where the message is to be sent.
message.tmid
ByehQCh2435MeiLbX
Optional
The message's id to create a thread.
message.msg
Sample message
Optional
The text of the message to send, is optional because of attachments.
message.alias
Some Name
Optional
This will cause the message's name to appear as the given alias, but your username will still display.
message.emoji
:smirk:
Optional
If provided, this will make the avatar on this message be an emoji. Emoji Cheetsheet
message.avatar
http://site.com/logo.png
Optional
If provided, this will make the avatar use the provided image url.
message.attachments
[{}]
Optional
See the below section, Attachments Detail, for details.

Attachments Detail

The attachments 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
Property
Example
Section
Description
color
#ff0000
General
The color you want the order on the left side to be, any value background-css supports.
text
Sample attachment text
General
The text to display for this attachment, it is different than the message's text.
ts
2016-12-09T16:53:06.761Z
General
Displays the time next to the text portion.
thumb_url
https://site.com/img.png
General
An image that displays to the left of the text, looks better when this is relatively small.
message_link
https://rocket.chat
General
Only applicable if the ts is provided, as it makes the time clickable to this link.
collapsed
false
General
Causes the image, audio, and video sections to be hiding when collapsed is true.
author_name
Bradley Hilton
Author
Name of the author.
author_link
https://bit.ly/
Author
Providing this makes the author name clickable and points to this link.
author_icon
https://site.com/img.png
Author
Displays a tiny icon to the left of the Author's name.
title
Attachment Title
Title
Title to display for this attachment, displays under the author.
title_link
https://youtube.com
Title
Providing this makes the title clickable, pointing to this link.
title_link_download
true
Title
When this is true, a download icon appears and clicking this saves the link to file.
image_url
https://site.com/img.png
Image
The image to display, will be "big" and easy to see.
audio_url
https://site.com/aud.mp3
Audio
Audio file to play, only supports what html audio does.
video_url
https://site.com/vid.mp4
Video
Video file to play, only supports what html video does.
fields
[{}]
Fields

Attachment Field Objects

The field property of the attachments allows for "tables" or "columns" to be displayed on messages.
Property
Example
Required
Description
short
true
Optional Default: false
Whether this field should be a short field.
title
Status
Required
The title of this field.
value
online
Required
The value of this field, displayed underneath the title value.

Message Object Example

1
{
2
"message": {
3
"rid": "Xnb2kLD2Pnhdwe3RH",
4
"msg": "Sample message",
5
"alias": "Gruggy",
6
"emoji": ":smirk:",
7
"avatar": "http://res.guggy.com/logo_128.png",
8
"attachments": [{
9
"color": "#ff0000",
10
"text": "Yay for gruggy!",
11
"ts": "2016-12-09T16:53:06.761Z",
12
"thumb_url": "http://res.guggy.com/logo_128.png",
13
"message_link": "https://google.com",
14
"collapsed": false,
15
"author_name": "Bradley Hilton",
16
"author_link": "https://rocket.chat/",
17
"author_icon": "https://avatars.githubusercontent.com/u/850391?v=3",
18
"title": "Attachment Example",
19
"title_link": "https://youtube.com",
20
"title_link_download": true,
21
"image_url": "http://res.guggy.com/logo_128.png",
22
"audio_url": "http://www.w3schools.com/tags/horse.mp3",
23
"video_url": "http://www.w3schools.com/tags/movie.mp4",
24
"fields": [{
25
"short": true,
26
"title": "Test",
27
"value": "Testing out something or other"
28
},{
29
"short": true,
30
"title": "Another Test",
31
"value": "[Link](https://google.com/) something and this and that."
32
}]
33
}]
34
}
35
}
Copied!

Example Call

1
curl -H "X-Auth-Token: 9HqLlyZOugoStsXCUfD_0YdwnNnunAJF8V47U3QHXSq" \
2
-H "X-User-Id: aobEdbYhXfu5hkeqG" \
3
-H "Content-type:application/json" \
4
http://localhost:3000/api/v1/chat.sendMessage \
5
-d '{"message": { "rid": "Xnb2kLD2Pnhdwe3RH", "msg": "This is a test!" }}'
Copied!

Example Result

1
{
2
"message": {
3
"rid": "GENERAL",
4
"msg": "123456789",
5
"ts": "2018-03-01T18:02:26.825Z",
6
"u": {
7
"_id": "i5FdM4ssFgAcQP62k",
8
"username": "rocket.cat",
9
"name": "test"
10
},
11
"unread": true,
12
"mentions": [],
13
"channels": [],
14
"_updatedAt": "2018-03-01T18:02:26.828Z",
15
"_id": "LnCSJxxNkCy6K9X8X"
16
},
17
"success": true
18
}
Copied!

Change Log

Version
Description
2.4.0
Added validation on user's identity
0.60.0
Added