val message = Message(
text = "Check this bear out https://imgur.com/r/bears/4zmGbMN"
)
channelClient.sendMessage(message).enqueue { /* ... */ }
Message Format
When you post a message on a Channel, there are a few things that happen on the server:
- The text markdown format is parsed.
- The first URL found in message.text is enriched, and additional information is added automatically. This gives you a preview of the images, videos, etc. from the open-graph data on the associated page.
Any slash commands such as /giphy
, /ban
, /flag
, etc. are handled.### Attachment Format
Messages containing URLs will have a generated attachment with the following structure:
name | type | description | default | optional |
---|---|---|---|---|
type | string | The attachment type based on the URL resource. This can be: audio, image or video | ✓ | |
author_name | string | The name of the author. | ✓ | |
title | string | The attachment title. | ✓ | |
title_link | string | The link to which the attachment message points to. | ✓ | |
text | string | The attachment text. It will be displayed in the channel next to the original message. | ✓ | |
image_url | string | The URL to the attached image. This is present for URL pointing to an image article (eg. Unsplash) | ✓ | |
thumb_url | string | The URL to the attached file thumbnail. You can use this to represent the attached link. | ✓ | |
asset_url | string | The URL to the audio, video or image related to the URL. | ✓ | |
og_scrape_url | string | The original URL that was used to scrape this attachment. | ✓ |
Open Graph Scraper
Our scraper uses the following user agent, as well as the latest desktop and mobile user agents: getstream.io/opengraph-bot facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)
If you plan to scrape any links to websites you can control, please ensure that this user agent isn’t blocked and returns valid opengraph data, for the best results.
Below is an example of URL enrichment as well as the resulting message structure:
const response = await channel.sendMessage({
text: 'Check this bear out https://imgur.com/r/bears/4zmGbMN'
})
let channel = Client.shared.channel(type: .messaging, id: "general")
let message = Message(text: "Check this bear out https://imgur.com/r/bears/4zmGbMN")
// Send the message
channel.send(message: message) { (result) in
do {
let response = try result.get()
print(response)
} catch {
print("Error when sending message: \(error)")
}
}
$response = $channel->sendMessage(["text" => "Check this bear out https://imgur.com/r/bears/4zmGbMN"], 'jenny');
channel.sendMessage(
Message(
text: 'Check this bear out https://imgur.com/r/bears/4zmGbMN',
),
);
const FMessage Message{TEXT("Check this bear out https://imgur.com/r/bears/4zmGbMN")};
Channel->SendMessage(Message);
message = {
"text": "Check this bear out https://imgur.com/r/bears/4zmGbMN",
}
channel.send_message(message, user_id)
message = {
"text" => "Check this bear out https://imgur.com/r/bears/4zmGbMN",
}
channel.send_message(message, user_id)
message := &stream_chat.Message{
Text: "Check this bear out https://imgur.com/r/bears/4zmGbMN",
}
channel.SendMessage(message, userID)
await messageClient.SendMessageAsync(channel.Type,
channel.Id,
"jenny",
"Check this bear out https://imgur.com/r/bears/4zmGbMN");
// Android SDK
Message message = new Message();
message.setText("Check this bear out https://imgur.com/r/bears/4zmGbMN");
channelClient.sendMessage(message).enqueue(result -> { /* ... */ });
// Backend SDK
Message.send(type, id)
.message(
MessageRequestObject.builder()
.text(
"Check this bear out https://imgur.com/r/bears/4zmGbMN")
.userId(userId)
.build())
.request();
// Will be implemented soon, raise a GitHub issue if you need this feature https://github.com/GetStream/stream-chat-unity/issues/
{
"id": "thierry-5e9619ec-1a0d-443b-ab26-c597ed7af3d0",
"text": "Check this bear out https://imgur.com/r/bears/4zmGbMN",
"html": "<p>Check this bear out <a href=\"https://imgur.com/r/bears/4zmGbMN\" rel=\"nofollow\">https://imgur.com/r/bears/4zmGbMN</a></p>\n",
"type": "regular",
"user": {
"id": "thierry",
"role": "user",
"created_at": "2019-04-03T14:42:47.087869Z",
"updated_at": "2019-04-16T09:20:03.982283Z",
"last_active": "2019-04-16T11:23:51.168113408+02:00",
"online": true
},
"attachments": [
{
"type": "image",
"author_name": "Imgur",
"title": "An update: Dushi made it safe to Bear Sanctuary Müritz",
"title_link": "https://imgur.com/4zmGbMN",
"text": "1678 views on Imgur",
"image_url": "https://i.imgur.com/4zmGbMN.jpg?fb",
"thumb_url": "https://i.imgur.com/4zmGbMN.jpg?fb",
"og_scrape_url": "https://imgur.com/r/bears/4zmGbMN"
}
],
"latest_reactions": [],
"own_reactions": [],
"reaction_groups": {
"love": {
"count": 9,
"sum_scores": 9,
"first_reaction_at": "2024-09-05T13:17:05.138248Z",
"last_reaction_at": "2024-09-05T13:17:11.454912Z"
},
"clap":
"count": 9,
"sum_scores": 13,
"first_reaction_at": "2024-09-05T13:17:05.673605Z",
"last_reaction_at": "2024-09-05T13:17:13.211086Z"
},
"wow": {
"count": 9,
"sum_scores": 9,
"first_reaction_at": "2024-09-05T13:17:05.059252Z",
"last_reaction_at": "2024-09-05T13:17:13.066055Z"
},
"haha": {
"count": 9,
"sum_scores": 9,
"first_reaction_at": "2024-09-05T13:17:05.522053Z",
"last_reaction_at": "2024-09-05T13:17:10.87445Z"
},
"like": {
"count": 7,
"sum_scores": 7,
"first_reaction_at": "2024-09-05T13:17:04.977203Z",
"last_reaction_at": "2024-09-05T13:17:14.856949Z"
}
},
"reply_count": 0,
"created_at": "2019-04-16T09:40:04.665274Z",
"updated_at": "2019-04-16T09:40:04.665274Z",
"message_text_updated_at":"2024-02-26T10:26:38.26136Z"
}
Messages returned by the API follow this structure:
name | type | description | default | optional |
---|---|---|---|---|
id | string | The message ID. This is either created by Stream or set client side when the message is added. | ✓ | |
html | string | The safe HTML generated from the raw text message. This field can only be set using server-side APIs or via the import | ✓ | |
type | string | The message type. See below for more information. | ✓ | |
user | object | The author user object. Schema is as described in the Setting the user portion of the docs. | ✓ | |
attachments | array | The list of attachments, either provided by the user or generated from a command or as a result of URL scraping. A message can have at most 30 attachments. | ✓ | |
latest_reactions | array | The latest reactions to the message created by any user. (Max 10 reactions) | ✓ | |
own_reactions | array | The array of reactions added to the message by the current user. e.g. [ReactionObject1, ReactionObject2]. | ✓ | |
reaction_counts | object | The reaction count by type for this message e.g. {“haha”: 3, “angry”: 2}. Please use reaction_groups instead, this field only exists for compatibility reasons. | ✓ | |
reply_count | integer | Reserved field indicating the number of replies for this message. | ✓ | |
parent_id | string | The ID of the parent message, if the message is a reply. | ✓ | |
created_at | date | Reserved field indicating when the message was created. | ✓ | |
updated_at | date | Reserved field indicating when the message was updated last time. | ✓ | |
deleted_at | date | Reserved field indicating when the message was deleted. | ✓ | |
mentioned_users | array of users | The list of users that are mentioned in this message. | ✓ | |
message_text_updated_at | date | Field indicating when the message text was updated last time | - | ✓ |
reaction_groups | object | The reaction groups by type. For example: {clap: {count: 5, sum_scores: 13, first_reaction_at: “2024-09-05T13:17:11.454912Z”, last_reaction_at: “2024-09-10T21:23:12.675478Z”}} | - | ✓ |
Message Types
Chat supports different types of messages. The type of the message is set by the APIs or by chat bots and custom commands.
Name | Description |
---|---|
regular | A regular message created in the channel. This is the default type for messages posted on a channel. |
ephemeral | A temporary message which is only delivered to one user. It is not stored in the channel history. Ephemeral messages are normally used by commands (e.g. /giphy ) to prompt messages or request for actions. |
error | An error message generated as a result of a failed command. It is also ephemeral, as it is not stored in the channel history and is only delivered to one user. |
reply | A message in a reply thread. Messages created with parent_id are automatically of this type. |
system | A message generated by a system event, like updating the channel or muting a user. |
deleted | A soft deleted message. |