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
  • Send group messages

Send group messages

Last updated:2022-04-02 17:12

Description

Send group messages and push to all online users in the group.

Request limit: 10 requests/second.

The client will receive notifications of group messages through the event callback of the ZIM SDK.

Platform Callback
iOS/macOS
zim:receiveGroupMessage:fromUserID:
Android
onReceiveGroupMessage
Windows
onReceiveGroupMessage

Request method and endpoint

Request parameters

Listed below are the parameters specific to this request and part of the public request parameters. For the complete list of public request parameters, see Accessing Server APIs - Public parameters.

Parameter Type Required Description
FromUserId
String
Yes
The ID of the user who send the message.
GroupId
String
Yes
Group ID.
MessageType
Number
Yes
Message type, the values are as follows:

  • 1: Text message.
  • 2: Command message (signaling message). It's deliverability can't be guranteed because this is not stored in the cloud.
Priority
Number
Yes
Message priority, the values are as follows:

  • 1: Low.
  • 2: Medium.
  • 3: High.
MessageBody
Object
Yes
Message content.

The FromUserId and GroupId can only contain numbers, letters, and the following special characters: !#$%&()+-:;<=.>?@[]^_{}|~.

The format of MessageBody varies according to the value of MessageType. The following table shows the details:

MessageType MessageBody format Type Required Description
1 (Text message)
Message
String
Yes
Text message content, it is 2 KB by default. Size limit: 32 KB. For a larger configuration, contact ZEGOCLOUD Technical Support.
ExtendedData
String
No
Extension field.
OfflinePush
Object
No
Offline notification.
└ Enable
String
No
Enable or disable the offline notifications:

  • 0: Enable (by default).
  • 1: Disable
└ Title
String
Yes (required only when the OfflinePush is filled)
The title of the offline notification. Maximum number of characters: 20
└ Content
String
Yes (required only when the OfflinePush is filled)
The offline notification content. Maximum number of characters: 50
└ Payload
String
No
The action after receiving the offline notification.
2 (Command/Signaling message)
Message
String
Yes
Message content, it is 2 KB by default. Size limit: 32 KB. For a larger configuration, contact ZEGOCLOUD Technical Support.
ExtendedData
String
No
Extension field.

The ZIM Server only supports the Command message type (the MessageType is 2) if the version of the SDK you are using is earlier than 2.0.0.

For a better development experience, we recommend you use the latest version of SDK.

Sample request

  • A sample URL request:

    https://zim-api.zego.im/?Action=SendGroupMessage
    &<Public parameters>
  • Request message body:

    {
        "FromUserId": "u1",
        "GroupId": "r1",
        "MessageType": 1,
        "Priority": 1,
        "MessageBody": {
            "Message":"hello world",
            "ExtendedData":"d",
            "OfflinePush" :{
                "Enable":0,
                "Title":"Title",
                "Content":"Content",
                "Payload":"data"
            }
        }
    }

Response parameters

Parameter Type Description
Code
Number
Return code.
Message
String
Description of the request execution result.
RequestId
String
Request ID.

Sample response

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

Return codes

Listed below are the return codes related to this API. For the complete list of return codes, see Return codes.

Return code Possible cause and solutions
660600001
The group does not exist. Please check the group ID.
660400001
The size of message has exceeded the limit. Please check the message size.
660500002
The message sender has not logged in. Please log in first before sending messages.
Page Directory