Sending Ordinary Messages in a Group

Last updated: 2020-07-09 15:19:38

    Feature Description

    This API is used by app admins to send ordinary messages in a group.

    API Calling Description

    Applicable group types

    Group Type ID Is this RESTful API Supported?
    Private Yes. Same as Work (work group for friends) in the new version.
    Public Yes.
    ChatRoom Yes. Same as Meeting (temporary meeting group) in the new version.
    AVChatRoom Yes.

    These are the 4 built-in group types in IM. For detailed information, see the Group System.

    Sample request URL

    https://console.tim.qq.com/v4/group_open_http_svc/send_group_msg?sdkappid=88888888&identifier=admin&usersig=xxx&random=99999999&contenttype=json

    Request parameters

    The list below contains only the parameters commonly used when calling this API and their descriptions. For more parameters, see RESTful API Overview.

    Parameter Description
    v4/group_open_http_svc/send_group_msg Request API
    sdkappid SDKAppID assigned by the IM console when the application is created
    identifier The value must be the app admin account. For more information, see App Admins.
    usersig Signature generated by the app admin account. For details, see Generating UserSig.
    random A random 32-bit unsigned integer ranging from 0 to 4294967295

    Maximum calling frequency

    The maximum calling frequency is 200 calls per second.

    Sample request packet

    • Basic form
      The app admin sends ordinary group messages.
      {
        "GroupId": "@TGS#2C5SZEAEF",
        "Random": 8912345, // A random number. If the random numbers of two messages within five minutes are the same, the two messages are considered to be the same message.
        "MsgBody": [ // Message body, which consists of an element array. For details, see the field description.
            {
                "MsgType": "TIMTextElem", // Text message
                "MsgContent": {
                    "Text": "red packet"
                }
            },
            {
                "MsgType": "TIMFaceElem", // Emoji message
                "MsgContent": {
                    "Index": 6,
                    "Data": "abc\u0000\u0001"
                }
            }
        ],
        "OfflinePushInfo": {
            "PushFlag": 0, // Normal push
            "Desc": "The content that is pushed offline",
            "Ext": "This is the passthrough content",
            "AndroidInfo": {
                "Sound": "android.mp3"
            },
            "ApnsInfo": {
                "Sound": "apns.mp3",
                "BadgeMode": 1, // If this parameter is not specified or is set to 0, the message is counted. If this parameter is set to 1, the message is not counted, that is, the number in the upper-right corner of the icon does not increase.
                "Title":"apns title", // apns title
                "SubTitle":"apns subtitle", // apns subtitle
                "Image":"www.image.com" // image url
            }
        }
      }
    • Specify the message sender
      The app admin can specify a group member as the message sender in From_Account.
      After receiving the message, other members will see that the message is sent from the group member specified by the app admin.
      {
        "GroupId": "@TGS#2C5SZEAEF",
        "From_Account": "leckie", // Message sender (optional)
        "Random": 8912345, // A random number. If the random numbers of two messages within five minutes are the same, the two messages are considered to be the same message.
        "MsgBody": [ // Message body, which consists of an element array. For details, see the field description.
            {
                "MsgType": "TIMTextElem", // Text message
                "MsgContent": {
                    "Text": "red packet"
                }
            },
            {
                "MsgType": "TIMFaceElem", // Emoji message
                "MsgContent": {
                    "Index": 6,
                    "Data": "abc\u0000\u0001"
                }
            }
        ]
      }
    • Specify the message priority
      You can specify the message priority. The default priority is Normal.
      The four priority options in descending order are High, Normal, Low, and Lowest. They are case-sensitive.
      {
        "GroupId": "@TGS#2C5SZEAEF",
        "Random": 8912345, // A random number. If the random numbers of two messages within five minutes are the same, the two messages are considered to be the same message.
        "MsgPriority": "High", // Message priority
        "MsgBody": [ // Message body, which consists of an element array. For details, see the field description.
            {
                "MsgType": "TIMTextElem", // Text message
                "MsgContent": {
                    "Text": "red packet"
                }
            },
            {
                "MsgType": "TIMFaceElem", // Emoji message
                "MsgContent": {
                    "Index": 6,
                    "Data": "abc\u0000\u0001"
                }
            }
        ]
      }
    • Disable callback for a specified message
      When callback is toggled on, users can specify ForbidCallbackControl to control whether to initiate callback for a single message. By default, callback is initiated.
      {
        "GroupId": "@TGS#2C5SZEAEF",
        "Random": 8912345, // A random number. If the random numbers of two messages within five minutes are the same, the two messages are considered to be the same message.
        "ForbidCallbackControl":[
                "ForbidBeforeSendMsgCallback",
                "ForbidAfterSendMsgCallback"], // Option to control whether to disable callback
        "MsgBody": [ // Message body, which consists of an element array. For details, see the field description.
            {
                "MsgType": "TIMTextElem", // Text message
                "MsgContent": {
                    "Text": "red packet"
                }
            },
            {
                "MsgType": "TIMFaceElem", // Emoji message
                "MsgContent": {
                    "Index": 6,
                    "Data": "abc\u0000\u0001"
                }
            }
        ]
      }
    • Specify messages for online delivery without offline or roaming retention
      If OnlineOnlyFlag in the message body is set to a value greater than 0, the message is for online delivery only, not for offline or roaming retention (this feature is not supported by AVChatRooms and BChatRooms).
        {
            "GroupId": "@TGS#2C5SZEAEF",
            "Random": 8912345, // A random number. If the random numbers of two messages within five minutes are the same, the two messages are considered to be the same message.
            "OnlineOnlyFlag": 1, // This indicates that the message is for online delivery only (only online group members will receive the message), not for offline or roaming retention.
            "MsgBody": [ // Message body, which consists of an element array. For details, see the field description.
                {
                    "MsgType": "TIMTextElem", // Text message
                    "MsgContent": {
                        "Text": "red packet"
                    }
                },
                {
                    "MsgType": "TIMFaceElem", // Emoji message
                    "MsgContent": {
                        "Index": 6,
                        "Data": "abc\u0000\u0001"
                    }
                }
            ]
        }

    Request packet fields

    Field Type Required Description
    GroupId String Required ID of the group to which messages are to be sent
    Random Integer Required A random 32-bit unsigned integer. If the random numbers of two messages within five minutes are the same, the second message will be discarded as a duplicate.
    MsgPriority String Optional Message priority
    MsgBody Array Required Message body. For details, see Message Format Description.
    From_Account String Optional Message source account (optional). If this field is not specified, the message sender is the app admin account that is used to call the API by default. Alternatively, apps can specify the message sender in this field for some special purposes. Note that if this field is specified, you must ensure that the account in this field does exist.
    OfflinePushInfo Object Optional Information to be pushed offline. For more information, see Message Format Description.
    ForbidCallbackControl Array Optional Message callback forbidden toggle, which is valid only for single messages. ForbidBeforeSendMsgCallback indicates that callbacks before message sending are forbidden, and ForbidAfterSendMsgCallback indicates that callbacks after message sending are forbidden.
    OnlineOnlyFlag Integer Optional 1: messages are sent to online members only. 0 (default): messages are sent to all group members. AVChatRooms (livestreaming groups) do not support this parameter.

    Sample response packet body

    {
        "ActionStatus": "OK",
        "ErrorInfo": "",
        "ErrorCode": 0,
        "MsgTime": 1497249503,
        "MsgSeq": 1
    }

    Response packet fields

    Field Type Description
    ActionStatus String The processing result of the request. OK: succeeded. FAIL: failed.
    ErrorCode Integer Error code. 0 indicates that the request was successful, and any non-zero value indicates that the request failed.
    ErrorInfo String Detailed error information
    MsgTime Integer Message sending timestamp, which is synced to the backend server time
    MsgSeq Integer Message sequence number, which is the unique identifier of a message

    Error Codes

    Unless a network error (such as error 502) occurs, the returned HTTP status code for this API is always 200. The specific error code and details can be found in the response packet fields such as ErrorCode and ErrorInfo.
    For public error codes (60000 to 79999), see Error Codes.
    The list below contains error codes specific to this API:

    Error Code Description
    10002 An internal server error occurred. Please try again.
    10004 A parameter is invalid. Check the error description and troubleshoot the issue.
    10007 Insufficient permissions. For example, to remove someone from a public group requires admin permissions.
    10010 The group does not exist, or once existed but has been disbanded.
    10015 The group ID is invalid. Be sure to use the correct group ID.
    10016 The app backend rejected this operation through a third-party callback.
    10017 The message cannot be sent because the sender has been muted. Check whether the sender is muted.
    10023 The message sending frequency exceeds the limit. Please send messages at a slower pace.
    80001 The message failed text content filtering. Check whether the message contains sensitive words.
    80002 The message is too long. Currently, the supported maximum message length is 8,000 bytes. Adjust the message length.

    API Debugging Tool

    Use the online debugging tool for RESTful APIs to debug this API.

    Reference

    Possible Callbacks

    Callback Before Delivering Group Messages

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help