Callbacks and events
Chat supports HTTP callbacks (webhooks). You can listen for event callbacks and add app logics accordingly. Once a registered callback is triggered by a specified type of event, the Chat server sends an HTTP POST request to your app server, notifying you that the event occurs. The request body is a JSON string encoded in UTF-8 characters.
This page introduces the events and callbacks in Chat.
User login and logout events
When a user logs in to or logs out of the Chat app, the Chat server sends a callback to your app server.
Log in to the app
When a user logs in to the Chat app, the Chat server sends a callback to your app server. The sample code is as follows:
Field | Data Type | Description |
---|---|---|
callId | String | The ID of the callback. The unique identifier assigned to each callback, in the format of {appKey}_{uuid} , where the value of uuid is randomly generated. |
reason | String | The reason that triggers the callback. login indicates that a user logs in to the app. |
security | String | The signature in the callback request used to confirm whether this callback is sent from the Chat server. The signature is the MD5 hash of the {callId} + {secret} + {timestamp} string, where the value of secret can be found on Agora Console. |
os | String | The operating system of the device. Valid values: ios , android , linux , win , and other. |
ip | String | The IP address of the user who logs in to the app. |
host | String | The domain name assigned by the Chat service to access RESTful APIs. |
appkey | String | The key of the app. The unique identifier assigned to each app by the Chat service. |
user | String | The ID of the user. The unique identifier of each user in the Chat app, in the format of {appKey}/{OS}_{deviceId} . |
version | String | The version of the Chat SDK. |
timestamp | Long | The Unix timestamp when the Chat server receives the login request, in milliseconds. |
status | String | The current status of the user. online indicates that the user is online. |
Log out of the app voluntarily
When a user logs out of the Chat app, the Chat server sends a callback to your app server. The sample code is as follows:
Field | Data Type | Description |
---|---|---|
callId | String | The ID of the callback. The unique identifier assigned to each callback, in the format of {appKey}_{uuid} , where the value of uuid is randomly generated. |
reason | String | The reason that triggers the callback. logout indicates that a user logs out of the app. |
security | String | The signature in the callback request used to confirm whether this callback is sent from the Chat server. The signature is the MD5 hash of the {callId} + {secret} + {timestamp} string, where the value of secret can be found on Agora Console. |
os | String | The operating system of the device. Valid values: ios , android , linux , win , and other. |
ip | String | The IP address of the user who logs out of the app. |
host | String | The domain name assigned by the Chat service to access RESTful APIs. |
appkey | String | The key of the app. The unique identifier assigned to each app by the Chat service. |
user | String | The ID of the user. The unique identifier of each user in the Chat app, in the format of {appKey}/{OS}_{deviceId} . |
version | String | The version of the Chat SDK. |
timestamp | Long | The Unix timestamp when the Chat server receives the logout request, in milliseconds. |
status | String | The current status of the user. offline indicates that the user is offline. |
Log out of the app passively
When a user logs out of the Chat app due to being kicked out by another device, the Chat server sends a callback to your app server. The sample code is as follows:
Field | Data Type | Description |
---|---|---|
callId | String | The ID of the callback. The unique identifier assigned to each callback, in the format of {appKey}_{uuid} , where the value of uuid is randomly generated. |
reason | String | The reason that triggers the callback. replaced indicates that a user logs out of the app due to being kicked out by another device. |
security | String | The signature in the callback request used to confirm whether this callback is sent from the Chat server. The signature is the MD5 hash of the {callId} + {secret} + {timestamp} string, where the value of secret can be found on Agora Console. |
os | String | The operating system of the device. Valid values: ios , android , linux , win , and other. |
ip | String | The IP address of the user. |
host | String | The domain name assigned by the Chat service to access RESTful APIs. |
appkey | String | The key of the app. The unique identifier assigned to each app by the Chat service. |
user | String | The ID of the user. The unique identifier of each user in the Chat app, in the format of {appKey}/{OS}_{deviceId} . |
version | String | The version of the Chat SDK. |
timestamp | Long | The Unix timestamp when the Chat server receives the logout request, in milliseconds. |
status | String | The current status of the user. offline indicates that the user is offline. |
Message events
Send a message
When a user sends a message in a one-to-one chat, chat group, or chat room of the Chat app, the Chat server sends a callback to your app server. The sample code is as follows:
Field | Data Type | Description |
---|---|---|
callId | String | The ID of the callback. The unique identifier assigned to each callback, in the format of {appKey}_{uuid} , where the value of uuid is randomly generated. |
eventType | String | The message type of the callback.
|
timestamp | Long | The Unix timestamp when the Chat server receives the callback event, in milliseconds. |
chat_type | String | The type of chat.
|
group_id | String | The ID of the chat group or chat room where the message is sent. This field only exists if chat_type is set to groupchat . |
from | String | The sender of the message. |
to | String | The recipient of the message. |
msg_id | String | The message ID of the callback event. This ID is the same as the msg_id when the message is sent. |
payload | Object | The structure of the callback event. This field varies according to the type of the message sent in a one-to-one chat, chat group, or chat room. See payload example below for details. |
securityVersion | String | This parameter is reserved for future use. |
security | String | The signature in the callback request used to confirm whether this callback is sent from the Chat server. The signature is the MD5 hash of the {callId} + {secret} + {timestamp} string, where the value of secret can be found on Agora Console. |
appkey | String | The key of the app. The unique identifier assigned to each app by the Chat service. |
host | String | The domain name assigned by the Chat service to access RESTful APIs. |
Send a text message
When a user sends a text message in a one-to-one chat, chat group, or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
ext
indicates the message extension in Object data type. bodies
indicates the message body in Object data type, which contains the following fields:
Field | Data Type | Description |
---|---|---|
msg | String | The content of the text message. |
type | String | The type of the message. txt indicates a text message. |
Send an image message
When a user sends an image message in a one-to-one chat, chat group, or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
ext
indicates the message extension in Object data type. bodies
indicates the message body in Object data type, which contains the following fields:
Field | Data Type | Description |
---|---|---|
filename | String | The filename of the image. |
secret | String | The secret returned after uploading the image file. |
size | Json | The dimension of the image in pixels.
|
file_length | Int | The size of the image in bytes. |
url | String | The URL of the image, in the format of https://{host}/{org_name}/{app_name}/chatfiles/{file_uuid} , where file_uuid is the ID of the image file. You can fetch file_uuid from the response body after the file is uploaded. |
type | String | The type of the message. img indicates an image message. |
Send an audio message
When a user sends an audio message in a one-to-one chat, chat group, or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
ext
indicates the message extension in Object data type. bodies
indicates the message body in Object data type, which contains the following fields:
Field | Data Type | Description |
---|---|---|
filename | String | The filename of the audio. |
secret | String | The secret returned after uploading the audio file. |
file_length | Long | The size of the audio file in bytes. |
length | Int | The duration of the audio file in seconds. |
url | String | The URL of the audio file, in the format of https://{host}/{org_name}/{app_name}/chatfiles/{file_uuid} , where file_uuid is the ID of the audio file. You can fetch file_uuid from the response body after the file is uploaded. |
type | String | The type of the message. audio indicates an audio message. |
Send a video message
When a user sends a video message in a one-to-one chat, chat group, or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
ext
indicates the message extension in Object data type. bodies
indicates the message body in Object data type, which contains the following fields:
Field | Data Type | Description |
---|---|---|
thumb_secret | String | The secret returned after uploading the video thumbnail. |
filename | String | The filename of the video. |
size | Json | The dimension of the video thumbnail.
|
thumb | String | The URL of the thumbnail, in the format of https://{host}/{org_name}/{app_name}/chatfiles/{file_uuid} , where file_uuid is the ID of the video thumbnail. You can fetch file_uuid from the response body after the video thumbnail is uploaded. |
secret | String | The secret returned after uploading the video file. |
file_length | Long | The size of the video file in bytes. |
url | String | The URL of the video file, in the format of https://{host}/{org_name}/{app_name}/chatfiles/{file_uuid} , where file_uuid is the ID of the video file. You can fetch file_uuid from the response body after the video file is uploaded. |
type | String | The type of the message. video indicates a video message. |
Send a location message
When a user sends a location message in a one-to-one chat, chat group, or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
ext
indicates the message extension in Object data type. bodies
indicates the message body in Object data type, which contains the following fields:
Field | Data Type | Description |
---|---|---|
log | String | The longitude of the location. |
lat | String | The latitude of the location. |
addr | String | The address of the location. |
type | String | The type of the message. loc indicates a location message. |
Send a command message
When a user sends a command message in a one-to-one chat, chat group, or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
ext
indicates the message extension in Object data type. bodies
indicates the message body in Object data type, which contains the following fields:
Field | Data Type | Description |
---|---|---|
msg | String | The content of the command message. |
type | String | The type of the message. cmd indicates a command message. |
Send a custom message
When a user sends a custom message in a one-to-one chat, chat group, or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
ext
indicates the message extension in Object data type. bodies
indicates the message body in Object data type, which contains the following fields:
Field | Data Type | Description |
---|---|---|
customExts/v2:customExts | Json | The attribute of the custom event, in the Map<String, String> format. The attribute can contain a maximum of 16 elements. |
customEvent | String | The type of the custom event. The type can be 1 to 32 characters. |
type | String | The type of the message. custom indicates a custom message. |
Recall a message
When a user recalls a message in a one-to-one chat, chat group, or chat room of the Chat app, the Chat server sends a callback to your app server. The sample code is as follows:
Field | Data Type | Description |
---|---|---|
callId | String | The ID of the callback. The unique identifier assigned to each callback, in the format of {appKey}_{uuid} , where the value of uuid is randomly generated. |
eventType | String | The message type of the callback.
|
timestamp | Long | The Unix timestamp when the Chat server receives the callback event, in milliseconds. |
chat_type | String | The type of chat.
|
group_id | String | The ID of the chat group or chat room where the message resides. This field only exists if chat_type is set to groupchat . |
from | String | The sender of the message. |
to | String | The recipient of the message. |
recall_id | String | The ID of the message to recall. |
msg_id | String | The message ID of the callback event. This ID is the same as the msg_id when the end user sends the message. |
payload | Object | The structure of the callback event that contains the following fields:
|
securityVersion | String | This parameter is reserved for future use. |
security | String | The signature in the callback request used to confirm whether this callback is sent from the Chat server. The signature is the MD5 hash of the {callId} + {secret} + {timestamp} string, where the value of secret can be found on Agora Console. |
appkey | String | The key of the app. The unique identifier assigned to each app by the Chat service. |
host | String | The domain name assigned by the Chat service to access RESTful APIs. |
Chat group and chat room events
When a user performs operations on a chat group or chat room in the Chat app, the Chat server sends a callback to your app server. The sample code is as follows:
Field | Data Type | Description |
---|---|---|
chat_type | String | The type of the event. muc indicates a chat group or a chat room. |
callId | String | The ID of the callback. The unique identifier assigned to each callback, in the format of {appKey}_{file_uuid} , where the value of file_uuid is randomly generated. |
eventType | String | The message type of the callback.
|
timestamp | Long | The Unix timestamp when the Chat server receives the callback event, in milliseconds. |
group_id | String | The ID of the chat group or chat room where the message resides. This field only exists if chat_type is set to groupchat . |
from | String | The sender of the message. |
to | String | The recipient of the message. |
msg_id | String | The message ID of the callback event. This ID is the same as the msg_id when sending the message. |
payload | Object | The content structure of the callback event that contains the following fields:
|
securityVersion | String | This parameter is reserved for future use. |
security | String | The signature in the callback request used to confirm whether this callback is sent from the Chat server. The signature is the MD5 hash of the {callId} + {secret} + {timestamp} string, where the value of secret can be found on Agora Console. |
appkey | String | The key of the app. The unique identifier assigned to each app by the Chat service. |
host | String | The domain name assigned by the Chat service to access RESTful APIs. |
Create a chat group or chat room
When a user creates a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Destroy a chat group or chat room
When the owner destroys a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Send a join request to a chat group
When a user sends a join request to a chat group, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Accept a join request
When the owner or an admin accepts a join request to the chat group, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Send a group invitation to a user
When a user invites another user to a chat group, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Accept a group invitation
When a user accepts a group invitation, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Decline a group invitation
When a user declines a group invitation, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Join a chat group or chat room
When a user joins a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Leave a chat group or chat room
When a member voluntarily leaves a group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
When a member voluntarily or passively leaves a chat group or chat room, the Chat server sends the leave result to your app server. The sample code of the payload
field is as follows:
Remove a member from a chat group or chat room
When the owner or an admin removes a member from a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Add a member to the block list of a chat group or chat room
When the owner or an admin adds a member to the block list of a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Remove a member from the block list of a chat group or chat room
When the owner or an admin removes a member from the block list of a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Add a member to the allow list of a chat group or chat room
When the owner or an admin adds a member to the allow list of a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Remove a member from the allow list of a chat group or chat room
When the owner or an admin removes a member from the allow list of a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Mute a member in a chat group or chat room
When the owner or an admin mutes a member in a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Unmute a member in a chat group or chat room
When the owner or an admin unmutes a member in a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Mute a chat group or chat room
When a member mutes a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Unmute a chat group or chat room
When a member unmutes a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Mute a chat group or chat room globally
When a chat group or chat room is globally muted, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Unmute a chat group or chat room globally
When a chat group or chat room is globally unmuted, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Transfer the ownership
When the owner transfers the ownership of a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Promote a member to an admin
When the owner promotes a member to an admin in a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Demote an admin to a member
When the owner demotes an admin to a member in a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Update the information of a chat group or chat room
When the owner or an admin updates the information of a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Update the announcements of a chat group or chat room
When the owner or an admin updates the announcements of a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Delete the announcements of a chat group or chat room
When the owner or an admin deletes the announcements of a chat group or chat room, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Upload a shared file to a chat group
When a user uploads a shared file to a chat group, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
reason
indicates the details of the shared file uploaded to a chat group, which contains the following fields:
file_id
: The ID of the file.file_name
: The filename.file_owner
: The owner of the file, that is, the ID of the user who uploads the file.file_size
: The size of the file in bytes.created
: The Unix timestamp when the file is created, in milliseconds.
Delete a shared file in a chat group
When a user deletes a shared file in a chat group, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
User contact events
When a user performs operations on the contacts in the Chat app, the Chat server sends a callback to your app server. The sample code is as follows:
Field | Data Type | Description |
---|---|---|
chat_type | String | The type of the event. roster indicates an event occurred in user contacts. |
callId | String | The ID of the callback. The unique identifier assigned to each callback, in the format of {appKey}_{uuid} , where the value of uuid is randomly generated. |
eventType | String | The message type of the callback.
|
timestamp | Long | The Unix timestamp when the Chat server receives the callback event, in milliseconds. |
from | String | The user who operates the contact. |
to | String | The contact who is operated by the user. |
msg_id | String | The message ID of the callback event. This ID is the same as the msg_id when sending the message. |
payload | Object | The structure of the callback event. See payload example below for details. |
security | String | The signature in the callback request used to confirm whether this callback is sent from the Chat server. The signature is the MD5 hash of the {callId} + {secret} + {timestamp} string, where the value of secret can be found on Agora Console. |
appkey | String | The key of the app. The unique identifier assigned to each app by the Chat service. |
host | String | The domain name assigned by the Chat service to access RESTful APIs. |
Send a contact invitation
When a user adds a contact in the Chat app, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Remove a contact
When a user removes a contact in the Chat app, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Accept a contact invitation
When a user accepts the contact invitation from another user, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
When another user accepts the contact invitation from a user, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Decline a contact invitation
When a user declines the contact invitation from another user, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
When another user declines the contact invitation from a user, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Add a contact to the block list
When a user adds a contact to the block list, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Remove a contact from the block list
When a user removes a contact from the block list, the Chat server sends a callback to your app server. The sample code of the payload
field is as follows:
Receipt events
When a user sends an receipt, the Chat server sends a callback to your app server. The sample code is as follows:
Field | Data Type | Description |
---|---|---|
chat_type | String | The type of the event.
|
callId | String | The ID of the callback. The unique identifier assigned to each callback, in the format of {appKey}_{uuid} , where the value of uuid is randomly generated. |
security | String | The signature in the callback request used to confirm whether this callback is sent from the Chat server. The signature is the MD5 hash of the {callId} + {secret} + {timestamp} string, where the value of secret can be found on Agora Console. |
payload | Object | The structure of the callback event that contains the following fields:
|
host | String | The domain name assigned by the Chat service to access RESTful APIs. |
appkey | String | The key of the app. The unique identifier assigned to each app by the Chat service. |
from | String | The ID of the user who sends the receipt. |
to | String | The ID of the user who receives the receipt. |
eventType | String | The message type of the callback.
|
timestamp | long | The Unix timestamp when the Chat server receives the callback event, in milliseconds. |
msg_id | String | The message ID of the receipt. |
Content moderation result
When the message moderation is complete, the Chat server sends the moderation result to your app server.
The sample code is as follows:
Parameter | Type | Description |
---|---|---|
callId | String | The ID of the callback. The unique identifier assigned to each callback, in the format of {appKey}_{uuid} , where the value of uuid is randomly generated. |
moderationResult | String | The message handling result: - PASS :Send the message. - REJECT : Reject sending the message. - EXCHANGE : Replace the sensitive content in the message.- RECALL : Recall the voice or video that is sent. |
providerResult | String | The message moderation result: - PASS : The message does not contain inappropriate content. - REVIEWED :The message is suspected of containing inappropriate content. - REJECT :The message contains inappropriate content. |
security | String | The signature in the callback request used to confirm whether this callback is sent from the Chat server. The signature is the MD5 hash of the {callId} + {secret} + {timestamp} string, where the value of secret can be found on Agora Console. |
messageType | String | The message text: - txt : Text message.- img : Image message.- audio : Voice message.- video : Video message.- custom : Custom message. |
messageId | String | Message ID. |
targetType | String | Conversation type: - chat: One-to-one chat.<br/> - groupchat: Group chat.<br/> - chatroom`: Chat room. |
appkey | String | The key of the app. The unique identifier assigned to each app by the Chat service. |
eventType | String | The event type, which is moderation for the moderation service. |
from | String | The user ID of the message sender. |
to | String | The message recipient: - One-to-one chat: User ID of the message recipient. - Group chat: Group ID. - Chat room: Chat room ID. |
msg | String | The content of the text message. This parameter is valid only when messageType is txt . |
url | String | The URL of the attachment message, like a voice, video, or image message. This parameter is valid only when messageType is img , audio , or video . |
timestamp | Number | The Unix timestamp when the Chat server receives the callback event, in milliseconds. |