Skip to main content

Sending a chat message

As mentioned in introduction, there are 3 types of chat messages - text messages, images, and files. There is a method in meeting.chat to send a message of each type.

Send a text message

To send a text message, the meeting.chat.sendTextMessage() method can be used. This accepts a string message and sends it to the room.

val message = "Is this the real life?"
meeting.chat.sendTextMessage(message)

Send an image

You can send an image with the help of meeting.chat.sendImageMessage() and sends it to the participants in the meeting.

meeting.chat.sendImageMessage(imageUri) { err ->
// Handle error if any
}

Send a file

Sending a file is quite similar to sending an image. The only difference is that when you send an image, a preview will be shown in the meeting chat, which is not the case for sending files. That being said, an image can be sent as a file too using meeting.chat.sendFileMessage().

meeting.chat.sendFileMessage(fileUri) { err ->
// Handle error if any
}

Chat Errors

The sendTextMessage method returns a ChatTextError if the operation fails, null if successful. The error can be the following:

  • PermissionDenied: The user does not have permission to send a message.
  • MessageIsBlank: The message is empty.
  • CharacterLimitExceeded: The message exceeds the character limit. Default limit is 2000 characters.
  • RateLimitBreached: The user has sent too many messages in a short period of time.

Both sendImageMessage and sendFileMessage methods accept a callback function that will be called with a ChatFileError if the operation is not successful, otherwise with null if successful.

Possible ChatFileErrors are:

  • FileFormatNotAllowed: The file format is not allowed.
  • PermissionDenied: The user does not have permission to send a file.
  • RateLimitBreached: The user has breached the rate limit for sending messages.
  • ReadFailed: The file could not be read.
  • UploadFailed: The file could not be uploaded.

A when block can be used to handle these errors inside the callback, as shown below:

when (err) {
is ChatFileError.FileFormatNotAllowed -> {}
is ChatFileError.PermissionDenied -> {}
is ChatFileError.RateLimitBreached -> {}
is ChatFileError.ReadFailed -> {}
is ChatFileError.UploadFailed -> {}
else -> {}
}