In-app Chat
  • iOS : Objective-C
  • Android
  • Web
  • Flutter
  • React Native
  • Unity3D
  • Windows
  • macOS
  • Introduction
    • Overview
    • Basic concepts
  • Sample app
  • Getting started
  • Client SDKs
    • SDK downloads
    • Release notes
    • Upgrade guide
  • Guides
    • Authentication
    • Manage users
    • Room
    • Group
    • Messaging
    • Call invitation (signaling)
    • Manage sessions
  • Offline push notifications
  • Error codes
  • Client APIs
  • Server APIs
  • Documentation
  • In-app Chat
  • Server APIs
  • Message related
  • Send room messages

Send room messages

Last updated:2024-03-22 10:54

Overview

You can call this operation to send messages to all online users in a room.

The QPS limit is 10 calls per second. If you need a higher limit, contact ZEGOCLOUD business staff for billing.

The client receives the message notification in the following ZIM SDK callbacks.

Operation prototype

  • Request method: POST
  • Request URL: https://zim-api.zego.im/?Action=SendRoomMessage
  • Protocol: HTTPS

Request parameters

The following table describes only the operation-specific request parameters and some common request parameters. For the complete list of common request parameters, see the Public request parameters section of the Accessing Server APIs topic.

Parameter Type Required Description
FromUserId
String
Yes
The ID of the message sender.
RoomId
String
Yes
The room ID.
MessageType
Number
Yes
The message type. For more information about room message types, see MessageBody Introduction.
Priority
Number
Yes
The message priority. Valid values:

  • 1: low;
  • 2: medium;
  • 3: high.
MessageBody
Object
Yes
The message content. For more information, see MessageBody Introduction.
SubMsgType
Number
No (Yes if MessageType is 200)
The custom message type. Value range: [0,200].
SearchedContent
String
No
The search field for a custom message. This field is valid only if MessageType is 200, cannot exceed 64 bytes in length, and must be specified to search for custom messages in the client.
  • The `FromUserId` and `RoomId` parameters can contain only digits, letters, and the following characters: '!', '#', '$', '%', '&', '(', ')', '+', '-', ':', ';', '<', '=', '.', '>', '?', '@', '[', ']', '^', '_', ' ', '{', '}', '|', '~'.
  • To send and receive custom messages whose `MessageType` is `200`, the version of the ZIM SDK needs to be 2.8.0 or later.
  • If the version of the receiving ZIM SDK is 2.0.0 or later but earlier than 2.8.0, the ZIM SDK can receive custom messages but will identify the message type as unknown. In addition, it cannot obtain the message content. To obtain the message content, upgrade the ZIM SDK to 2.8.0 or later.
  • If the version of the receiving ZIM SDK is 1.x.x, the ZIM SDK cannot receive custom messages and identify the message type as unknown.

Sample request

  • Request URL:

    https://zim-api.zego.im/?Action=SendRoomMessage
    &<Common request parameters>
  • Request body:

    {
        "FromUserId": "u1",
        "RoomId": "r1",
        "MessageType": 1,
        "Priority": 1,
        "MessageBody": {
            "Message":"hello world",
            "ExtendedData":"d"
        }
    }

Response parameters

Parameter Type Description
Code
Number
The return code.
Message
String
The description of the request result.
RequestId
String
The request ID.

Sample response

{
    "Code":0,
    "Message":"success",
    "RequestId":"343649807833778782"
}

Return codes

The following table describes only the return codes related to the business logic of the operation. For the complete list of return codes, see Return codes.

Return Code Description Solution
660000025
Failed to send the Base64-encoded signaling message when IsBase64 is set to 1 in MessageBody.
Check the following items: - Check whether IsBase64 needs to be set to 1, that is, whether a binary signaling message needs to be sent. - Check whether the message is Base64-encoded.
660300001
The room does not exist.
Check whether the value of the RoomId parameter is valid.
660300013
The receipt is unavailable for room messages.
Delete the HasReceipt field in the request.
660400001
The message size exceeds the limit.
Check the message size.
660500002
The message sender has not logged in to the ZIM SDK.
Log in to the ZIM SDK before sending the message.
Page Directory