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
  • Server callbacks
  • Callback on message not sent yet

Callback on message not sent yet

Last updated:2023-10-07 11:59

Description

After setting this callback, when a user sends a message to a one-on-one chat, group chat or room chat, In-app Chat will initiate a request to your business server, and you can perform real-time operations on the message through the response, such as:

  • Recording chat messages and intercepting requests for inappropriate speech;
  • Implementing black and white list functions to determine which messages can be sent normally.

The supported message types for this callback are text messages, image messages, file messages, audio messages, video messages, and custom messages. command messages and barrage messages are not supported.

Based on the value of the response from your business server, you can make one of the following four judgments on whether to send the message:

Value Judgment Whether to send the message Result returned to the message sender Whether the message recipient can receive the message
0 Neutral (not judged whether to send) Send Sent Receivable
1 Send Send Sent Receivable
2 Silently send Send Sent Not receivable
3 Do not send Do not send Not sent Not receivable

Callback request

  • Request method: POST/JSON

    The callback data needs to be decoded by UrlDecode.

  • Request endpoint: Contact ZEGOCLOUD Technical Support to configure the corresponding callback endpoint.

  • Transmission protocol: HTTPS/HTTP (HTTPS is recommended.)

Request parameters

Public parameters Type Description
appid
String
A unique identifier for the App.
event
String
Callback event, the return value of this callback is before_send_msg.
nonce
String
Random number, used to calculate signature.
signature
String
The verification string, see Authenticating server-to-server callbacks for details.
timestamp
Int
The current server time in Unix timestamp format, in seconds, used to calculate the signature.
request_id
String
Request ID.
Business parameters Type Description
from_user_id
String
Message sender ID.
conv_id
String
Target session ID.
conv_type
Int
Target session type:
  • 0: One-on-one chat.
  • 1: Room chat.
  • 2: Group chat.
msg_id
String
Message ID, which can be used to determine the uniqueness of the message.
msg_type
Int
Message type:
  • 1: Text.
  • 11: Images.
  • 12: File.
  • 13: Audio.
  • 14: Video.
  • 200: Custom.
sub_msg_type
Int
The specific custom type. The value is filled in when the user sends a custom message, and the value range is [0,200]. This parameter is meaningful only when msg_type is 200 (custom type).
msg_body
String
Message content.
  • When msg_type is 1 (text type) or 200 (custom type), msg_body is the message content passed in when sending a message, and you can directly read the message content.
  • When msg_type is 11, 12, 13, 14, that is, when the message is a media type, msg_body is a JSON string. Please use URLDecode to decode this JSON string, and parse this JSON string according to the multimedia message structure, and then obtain each field data in the message.

We recommend that you convert some parameters to Int for logical processing. The relevant fields include appid and nonce.

msg_body JSON string parsing result parameter description

Parameters Type Description
md5 String The MD5 value of the file.
file_name String File name.
file_size String File size in bytes.
download_url String Download URL.
media_duration String Audio and Video duration, in seconds.

Callback example

{
    "appid": "1",
    "event": "before_send_msg",
    "from_user_id": "sender",
    "conv_id": "receiver",
    "request_id": "3501907290370176",
    "msg_id": "1234232421343",
    "conv_type": 0,
    "timestamp": 1499676968,
    "msg_body": "msg_body",
    "msg_type": 1,
    "signature": "abc",
    "nonce": "321",
    "sub_msg_type": 0
}

Response parameters

Parameters Type Description
result Int The value of your business server response to determine whether to send the message.
  • 0: neutral (do not judge whether to send).
  • 1: Send.
  • 2: Push silently.
  • 3: Do not send.
  • Others: default to be neutral.

Sample response

{
    "result": 0
}

Return response

Returning an HTTP status code of 2XX (e.g., 200) indicates success, and other responses indicate failure.

Retry mechanism

If the ZEGOCLOUD server does not receive a response, it will retry after 3 seconds. If the callback fails after the second retry, it will no longer be retried and an exception is judged.

Note

When the ZEGOCLOUD client initiates a request to you, if an exception occurs on your business server, no message will be sent by default. If you want to send messages by default, contact ZEGOCLOUD Technical Support.

Page Directory