Offline push
This page shows how to call Chat RESTful APIs to set the display name, display style, push notification mode, and do-not-disturb (DND) mode.
Before calling the following methods, ensure that you meet the following:
-
You understand the call frequency limit of the Chat RESTful APIs as described in Limitations.
-
You have activated the advanced features for push in Agora Console. Advanced features allow you to set the push notification mode, do-not-disturb mode, and custom push template.
Common parameters
The following table lists common request and response parameters of the Chat RESTful APIs:
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
host | String | The domain name assigned by the Chat service to access RESTful APIs. For how to get the domain name, see Get the information of your project. | Yes |
org_name | String | The unique identifier assigned to each company (organization) by the Chat service. For how to get the org name, see Get the information of the Chat project. | Yes |
app_name | String | The unique identifier assigned to each app by the Chat service. For how to get the app name, see Get the information of the Chat project. | Yes |
username | String | The unique login account of the user. | Yes |
Response parameters
Parameter | Type | Description |
---|---|---|
action | String | The request method. |
organization | String | The unique identifier assigned to each company (organization) by the Chat service. This is the same as org_name . |
application | String | A unique internal ID assigned to each app by the Chat service. You can safely ignore this parameter. |
applicationName | String | The unique identifier assigned to each app by the Chat service . This is the same as app_name . |
timestamp | Number | The Unix timestamp (ms) of the HTTP response. |
duration | Number | The duration (ms) from when the HTTP request is sent to the time the response is received. |
path | String | The request path, which is part of the request URL. You can safely ignore this parameter. |
uri | String | The request URI. |
entities | JSON | The response entity. |
data | JSON | The response details. |
Authorization
Chat RESTful APIs require Bearer HTTP authentication. Every time an HTTP request is sent, the following Authorization
field must be filled in the request header:
In order to improve the security of the project, Agora uses a token (dynamic key) to authenticate users before they log in to the chat system. Chat RESTful APIs only support authenticating users using app tokens. For details, see Authentication using App Token.
Set the display name in push notifications
Sets the nickname displayed in push notifications.
For each App Key, the total call frequency limit of this method and the method to set the display style is 100 per second.
HTTP request
Path parameter
For the descriptions of path parameters, see Common Parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The content type. Set it as application/json . | Yes |
Accept | String | The parameter type. Set it as application/json . | Yes |
Authorization | String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. | Yes |
Request body
Parameter | Type | Description | Required |
---|---|---|---|
nickname | String | The nickname displayed in push notifications. The length of the nickname cannot exceed 100 characters, and the following character sets are supported: The nickname can be different from the nickname in the user profile; however, Agora recommend that you use the same nickname for both. Therefore, if either nickname is updated, the other should be changed at the same time. To update the nickname in the user profile, see Setting user attributes. | No |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
uuid | String | A unique internal identifier generated by the Chat service for the user in this request. |
type | String | The type of the chat. "user" indicates a one-to-one chat. |
created | Number | The Unix timestamp (ms) when the user account is registered. |
modified | Number | The Unix timestamp (ms) when the user information is last modified. |
username | String | The ID of the user. |
activated | Bool | Whether the user account is active:true : The user account is active.false : The user account is deactivated. To unban a deactivated user account, refer to Unbanning a user. |
nickname | String | The nickname displayed in push notifications. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Set the display style in push notifications
Sets the display style of push notifications.
For each App Key, the total call frequency limit of this method and the method to set the display name is 100 per second.
HTTP request
Path parameter
For the descriptions of path parameters, see Common Parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Authorization | String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. | Yes |
Request body
Parameter | Type | Description | Required |
---|---|---|---|
notification_display_style | Int | The display style of push notifications:0 : The push title is "You have a new message", and the push content is "Click to check".1 : The push title is "You have a new message", and the push content contains the nickname of the sender and the content of the offline message. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
uuid | String | A unique internal identifier generated by the Chat service for the user in this request. |
type | String | The type of the chat. "user" indicates a one-to-one chat. |
created | Number | The Unix timestamp (ms) when the user account is registered. |
modified | Number | The Unix timestamp (ms) when the user information is last modified. |
username | String | The ID of the user. |
activated | Bool | Whether the user account is active:true : The user account is active.false : The user account is deactivated. To unban a deactivated user account, refer to Unbanning a user. |
notification_display_style | String | The display style of push notifications. |
nickname | String | The nickname displayed in push notifications. |
notifier_name | String | The name of the push certificate. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Set up push notifications
Sets the push notification and DND modes at both the app and conversation levels.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
type | String | The type of the chat:user : one-to-one chats.chatgroup : Group chats. | Yes |
key | String | The identifier of the chat:type is set to user , key indicates the user ID of the peer user.type is set to chatgroup , key indicates the ID of the chat group. | Yes |
type
to user
and key
to the user ID of the current user.Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The content type. Set it as application/json . | Yes |
Authorization | String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. | Yes |
Request body
Parameter | Type | Description | Required |
---|---|---|---|
type | String | The push notification mode:DEFAULT : Inherits the setting at the app level.ALL : Receives push notifications for all offline messages.AT : Only receives push notifications for mentioned messages.NONE : Do not receive push notifications for offline messages. | No |
ignoreInterval | String | The DND time frame in the format of {HH:MM-HH:MM} , for example, 08:30-10:00. The range of HH is [00,23] in hours, while the range of MM is [00,59].This parameter is valid only when type is set to user and key is set to the user ID of the current user in the request header, meaning the DND time frame only takes effect on an app rather than a specific conversation. | No |
ignoreDuration | Long | The DND duration in milliseconds. The range is [0,604800000], where 0 indicates that this parameter is invalid and 604800000 indicates that the DND mode lasts for 7 days. | No |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
type | String | The push notification mode. |
ignoreInterval | String | The DND time frame. |
ignoreDuration | Long | The DND duration. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Retrieve the settings of push notifications
Retrieves the push notification and DND modes at both the app and conversation levels.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
type | String | The type of the chat:user : one-to-one chats.chatgroup : Group chats. | Yes |
key | String | The identifier of the chat:type is set to user , key indicates the user ID of the peer user.type is set to chatgroup , key indicates the ID of the chat group. | Yes |
For the descriptions of other path parameters, see Common Parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Authorization | String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
type | String | The push notification mode. |
ignoreInterval | String | The DND time frame. |
ignoreDuration | Long | The DND duration. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Set the preferred language of push notifications
Sets the preferred language of push notifications.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the descriptions of path parameters, see Common Parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The content type. Set it as application/json . | Yes |
Authorization | String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. | Yes |
Request body
Parameter | Type | Description | Required |
---|---|---|---|
translationLanguage | String | The code for the language that the user prefers to see push notifications in. If set to an empty string, the server pushes the notifications of the original language directly. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
language | String | The code for the language that the user prefers to see push notifications in. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Retrieve the preferred language of push notifications
Retrieves the preferred language of push notifications.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the descriptions of path parameters, see Common Parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The content type. Set it as application/json . | Yes |
Authorization | String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
language | String | The code for the language that the user prefers to see push notifications in. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Create a push template
Creates a template for push notifications.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the descriptions of path parameters, see Common Parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The content type. Set it as application/json . | Yes |
Authorization | String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. | Yes |
Request body
Parameter | Type | Description | Required |
---|---|---|---|
name | String | The name of the push template. | Yes |
title_pattern | String | The custom title of the push template. You can add variables in the title, such as 0. | Yes |
content_pattern | String | The custom content of the push template. You can add variables in the content, such as 0 and 1. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
name | String | The name of the push template. |
createAt | Number | The Unix timestamp (ms) when the template is created. |
updateAt | Number | The Unix timestamp (ms) when the template is last modified. |
title_pattern | String | The custom title of the push template. |
content_pattern | String | The custom content of the push template. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Retrieve a push template
Retrieves the specified template for push notifications.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
name | String | The name of the push template. | Yes |
For the descriptions of other path parameters, see Common Parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Authorization | String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
name | String | The name of the push template. |
createAt | Number | The Unix timestamp (ms) when the template is created. |
updateAt | Number | The Unix timestamp (ms) when the template is last modified. |
title_pattern | String | The custom title of the push template. |
content_pattern | String | The custom content of the push template. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Delete a push template
Deletes the specified template for push notifications.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
name | String | The name of the push template. | Yes |
For the descriptions of other path parameters, see Common Parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Authorization | String | The authentication token of the user or administrator, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
name | String | The name of the push template. |
createAt | Number | The Unix timestamp (ms) when the template is created. |
updateAt | Number | The Unix timestamp (ms) when the template is last modified. |
title_pattern | String | The custom title of the push template. |
content_pattern | String | The custom content of the push template. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Status codes
For details, see HTTP Status Codes.