undefined

Messaging

ConnectyCube Chat (messaging) API is built on top of Real-time(XMPP) protocol. In order to use it you need to setup real-time connection with ConnectyCube Chat server and use it to exchange data.

By default Real-time Chat works over secure TLS connection.

Get started with SDK

Follow the Getting Started guide on how to connect ConnectyCube SDK and start building your first app.

Code samples

There are ready-to-go FREE code samples to help you better understand how to integrate messaging capabilities in your apps:

Connect to chat

const userCredentials = {
  userId: 4448514,
  password: "awesomepwd"
};

// JS SDK v1
ConnectyCube.chat.connect(userCredentials, (error, contactList) => {});

// JS SDK v2
ConnectyCube.chat
  .connect(userCredentials)
  .then(() => {
    // connected
  })
  .catch(error => {});

Connect to chat using custom authentication providers

In some cases we don't have a user's password, for example when login via:

  • Facebook
  • Twitter
  • Firebase phone authorization
  • Custom identity authentication
  • etc.

In such cases ConnectyCube API provides possibility to use ConnectyCube session token as a password for chat connection:

// get current ConnectyCube session token and set as user's password
const token = ConnectyCube.service.sdkInstance.session.token;

const userCredentials = {
    userId: 4448514,
    password: token
};

Disconnect

ConnectyCube.chat.disconnect();

ConnectyCube.chat.onDisconnectedListener = onDisconnectedListener;

function onDisconnectedListener() {}

Reconnection

The SDK reconnects automatically when connection to Chat server is lost.

The following 2 callbacks are used to track the state of connection:

ConnectyCube.chat.onDisconnectedListener = onDisconnectedListener;
ConnectyCube.chat.onReconnectListener = onReconnectListener;

function onDisconnectedListener() {}
function onReconnectListener() {}

Dialogs

All chats between users are organized in dialogs. The are 3 types of dialogs:

  • 1-1 chat - a dialog between 2 users.
  • group chat - a dialog between specified list of users.
  • public group chat - an open dialog. Any user from your app can chat there.

You need to create a new dialog and then use it to chat with other users. You also can obtain a list of your existing dialogs.

Create new dialog

Create 1-1 chat

You need to pass type: 3 and an id of an opponent you want to create a chat with:

const params = {
  type: 3,
  occupants_ids: [56]
};

// JS SDK v1
ConnectyCube.chat.dialog.create(params, (error, dialog) => {});

// JS SDK v2
ConnectyCube.chat.dialog
  .create(params)
  .then(dialog => {})
  .catch(error => {});

Create group chat

You need to pass type: 2 and ids of opponents you want to create a chat with:

const params = {
  type: 2,
  occupants_ids: [56, 98, 34],
  name: "Hawaii relax team"
};

// JS SDK v1
ConnectyCube.chat.dialog.create(params, (error, dialog) => {});

// JS SDK v2
ConnectyCube.chat.dialog
  .create(params)
  .then(dialog => {})
  .catch(error => {});

Create public group chat

It's possible to create a public group chat, so any user from you application can join it. There is no a list with occupants, this chat is just open for everybody.

You need to pass type: 1 and ids of opponents you want to create a chat with:

const params = {
  type: 1,
  name: "Blockchain trends"
};

// JS SDK v1
ConnectyCube.chat.dialog.create(params, (error, dialog) => {});

// JS SDK v2
ConnectyCube.chat.dialog
  .create(params)
  .then(dialog => {})
  .catch(error => {});

List dialogs

It's common to request all your dialogs on every app login:

const filters = {};

// JS SDK v1
ConnectyCube.chat.dialog.list(filters, (error, result) => {});

// JS SDK v2
ConnectyCube.chat.dialog
  .list(filters)
  .then(result => {})
  .catch(error => {});

If you want to retrieve only dialogs updated after some specific date time, you can use updated_at[gt] filter. This is useful if you cache dialogs somehow and do not want to obtain the whole list of your dialogs on every app start.

Update dialog

User can update group chat name, photo or add/remove occupants:

const dialogId = "5356c64ab35c12bd3b108a41";
const toUpdateParams = { name: "Tesla club" };

// JS SDK v1
ConnectyCube.chat.dialog.update(
  dialogId,
  toUpdateParams,
  (error, dialog) => {}
);

// JS SDK v2
ConnectyCube.chat.dialog
  .update(dialogId, toUpdateParams)
  .then(dialog => {})
  .catch(error => {});

Add/Remove occupants

To add more occupants use push_all operator. To remove yourself from the dialog use pull_all operator:

const dialogId = "5356c64ab35c12bd3b108a41";
const toUpdateParams = { push_all: { occupants_ids: [97, 789] } };

// JS SDK v1
ConnectyCube.chat.dialog.update(
  dialogId,
  toUpdateParams,
  (error, dialog) => {}
);

// JS SDK v2
ConnectyCube.chat.dialog
  .update(dialogId, toUpdateParams)
  .then(dialog => {})
  .catch(error => {});

Important note: Only group chat owner can remove other users from group chat.

Remove dialog

The following snippet is used to delete a dialog:

const dialogId = "5356c64ab35c12bd3b108a41";
// const dialogIds = ['5356c64ab35c12bd3b108a41', ..., '5356c64ab35c12bd3b108a84']

// JS SDK v1
ConnectyCube.chat.dialog.delete(dialogId, error => {});

// JS SDK v2
ConnectyCube.chat.dialog.delete(dialogId).catch(error => {});

This request will remove this dialog for current user, but other users still will be able to chat there. Only group chat owner can remove the group dialog for all users.

You can also delete multiple dialogs in a single request.

Subscribe to public dialog

In order to be able to chat in public dialog, you need to subscribe to it:

const dialogId = "5356c64ab35c12bd3b108a41";

// JS SDK v1
ConnectyCube.chat.dialog.subscribeToPublic(dialogId, (error, dialog) => {});

// JS SDK v2
ConnectyCube.chat.dialog
  .subscribeToPublic(dialogId)
  .then(dialog => {})
  .catch(error => {});

Unsubscribe from public dialog

const dialogId = "5356c64ab35c12bd3b108a41";

// JS SDK v1
ConnectyCube.chat.dialog.unsubscribeFromPublic(dialogId, error => {});

// JS SDK v2
ConnectyCube.chat.dialog.unsubscribeFromPublic(dialogId).catch(error => {});

Retrieve public dialog occupants

A public chat dialog can have many occupants. There is a separated API to retrieve a list of public dialog occupants:

const dialogId = "5356c64ab35c12bd3b108a41";

// JS SDK v1
ConnectyCube.chat.dialog.getPublicOccupants(dialogId, (error, result) => {
  // result.items
});

// JS SDK v2
ConnectyCube.chat.dialog
  .getPublicOccupants(dialogId)
  .then(result => {
    // result.items
  })
  .catch(error => {});

Add / Remove admins

Options to add or remove admins from the dialog can be done by Super admin (dialog's creator) only. Options are supported in group chat, public or broadcast.

Up to 5 admins can be added to chat.

const dialogId = "5356c64ab35c12bd3b108a41";
const adminsUsersIds = [45, 89];

// JS SDK v1
ConnectyCube.chat.dialog.addAdmins(
  dialogId,
  adminsUsersIds,
  (error, dialog) => {}
);

// JS SDK v2
ConnectyCube.chat.dialog
  .addAdmins(dialogId, adminsUsersIds)
  .then(dialog => {})
  .catch(error => {});
const dialogId = "5356c64ab35c12bd3b108a41";
const adminsUsersIds = [45, 89];

// JS SDK v1
ConnectyCube.chat.dialog.removeAdmins(
  dialogId,
  adminsUsersIds,
  (error, dialog) => {}
);

// JS SDK v2
ConnectyCube.chat.dialog
  .removeAdmins(dialogId, adminsUsersIds)
  .then(dialog => {})
  .catch(error => {});

Update notifications settings

A user can turn on/off push notifications for offline messages in a dialog. By default push notification are turned ON, so offline user receives push notifications for new messages in a chat.

const dialogId = "5356c64ab35c12bd3b108a41";
const enabled = false;

// JS SDK v1
ConnectyCube.chat.dialog.updateNotificationsSettings(
  dialogId,
  enabled,
  (error, result) => {}
);

// JS SDK v2
ConnectyCube.chat.dialog
  .updateNotificationsSettings(dialogId, enabled)
  .then(result => {})
  .catch(error => {});

Get notifications settings

Check a status of notifications setting - either it is ON or OFF for a particular chat.

Available responses: 1 - enabled, 0 - disabled.

const dialogId = "5356c64ab35c12bd3b108a41";

// JS SDK v1
ConnectyCube.chat.dialog.getNotificationsSettings(
  dialogId,
  (error, result) => {}
);

// JS SDK v2
ConnectyCube.chat.dialog
  .getNotificationsSettings(dialogId)
  .then(result => {})
  .catch(error => {});

Chat history

Every chat dialog stores its chat history which you can retrieve:

const dialogId = "5356c64ab35c12bd3b108a41";
const params = {
  chat_dialog_id: dialogId,
  sort_desc: "date_sent",
  limit: 100,
  skip: 0
};

// JS SDK v1
ConnectyCube.chat.message.list(params, (error, messages) => {});

// JS SDK v2
ConnectyCube.chat.message
  .list(params)
  .then(messages => {})
  .catch(error => {});

If you want to retrieve chat messages that were sent after or before specific date time only, you can use date_sent[gt] or date_sent[lt] filter. This is useful if you implement pagination for loading messages in your app.

Send/Receive chat messages

1-1 chat

const dialog = ...;
const opponentId = 78;
const message = {
  type: dialog.type === 3 ? 'chat' : 'groupchat',
  body: "How are you today?",
  extension: {
    save_to_history: 1,
    dialog_id: dialog._id
  },
  markable: 1
};

message.id = ConnectyCube.chat.send(opponentId, message);

// ...

ConnectyCube.chat.onMessageListener = onMessage;

function onMessage(userId, message) {
    console.log('[ConnectyCube.chat.onMessageListener] callback:', userId, message)
}

Group chat

Before you start chatting in a group dialog, you need to join it by calling join function:

const dialog = ...;

// JS SDK v1
ConnectyCube.chat.muc.join(dialog._id, error => {});

// JS SDK v2
ConnectyCube.chat.muc.join(dialog._id).catch(error => {});

Then you are able to send/receive messages:

const message = {
  type: dialog.type === 3 ? "chat" : "groupchat",
  body: "How are you today?",
  extension: {
    save_to_history: 1,
    dialog_id: dialog._id
  },
  markable: 1
};

message.id = ConnectyCube.chat.send(dialog._id, message);

// ...

ConnectyCube.chat.onMessageListener = onMessage;

function onMessage(userId, message) {
  console.log(
    "[ConnectyCube.chat.onMessageListener] callback:",
    userId,
    message
  );
}

When it's done you can leave the group dialog by calling leave function:

// JS SDK v1
ConnectyCube.chat.muc.leave(dialog._id, error => {});

// JS SDK v2
ConnectyCube.chat.muc.leave(dialog._id).catch(error => {});

'Sent' status

There is a 'sent' status to ensure that message is delivered to the server.

In order to use the feature you need to enable it when you pass config in ConnectyCube.init:

chat: {
  streamManagement: {
    enable: true;
  }
}

The following callback is used to track it:

ConnectyCube.chat.onSentMessageCallback = function(messageLost, messageSent) {};

'Delivered' status

The following callback is used to track the 'delivered' status:

ConnectyCube.chat.onDeliveredStatusListener = function(
  messageId,
  dialogId,
  userId
) {
  console.log(
    "[ConnectyCube.chat.onDeliveredStatusListener] callback:",
    messageId,
    dialogId,
    userId
  );
};

The SDK sends the 'delivered' status automatically when the message is received by the recipient. This is controlled by markable: 1 parameter when you send a message. If markable is 0 or omitted, then you can send the delivered status manually:

const params = {
  messageId: "557f1f22bcf86cd784439022",
  userId: 21,
  dialogId: "5356c64ab35c12bd3b108a41"
};

ConnectyCube.chat.sendDeliveredStatus(params);

'Read' status

Send the 'read' status:

const params = {
  messageId: "557f1f22bcf86cd784439022",
  userId: 21,
  dialogId: "5356c64ab35c12bd3b108a41"
};

ConnectyCube.chat.sendReadStatus(params);

// ...

ConnectyCube.chat.onReadStatusListener = function(messageId, dialogId, userId) {
  console.log(
    "[ConnectyCube.chat.onReadStatusListener] callback:",
    messageId,
    dialogId,
    userId
  );
};

'Is typing' status

The following 'typing' notifications are supported:

  • typing: The user is composing a message. The user is actively interacting with a message input interface specific to this chat session (e.g., by typing in the input area of a chat window)
  • stopped: The user had been composing but now has stopped. The user has been composing but has not interacted with the message input interface for a short period of time (e.g., 30 seconds)

Send the 'is typing' status:

const opponentId = 78; // for 1-1 chats
// const dialogJid = ..; // for group chat

ConnectyCube.chat.sendIsTypingStatus(opponentId);
ConnectyCube.chat.sendIsStopTypingStatus(opponentId);

// ...

ConnectyCube.chat.onMessageTypingListener = function(
  isTyping,
  userId,
  dialogId
) {
  console.log(
    "[ConnectyCube.chat.onMessageTypingListener] callback:",
    isTyping,
    userId,
    dialogId
  );
};

Attachments

Chat attachments are supported with the cloud storage API. In order to send a chat attachment you need to upload the file to ConnectyCube cloud storage and obtain a link to the file (file UID). Then you need to include this UID into chat message and send it.

// for example, a file from HTML form input field
const inputFile = $("input[type=file]")[0].files[0];
const fileParams = {
  name: inputFile.name,
  file: inputFile,
  type: inputFile.type,
  size: inputFile.size,
  public: false
};

const prepareMessageWithAttachmentAndSend = file => {
  const message = {
    type: dialog.type === 3 ? "chat" : "groupchat",
    body: "attachment",
    extension: {
      save_to_history: 1,
      dialog_id: dialog._id,
      attachments: [{ uid: result.uid, type: "photo" }]
    }
  };

  // send the message
  // ...
};
// JS SDK v1
ConnectyCube.storage.createAndUpload(fileParams, (error, result) => {
  if (!error) {
    prepareMessageWithAttachmentAndSend(result);
  }
});

// JS SDK v2
ConnectyCube.storage
  .createAndUpload(fileParams)
  .then(prepareMessageWithAttachmentAndSend)
  .catch(error => {});

If you are running Node.js environment, the following code snippet can be used to access a file:

const fs = require("fs");
const imagePath = __dirname + "/dog.jpg";

let fileParams;

fs.stat(imagePath, (error, stats) => {
  fs.readFile(srcIMG, (error, data) => {
    if (error) {
      throw error;
    } else {
      fileParams = {
        file: data,
        name: "image.jpg",
        type: "image/jpeg",
        size: stats.size
      };

      // upload
      // ...
    }
  });
});

The same flow is supported on the receiver's side. When you receive a message, you need to get the file UID and then download the file from the cloud storage.

ConnectyCube.chat.onMessageListener = (userId, message) => {
  if (message.extension.hasOwnProperty("attachments")) {
    if (message.extension.attachments.length > 0) {
      const fileUID = message.extension.attachments[0].uid;
      const fileUrl = ConnectyCube.storage.privateUrl(fileUID);
      const imageHTML = "<img src='" + fileUrl + "' alt='photo'/>";

      // insert the imageHTML as HTML template
    }
  }
};

Update chat message

Update message/messages on a backend for dialog ID:

// const messageIds = ""; // to update all
const messageIds = [
  "55fd42369575c12c2e234c64",
  "55fd42369575c12c2e234c68"
].join(","); // or one - "55fd42369575c12c2e234c64"
const params = {
  read: 1, // mark message as read
  delivered: 1, // mark message as delivered
  message: "some updated text", // update message body
  chat_dialog_id: "5356c64ab35c12bd3b108a41"
};

// JS SDK v1
ConnectyCube.chat.message.update(messageIds, params, (error, result) => {});

// JS SDK v2
ConnectyCube.chat.message
  .update(messageIds, params)
  .then(result => {})
  .catch(error => {});

Mark as read all chat messages

The following snippet is used to mark all messages as read on a backend for dialog ID:

const messageIds = ""; // use "" to update all
const params = {
  read: 1,
  chat_dialog_id: "5356c64ab35c12bd3b108a41"
};

// JS SDK v1
ConnectyCube.chat.message.update(messageIds, params, (error, result) => {});

// JS SDK v2
ConnectyCube.chat.message
  .update("", params)
  .then(result => {})
  .catch(error => {});

Delete chat messages

The following snippet is used to remove chat message/messages:

const messageIds = [
  "55fd42369575c12c2e234c64",
  "55fd42369575c12c2e234c68"
].join(",");
const params = {};

// JS SDK v1
ConnectyCube.chat.message.delete(messageIds, params, (error, result) => {});

// JS SDK v2
ConnectyCube.chat.message
  .delete(messageIds, params)
  .then(result => {})
  .catch(error => {});

This request will remove the messages from current user history only, without affecting the history of other users.

Unread messages count

You can request total unread messages count and unread count for particular dialog:

const params = { dialogs_ids: ["5356c64ab35c12bd3b108a41"] };

// JS SDK v1
ConnectyCube.chat.message.unreadCount(params, (error, result) => {});

// JS SDK v2
ConnectyCube.chat.message
  .unreadCount(params)
  .then(result => {})
  .catch(error => {});

The following API is used to search for messages and chat dialogs:

const params = {
  /* ... */
};

// JS SDK v2
ConnectyCube.chat.search(params, (error, result) => {});

// JS SDK v2
ConnectyCube.chat
  .search(params)
  .then(result => {})
  .catch(error => {});

Please refer to Global search parameters for more info on how to form search params.

Chat alerts

When you send a chat message and the recipient/recipients is offline, then automatic push notification will be fired.

In order to receive push notifications you need to subscribe for it. Please refer to Push Notifications guide.

To configure push template which users receive - go to Dashboard Console, Chat Alerts page

Note that currently push notifications are supported on mobile environment only.

Mark a client as Active/Inactive

When you send a chat message and the recipient/recipients is offline, then automatic push notification will be fired.

Sometimes a client app can be in a background mode, but still online. In this case it's useful to let server know that a user wants to receive push noificattions while still is connected to chat.

For this particular case we have 2 handy methods: 'markInactive' and 'markActive':

ConnectyCube.chat.markInactive();
ConnectyCube.chat.markActive();

The common use case for these APIs is to call 'markInactive' when an app goes to background mode and to call 'markActive' when an app goes to foreground mode.

Contact list

The Contact List API is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B appear in each other's roster.

Access to the Contact list

You can access the contact list on your login to chat - the contact list object will be returned in callback.

Also, the following function gives you an access to contact list:

// JS SDK v1
ConnectyCube.chat.contactlist.get(contactlist => {});

// JS SDK v2
ConnectyCube.chat.contactlist
  .get()
  .then(contactlist => {})
  .catch(error => {});

Add user to your contact list

To add a user to the contact list use the following method:

const userId = 34;

// JS SDK v1
ConnectyCube.chat.contactlist.add(userId, () => {});

// JS SDK v2
ConnectyCube.chat.contactlist.add(userId);

Note

Maximum number of contacts is 300.

Other user will receive a request to be added to the contact list - the onSubscribeListener callback will be called:

ConnectyCube.chat.onSubscribeListener = function(userId) {};

Confirm the contact request

To confirm the request use the following method:

// JS SDK v1
ConnectyCube.chat.contactlist.confirm(userId, () => {});

// JS SDK v2
ConnectyCube.chat.contactlist.confirm(userId);

A user will be informed that you have accepted the contact request by onConfirmSubscribeListener callback:

ConnectyCube.chat.onConfirmSubscribeListener = function(userId) {};

Reject the contact request

To reject the request use the following method:

// JS SDK v1
ConnectyCube.chat.contactlist.reject(userId, () => {});

// JS SDK v2
ConnectyCube.chat.contactlist.reject(userId);

A user will be informed that you have declined the contact request by onRejectSubscribeListener callback:

ConnectyCube.chat.onRejectSubscribeListener = function(userId) {};

Remove user from the contact list

To remove a previously added user from the contact list use the following method:

// JS SDK v1
ConnectyCube.chat.contactlist.remove(userId, () => {});

// JS SDK v2
ConnectyCube.chat.contactlist.remove(userId);

Contact list updates

You can also track contact list updates in real time by using delegates:

ConnectyCube.chat.onContactListListener = function(userId, type) {
  // type - if a user left the chat, type will be 'unavailable'.
  // Otherwise - 'available'.
};

Privacy (black) list

Privacy list API allows enabling or disabling communication with other users in a chat. You can create, modify, or delete privacy lists, define a default list.

The user can have multiple privacy lists, but only one can be active.

Create privacy list

A privacy list must have at least one element in order to be created.

You can choose a type of blocked logic. There are 2 types:

  • Block in one way. When you blocked a user, but you can send messages to him.
  • Block in two ways. When you blocked a user and you also can't send messages to him.
const users = [
  { user_id: 34, action: "deny" },
  { user_id: 48, action: "deny", mutualBlock: true }, // it means you can't write to user
  { user_id: 18, action: "allow" }
];
const list = { name: "myList", items: users };

// JS SDK v1
ConnectyCube.chat.privacylist.create(list, error => {});

// JS SDK v2
ConnectyCube.chat.privacylist.create(list).catch(error => {});

In order to be used the privacy list should be not only set, but also activated(set as default).

Activate privacy list

In order to activate rules from a privacy list you should set it as default:

const listName = "myList";

// JS SDK v1
ConnectyCube.chat.privacylist.setAsDefault(listName, error => {});

// JS SDK v2
ConnectyCube.chat.privacylist.setAsDefault(listName).catch(error => {});

Update privacy list

There is a rule you should follow to update a privacy list:

  • If you want to update or set new privacy list instead of current one, you should decline current default list first.
const listName = "myList";
const list = {
  name: listName,
  items: [{ user_id: 34, action: "allow" }]
};

// JS SDK v1
ConnectyCube.chat.privacylist.setAsDefault(null, error => {
  if (!error) {
    ConnectyCube.chat.privacylist.update(list, error => {
      if (!error) {
        ConnectyCube.chat.privacylist.setAsDefault(listName, error => {});
      }
    });
  }
});

// JS SDK v2
ConnectyCube.chat.privacylist
  .setAsDefault(null)
  .then(() => ConnectyCube.chat.privacylist.update(list))
  .then(() => ConnectyCube.chat.privacylist.setAsDefault(listName))
  .catch(error => {});

Retrieve privacy list names

To get a list of all your privacy lists' names use the following request:

let names;

// JS SDK v1
ConnectyCube.chat.privacylist.getNames((error, response) => {
  if (!error) {
    names = response.names;
  }
});

// JS SDK v2
ConnectyCube.chat.privacylist
  .getNames()
  .then(response => (names = response.names))
  .catch(error => {});

Retrieve privacy list with name

To get the privacy list by name you should use the following method:

const listName = "myList";

let name, items;

// JS SDK v1
ConnectyCube.chat.privacylist.getList("myList", (error, response) => {
  if (!error) {
    name = response.name;
    items = response.items;
  }
});

// JS SDK v2
ConnectyCube.chat.privacylist.getList(listName).then(response => {
  name = response.name;
  items = response.items;
});

Remove privacy list

To delete a list you can call a method below or you can edit a list and set items to nil.

const listName = "myList";

// JS SDK v1
ConnectyCube.chat.privacylist.delete(listName, error => {});

// JS SDK v2
ConnectyCube.chat.privacylist.delete(listName).catch(error => {});

Blocked user attempts to communicate with user

Blocked users will be receiving an error when trying to chat with a user in a 1-1 chat and will be receiving nothing in a group chat:

ConnectyCube.chat.onMessageErrorListener = function(messageId, error) {};

Get last activity

There is a way to get an info when a user was active last time, in seconds.

This is a modern approach for messengers apps, e.g. to display this info on a Contacts screen or on a User Profile screen.

const userId = 123234;

// JS SDK v1
ConnectyCube.chat.getLastUserActivity(userId);

ConnectyCube.chat.onLastUserActivityListener = (userId, seconds) => {
  // 'userId' was 'seconds' ago
};

// JS SDK v2
ConnectyCube.chat
  .getLastUserActivity(userId)
  .then(result => {
    const userId = result.userId;
    const seconds = result.seconds;
    // 'userId' was 'seconds' ago
  })
  .catch(error => {});

Last activity subscription

Listen to user last activity status via subscription.

ConnectyCube.chat.subscribeToUserLastActivityStatus(userId);
ConnectyCube.chat.unsubscribeFromUserLastActivityStatus(userId);

ConnectyCube.chat.onLastUserActivityListener = (userId, seconds) => {};

System messages

In a case you want to send a non text message data, e.g. some meta data about chat, some events or so - there is a system notifications API to do so:

const userId = 123234;

ConnectyCube.chat.sendSystemMessage(userId, msg);

ConnectyCube.chat.onSystemMessageListener = function(msg) {};