logo
In-app Chat
Powered Byspreading
On this page

Import group messages


Description

You can call this method to import historical group messages in chronological order from another instant messaging service to ZEGOCLOUD Instant Messaging (ZIM).

Request method and endpoint

  • Request method: POST
  • Request endpoint: https://zim-api.zego.im/?Action=ImportGroupMsg
  • Transmission protocol: HTTPS
  • QPS limit: 20 calls per second

Request parameters

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

ParameterTypeRequiredDescription
FromUserIdStringYesThe ID of the message sender (registered).
GroupIdStringYesThe group ID.
MessageTypeNumberYesMessage type. For more information about message types applicable to a group chat, see MessageBody Introduction. Signaling messages are not supported.
PriorityNumberYes

Message priority. Valid values:

  • 1: low.
  • 2: medium.
  • 3: high.
MessageBodyObjectYesMessage content. For more information about the format, see MessageBody Introduction. Offline push is not supported.
SubMsgTypeNumberNo (Yes if MessageType is 200)Custom message type. Value range: [0,200].
SearchedContentStringNoThe searched content of the custom message. This field is required only if MessageType is 200 and can contain up to 64 bytes in length. This field is required to search for associated custom messages on the client.
SendMessageTimeNumberNo

The Unix timestamp when the message was sent. Unit: ms. Import messages based on their sending timestamps in chronological order.

  • If the value is set to 0 or not specified, the current time is used.
  • If a value other than 0 is specified, it cannot be earlier than "the current time - message retention days specified in the package × 86400000" or later than the current time.
Note

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

Note
  • We recommend that you use the SDK of the latest version for better experience.
  • To receive a text message whose MessageType is 1, the version of the receiving ZIM SDK needs to be 2.7.0 or later.
  • To send and receive a custom message whose MessageType is 200, the version of the sending and receiving ZIM SDKs 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 a custom message 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 a custom message and identify the message type as unknown.

Sample request

  • Request URL:

    Untitled
    https://zim-api.zego.im/?Action=ImportGroupMsg
    &<Common request parameters>
    
    1
    Copied!
  • Request body:

    Untitled
    {
        "FromUserId": "u1",
        "GroupId": "r1",
        "MessageType": 1,
        "Priority": 1,
        "MessageBody": {
            "Message": "hello world",
            "ExtendedData": "d"
        },
        "SubMsgType": 200,
        "SearchedContent": "ex",
        "SendMessageTime": 123
    }
    
    1
    Copied!

Response parameters

ParameterTypeDescription
CodeNumberThe return code.
MessageStringThe description of the request result.
RequestIdStringThe request ID.
MsgSeqNumberThe message sequence.

Sample response

Untitled
{
    "Code": 0,
    "Message": "success",
    "RequestId": "343649807833778782",
    "MsgSeq": 123
}
1
Copied!

Verify the result

After messages are imported successfully, call the ZIM server API Query the message list of group chats to check whether all group messages are imported.

Return codes

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

Return codeDescriptionSolution
660400001The message size exceeds the limit. Check the message size.
660500002The message sender has not logged in to the ZIM SDK. Log in first.
660600001The GroupId does not exist. Check whether the value of the GroupId parameter is valid.

Previous

Import one-to-one messages

Next

MessageBody Introduction