Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Version 4

Receive messages in a group channel

Copy link

Messages sent from other members can be received through the onMessageReceived() method in the channel event handler. A BaseMessage object for each received message is one of the following three message types.

Message typeClassDescription



A text message sent by a user



A binary file message sent by a user



A text message sent by an admin through the Chat API

To register multiple concurrent handlers, pass a UNIQUE_HANDLER_ID argument as a unique identifier into the addGroupChannelHandler() method.

const channelHandler = new GroupChannelHandler({
    onMessageReceived: (channel: BaseChannel, message: BaseMessage) => {
        // ...

sb.groupChannel.addGroupChannelHandler(UNIQUE_HANDLER_ID, channelHandler);

When the UI isn't valid anymore, remove the channel event handler.


Receive replies in a message thread

Copy link

Once a reply is created or deleted from a thread, onThreadInfoUpdated() in GroupChannelHandler is invoked. The method returns a ThreadInfoUpdateEvent object that has the latest information about the thread. This object needs to be applied to the parent message object.

handler.onThreadInfoUpdated = (channel: BaseChannel, threadInfoUpdateEvent: ThreadInfoUpdateEvent) => {
    // Look for a message that has threadInfoUpdateEvent.targetMessageId.
    // Apply the event to the message.

List of parameters

Copy link
Parameter nameTypeDescription



Specifies the channel that has the message thread.



Specifies a ThreadInfoUpdateEvent object that has the latest information about the thread.

If a reply message is created, onMessageReceived() is also called with that reply message. A user will have to find the parent message with the parentMessageID property in that message object.

If the parent message is not in the message view stack and the user wants to get the parent message object, they can do so by calling sb.message.getMessage(params, handler) to retrieve the parent message object.

Once the reply message has been created, the onThreadInfoUpdated() event handler will be called since the thread info has been changed. To update thread information, the user should find the matching parent message with targetMessageID and use the parentMessage.applyThreadInfoUpdateEvent() method.

Receive callbacks for delivery receipts

Copy link

When a message is delivered to an online group channel member, it is automatically marked as delivered and the other online members are notified of delivery receipt through the onUndeliveredMemberStatusUpdated() method in the channel event handler. However, when it is delivered to an offline group channel member as a push notification, the message can be marked as delivered through the groupChannel.markAsDelivered(), and other online members are notified of the delivery receipt through the onUndeliveredMemberStatusUpdated().

const channelHandler = new GroupChannelHandler();
channelHandler.onUndeliveredMemberStatusUpdated = (channel: GroupChannel) => {
    // Message delivery status changed.

sb.groupChannel.addGroupChannelHandler(UNIQUE_HANDLER_ID, channelHandler);