undefined

Chat

Dialogs List

Endpoint
GET https://api.connectycube.com/admin/chat/list
Parameters
Parameter Data type Description Value example
updated_at integer (timestamp) Filter dialogs by updated_at field (operators gt, lt, gte, lte) updated_at[gt]=1687886581
created_at integer (timestamp) Filter dialogs by updated_at field (operators gt, lt, gte, lte) created_at[lte]=1687886581
_id string (ObjectId) Filter dialogs by _id field (operators gt, lt, gte, lte) _id[gte]=620e2b1463ee2a1977b4ee65
limit integer Dialogs in one response (default 100, max 100) limit=50
sort_asc/sort_desc string Set sort direction asc/desc (supported fields created_at, updated_at) sort_desc=updated_at
Request example
curl -X GET \
-H "CB-Administration-API-Key: <API_KEY>" \
-d 'updated_at[lt]=1687886581&offset=200' \
https://api.connectycube.com/admin/chat/list
Response
{
  "total_entries": 1788,
  "skip": 200,
  "limit": 100,
  "items": [
    {
      "_id": "620e2b1463ee2a1977b4ee65",
      "user_id": 32241,
      "created_at": "2022-02-17T11:01:40Z",
      "updated_at": "2022-02-17T11:01:49Z",
      "type": 3,
      "occupants_ids":[32241, 32242],
      "last_message": "Warning! People are coming",
      "last_message_date_sent": 1645095709,
      "last_message_id": "620e2b14e45f5b089d000008",
      "last_message_user_id": 32241,
      "last_message_status": "sent",
      "name": null,
      "description": null,
      "photo": null,
      "occupants_count": null,
      "xmpp_room_jid": null,
      "is_e2ee": null,
      "admins_ids":[],
      "is_muted": null,
      "unread_messages_count": null,
      "pinned_messages_ids": null,
      "deleted_ids":[],
      "silent_ids":[]
    }
    ...
  ]
}

Response is similar to Retrieve dialog API, but with additional fields

Parameter Data type Description Value example
silent_ids array of int (field may be missing) Array of users ids who muted chat [32241, 32245]
deleted_ids array of int (field may be missing) Array of users ids who deleted chat [32245]
NodeJS example

To get list of all dialogs, use pagination by updated_at field:

import fetch from 'node-fetch'

const url = 'https://api.connectycube.com/admin/chat/list'
const headers = { 'CB-Administration-API-Key': 'XXXXXXXXXXXXXXXXX' }
const limit = 100

let allDialogs = []

const firstResponse = await fetch(`${url}?limit=${limit}`, { headers }).then(response => response.json())
const { total_entries, items } = firstResponse

console.log(total_entries) // 1167

allDialogs = allDialogs.concat(items)

const totalBatchesCount = Math.ceil(total_entries / limit)

for (let i = 1; i <= totalBatchesCount; ++i) {
  const lastRetrievedDialog = allDialogs.at(-1)
  const lastId = lastRetrievedDialog['_id']
  const lastUpdatedAt = Math.ceil(new Date(lastRetrievedDialog['updated_at']) / 1000) // timestamp

  const firstResponse = await fetch(`${url}?limit=${limit}&updated_at[lt]=${lastUpdatedAt}&_id[lt]=${lastId}&sort_desc=updated_at`, { headers }).then(response => response.json())
  const { items } = firstResponse

  allDialogs = allDialogs.concat(items)
}

console.log(allDialogs.length) // 1167