Send an open channel message
Send a message from a user to one or more open channels.
- By default, the message is not synced to the sender's client. To enable sync, see the
isEchoToSenderparameter. - You can send to multiple open channels in a single request (recommended max: 10).
tip
- Users do not need to join an open channel to send messages through this API.
- To broadcast a message to all open channels in your app, use the Broadcast to all open channels API.
Request
POST: https://[Base URL](/platform-chat-api/base-url)/v4/open-channel/message/send
Rate limit: 100 messages per second. Sending to 10 open channels counts as 10 messages.
Authentication: All server API requests require signature verification. See API request signing.
Request body
Content type: application/json
| Parameter | Type | Required | Description |
|---|---|---|---|
fromUserId | String | Yes | Sender's user ID. |
toChannelIds | String[] | Yes | Target open channel IDs. You can specify multiple IDs (recommended max: 10). |
messageType | String | Yes | Message type. Accepts a built-in message type or a custom message type value. Custom types must not start with RC: and must not exceed 32 characters. The custom type must be registered in the client SDK. |
content | String | Yes | Message content, max 128 KB.
|
shouldPersist | Number | No | Whether to store this message in the cloud message history. 0: do not store. 1 (default): store (requires the Open Channel Cloud Message Storage service). In most cases, client-side storage does not depend on this parameter:
|
isEchoToSender | Number | No | Whether to sync the sent message to the sender's client. 1: sync. 0 (default): do not sync. See How to sync sent messages to the sender's client. |
priority | Number | No | Message priority level. Default: 0 (standard priority).
|
Request example
HTTP
POST /v4/open-channel/message/send HTTP/1.1
Host: api.sg-light-api.com
App-Key: uwd1c0sxdlx2
Timestamp: 1585127132438
Nonce: 14314
Signature: 45beb7cc7307889a8e711219a47b7cf6a5b000e8
Content-Type: application/json
{
"fromUserId": "2191",
"toChannelIds": ["2192", "2193"],
"messageType": "RC:TxtMsg",
"content": "{\"content\":\"hello\"}"
}
Response
The response body contains a JSON object with the following properties:
| Property | Type | Description |
|---|---|---|
code | Number | Status code. 0 indicates success. See Server API status codes. |
result | Object | Response data object. |
result.messageUIDs | Array | List of message UIDs. |
result.messageUIDs[i].channelId | String | Open channel ID, corresponding to toChannelIds in the request. |
result.messageUIDs[i].messageUID | String | Unique ID of the message sent to the corresponding open channel. |
Response example
HTTP
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"code": 0,
"result": {
"messageUIDs": [
{
"channelId": "2192",
"messageUID": "XXXX-JJJJ-KKK-LLLL"
},
{
"channelId": "2193",
"messageUID": "XXXX-JJJJ-KKK-LLKL"
}
]
}
}