Receive messages in a group channel
Messages sent by other group channel members can be received through the onMessagesAdded()
method in message collection handler.
Message type
Each BaseMessage
object received in a group channel falls into one of the following three message types.
Message type | Class | Description |
---|---|---|
Text | A text message sent by a user. | |
File | A binary file message sent by a user. | |
File | A message with multiple files sent by a user. | |
Admin | A text message sent by an admin through the Chat API |
File message and multiple files message
When receiving a message payload with file data, the SDK can distinguish FileMessage
and MultipleFilesMessages
based on the number of files included in files
. If the message contains more than two files, the SDK acknowledges it as a multipleFilesMessage
. If the number of files contained in a messages exceeds the limit, which is 30, the message fails and returns an error of 800110
. If any of the files exceeds the file size limit, it returns 800260
.
Event handler
When a new message arrives in a group channel, onMessageAdded()
and onChannelUpdated()
in the message collection are called.
Whenever an event related to message or group channel occurs, the collection is informed of the event through MessageContext
and GroupChannelContext
, respectively. The MessageContext
and GroupChannelContext
instances have CollectionEventSource
, which contains the information of the event that took place. For example, when a new message is received, EVENT_MESSAGE_RECEIVED
is passed as the MessageContext.CollectionEventSource
value to onMessagesAdded()
. Meanwhile, when a message is delivered to group channel members who are online, the message's delivery status is automatically marked as delivered. The value for GroupChannelContext.CollectionEventSource
is set to EVENT_DELIVERY_STATUS_UPDATED
and channel members are notified of the event through onChannelUpdated()
. To learn more about this topic, see the Message events section in the Message collection page.
You can also register other message-related event handlers using the MessageCollection
object.
When the message UI is no longer needed, call dispose()
. Note that the handlers don't work when the message collection is disposed.