ConnectyCube Chat 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.
Connect to chat
Use connectionStateStream to listen different connection states:
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:
Disconnect
To fully destroy chat connection use cubeChatConnection.destroy:
Reconnection
The SDK will try to reconnect to the chat after lost connection.
To configure internal reconnection manager use next code snippet:
Additional to the internal reconnection manager or instead of it you can use your own reconnection manager.
For it you can use for example connectivity library from pub.dev repo.
You can use code snippet below to listen internet connection state and start relogin to the chat when internet connection will be established:
Additionaly you can try reconnect to the chat immediately after lost chat connection, for it use:
Dialogs
All chats between users are organized in dialogs.
The are 4 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.
broadcast - chat where a message is sent to all users within application at once.
All the users from the application are able to join this group. Broadcast dialogs can be created only via Admin panel.
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 = CubeDialogType.PRIVATE and an id of an opponent you want to create a chat with:
Create group chat
You need to pass type = CubeDialogType.GROUP and ids of opponents you want to create a chat with:
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 = CubeDialogType.PUBLIC and ids of opponents you want to create a chat with:
List dialogs
It’s common to request all your dialogs on every app login:
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:
!> Important note: Only group chat owner or admins can remove other users from group chat.
Remove dialog
The following snippet is used to delete a dialog:
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:
Unsubscribe from public dialog
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:
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.
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.
Get notifications settings
Check a status of notifications setting - either it is ON or OFF for a particular chat.
Available responses: true - enabled, false - disabled.
Chat history
Every chat dialog stores its chat history which you can retrieve:
If you want to retrieve chat messages that were sent after or before specific date time only, you can use "date_sent", QueryRule.GT or "date_sent", QueryRule.LT filter.
This is useful if you implement pagination for loading messages in your app.
Send/Receive chat messages
’Sent’ status
(coming soon)
‘Delivered’ status
The following callback is used to track the ‘delivered’ status:
The SDK sends the ‘delivered’ status automatically when the message is received by the recipient.
This is controlled by markable = true parameter when you send a message. If markable is false or omitted,
then you can send the delivered status manually:
‘Read’ status
Send the ‘read’ status:
‘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 screen)
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:
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.
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.
Update chat message
Via HTTP API
Update message/messages on a backend for dialog ID:
Via Chat connection
Use the following code snippet to edit a message (correct message body).
Other user(s) will receive the ‘edit’ message info to the listener:
Mark as read all chat messages
The following snippet is used to mark all messages as read on a backend for dialog ID:
Message reactions
Add/Remove reactions
User can add/remove message reactions and listen message reaction events
Add
Remove
Add/Remove
Listen reactions
List message reactions
User can list message reactions
Response example from getMessageReactions(messageId) - see
Delete chat messages
Via HTTP API
The following snippet is used to remove chat message/messages:
This request will remove the messages from current user history only, without affecting the history of other users.
Via Chat connection
Use the following code snippet to delete a message.
Other user(s) will receive the ‘delete’ message info to the listener:
Unread messages count
You can request total unread messages count and unread count for particular dialog:
Global search
The following API is used to search for messages and chat dialogs:
Also, here is a way to avoid automatically sending push notifications to offline recipient/recipients. For it add the silent parameter with value 1 to the properties field of the instance of a CubeMessage.
After sending such a message, the server won’t create the push notification for offline recipient/recipients.
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 notifications while still is connected to chat.
For this particular case we have 2 handy methods: markInactive and 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
(coming soon)
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.
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:
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.
Retrieve privacy list names
To get a list of all your privacy lists’ names use the following request:
Retrieve privacy list with name
To get the privacy list by name you should use the following method:
Remove privacy list
To delete a list you can call a method below:
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:
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.
Last activity subscription
Listen to user last activity status via subscription.
Use the code below to subscribe for the last activity events. You can leave the callback at null if you don’t want to listen to evens for the specific user.
Use the code below to unsubscribe from the last activity events.
Use the listener below if you want to listen to events from all users you subscribed to:
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: