Set a timer to close a chat room

Update time: 2022/12/13 08:47:07

Chat rooms can be automatically closed by setting a timer.

You can set a countdown timer for closing a chat room when creating a chat room, or call the API described in this document to set a timer.

You have the following two options for closing a chat room:

  • Close a chat room after a fixed time period(delayClosePolicy = 1): N hours after the chat room is created, it will be closed automatically, regardless of whether participants exist in the chat room.
  • Close a chat room after the chat room stay idle (delayClosePolicy = 2): N hours after no participants exist in the chat room, automatically close the chat room.
  • The previous N hours are defined by the delaySeconds parameter in the API. Note that the unit in the parameter is seconds.
  • Timed closure does not happen in real time. Some discrepancies may occur.

Set a countdown timer to close a chat room.

You can change the method to close a chat room by calling this API. If the call is successful, the timer will restart from the current time.

Request URL

httpPOST  https://api.netease.im/nimserver/chatroom/updateDelayClosePolicy.action  HTTP/1.1
Content-Type: application/x-www-form-urlencoded;charset=utf-8

Request parameters

  • For the setting of Headers in POST requests, seeAPI Calling.

  • The settings of the body in a POST request:

ParameterTypeRequiredDescription
roomid LongYes Chat room ID
delayClosePolicy IntegerNo Timer option. 0: no timer,
1: set a timer to close the chat room regardless of whether participants exist in the chat room,
2: set a timer to close the chat room when no participants exist in the chat room
delaySeconds LongNo The timer to close the chat room.
If you set delayClosePolicy=1 or 2 without a specific period of time, the default value (7*24*3600s) is applied

Response parameters

ParameterTypeDescription
code IntegerStatus code
roomid LongChat room ID
valid Booleanfalse: close a chat room, true: open a chat room
announcement StringAnnouncement in a chat room
name StringThe name of a chat room
broadcasturl StringURL for live streaming
ext StringExtension field
queuelevel Integer Queue management permission. 0: All participants have the permission to change a queue, 1: Only hosts and administrators have the permission to change a queue
muted BooleanWhether the chat room is all muted. Only administrators and creators can speak if a chat room is all muted. false: unmuted, true: muted
creator StringID of the creator
delayInfo StringTimer info
delayCloseEnable BooleanWhether a timer is enabled, true: enabled, false: disabled
delayClosePolicyIntegerMethod to close a chat room. 0: no timer, 1: close a chat room when the timer ends, 2: close a chat room if no participants exist in the chat room
delaySeconds Long Timer period. The maximum period (7*24*3600s)
status IntegerCurrent status, 1: The task starts in the initial state, 2: waiting state, 3: task completion state, 4: task canceled< /td>
startTimeLong Timestamp of the start time

Example

cURL request

curlcurl -X POST -i 'https://api.netease.im/nimserver/chatroom/updateDelayClosePolicy.action' -H "Nonce: 12345" -H "CheckSum: 54871a1f9a695bba5d42c04e727e6423c87fa728" -H "AppKey: 2bd025c577313e81b2bdb2d2dcefcadb" -H "CurTime: 1666597250" -d 'roomid=1600849147&delayClosePolicy=2&delaySeconds=60'

Example success response

json"Content-Type": "application/json; charset=utf-8"
{
  "code": 200,
  "chatroom": {
    "valid": true,
    "ext": "",
    "creator": "test100",
    "name": "test1-chatroom",
    "muted": false,
    "announcement": null,
    "broadcasturl": "xxxxxx",
    "roomid": 1600849147,
    "queuelevel": 0,
    "delayInfo": {
    "delaySeconds": 60,
        "delayCloseEnable": true,
        "startTime": 1666597250262,
        "delayClosePolicy": 2,
        "status": 2
        }
    }
}

Example error response

json"Content-Type": "application/json; charset=utf-8"
{
    "code": 414,  
    "desc": "owner not register" 
}

Status codes

The following status codes are related to responses of this API. For more status codes, see Status codes.

Status code Description Recommendation
200 Success -
414 Parameter error Check the format and restrictions of arguments based on the error message
403 Forbidden operation The chat room name failed to pass the moderation or the chat room permission is not granted
404 Chat room does not exist Check the chat room ID
419 The number of chat rooms exceeds the upper limit -
13009 The timer for closing a chat room is disabled It is recommended to enable the timer
13002 The chat room is already closed Open or recreate the chat room
Was this page helpful?
Yes
No
  • Request URL
  • Request parameters
  • Response parameters
  • Example
  • cURL request
  • Example success response
  • Example error response
  • Status codes