Use in-meeting chat
The code on this page works with either the default UI or the custom UI.
The Meeting SDK lets you use in-meeting chat to communicate with other participants in the same meeting.
Handle chat functionality through the InMeetingChatController interface.
ZoomSDK.getInstance().inMeetingService.inMeetingChatController
InMeetingChatController chatController = ZoomSDK.getInstance().getInMeetingService().getInMeetingChatController();
Control chat settings
Before you use in-meeting chat, check if the current meeting or webinar supports chat, and then look at which participants or attendees can use chat.
Chat settings in a meeting
In a meeting, use meetingAttendeeChatPrivilege.
if (!chatController.isChatDisabled) {
val chatPrivilege = chatController.meetingAttendeeChatPrivilege
}
if (!chatController.isChatDisabled()) {
InMeetingChatController.MobileRTCMeetingChatPriviledge chatPriviledge = chatController.getMeetingAttendeeChatPrivilege();
}
The meetingAttendeeChatPrivilege uses one of these values.
No_One- No participants may use chat.Host_Only- Only the host of the meeting may use chat.Everyone_Publicly- All participants may use chat, but private messages are not allowed.Everyone_Publicly_And_Privately- All participants may use chat to send both private and public messages.Invalid- Meeting chat privilege is not applicable to the current meeting.
If the current user is the meeting's host, they can control chat settings by specifying a MobileRTCMeetingChatPriviledge.
chatController.changeAttendeeChatPriviledge(InMeetingChatController.MobileRTCMeetingChatPriviledge.Everyone_Publicly_And_Privately)
chatController.changeAttendeeChatPriviledge(InMeetingChatController.MobileRTCMeetingChatPriviledge.No_One)
chatController.changeAttendeeChatPriviledge(InMeetingChatController.MobileRTCMeetingChatPriviledge.Everyone_Publicly_And_Privately);
chatController.changeAttendeeChatPriviledge(InMeetingChatController.MobileRTCMeetingChatPriviledge.No_One);
Chat settings in a webinar
In a webinar, use webinarAttendeeChatPrivilege.
val chatPrivilege = chatController.webinarAttendeeChatPrivilege
InMeetingChatController.MobileRTCWebinarChatPriviledge chatPriviledge = chatController.getWebinarAttendeeChatPrivilege();
The webinarAttendeeChatPrivilege uses one of these values.
No_One- No attendees may use chat.All_Panelists- Only panelists may use chat.All_Panelists_And_Attendees- All panelists and attendees may use chat.Invalid- Webinar chat privilege is not applicable to the current webinar.
Update a webinar's chat settings by setting a MobileRTCWebinarPanelistChatPrivilege.
chatController.panelistChatPrivilege = InMeetingChatController.MobileRTCWebinarPanelistChatPrivilege.ChatPrivilege_All
chatController.panelistChatPrivilege = InMeetingChatController.MobileRTCWebinarPanelistChatPrivilege.ChatPrivilege_AllPanelist
chatController.setPanelistChatPrivilege(InMeetingChatController.MobileRTCWebinarPanelistChatPrivilege.ChatPrivilege_All);
chatController.setPanelistChatPrivilege(InMeetingChatController.MobileRTCWebinarPanelistChatPrivilege.ChatPrivilege_AllPanelist);
Send messages
To send a public message in either a meeting or a webinar, instantiate a ChatMessageBuilder and set the content and message type.
val chatMessage = ChatMessageBuilder()
.setContent("This is a sample message.")
.setMessageType(ZoomSDKChatMessageType.ZoomSDKChatMessageType_To_All)
.build()
chatController.sendChatMsgTo(chatMessage)
InMeetingChatMessage chatMessage = new ChatMessageBuilder()
.setContent("This is a sample message")
.setMessageType(ZoomSDKChatMessageType.ZoomSDKChatMessageType_To_All)
.build();
chatController.sendChatMsgTo(chatMessage);
For private messages, change the message type to ZoomSDKChatMessageType_To_Individual and include a receiver ID to specify the message recipient.
val privateMessage = ChatMessageBuilder()
.setMessageType(ZoomSDKChatMessageType.ZoomSDKChatMessageType_To_Individual)
.setContent("This is a sample private message")
.setReceiver(userId)
.build()
chatController.sendChatMsgTo(privateMessage)
InMeetingChatMessage privateMessage = new ChatMessageBuilder()
.setMessageType(ZoomSDKChatMessageType.ZoomSDKChatMessageType_To_Individual)
.setContent("This is a sample private message")
.setReceiver(userId)
.build();
chatController.sendChatMsgTo(privateMessage);
To reply to an existing message in a thread, first get a threadId for the message being responded to. For more information on how to get the threadId, see Receive messages. Once you've retrieved the thread ID, pass it in and set the type based on whether the parent message is public or private.
val threadId = msg?.threadId
val threadReplyMessage = ChatMessageBuilder()
.setMessageType(ZoomSDKChatMessageType.ZoomSDKChatMessageType_To_All)
.setThreadId(threadId)
.setContent("This is a sample message reply to a thread.")
.build()
chatController.sendChatMsgTo(threadReplyMessage)
InMeetingChatMessage threadReplyMessage = new ChatMessageBuilder()
.setMessageType(ZoomSDKChatMessageType.ZoomSDKChatMessageType_To_All)
.setThreadId(threadId)
.setContent("This is a sample message reply to a thread.")
.build();
chatController.sendChatMsgTo(threadReplyMessage);
Messages sent from the SDK can also include quoted text. The quote position specifies the start and end characters in the quoted text string.
val quotedMessage = ChatMessageBuilder()
.setMessageType(ZoomSDKChatMessageType.ZoomSDKChatMessageType_To_All)
.setQuotePosition(0, 42)
.setContent("This is a sample message stylized as a quote")
.build()
chatController.sendChatMsgTo(quotedMessage)
InMeetingChatMessage quotedMessage = new ChatMessageBuilder()
.setMessageType(ZoomSDKChatMessageType.ZoomSDKChatMessageType_To_All)
.setQuotePosition(0, 42)
.setContent("This is a sample message stylized as a quote")
.build();
chatController.sendChatMsgTo(quotedMessage);
Receive messages
To display content from chat messages, the SDK provides a callback to get notified of when a new message is sent to the meeting. You can also use this callback to confirm that a message sent by the current user has successfully been posted to the meeting chat.
Use the msg parameter within InMeetingChatListener#onChatMesageReceived to get information about the chat message. Some data, like receiverUserId, will only be available for specific types of messages.
val messageListener = object : InMeetingListener() {
...
override fun onChatMessageReceived(msg: InMeetingChatMessage?) {
msg?.content // The content of the message that is visible to users in the meeting.
msg?.chatMessageType // The message type (See "Send Messages").
msg?.isChatToAll // Whether the chat message is public.
msg?.msgId // A unique identifier assigned to this message.
msg?.isChatToWaitingroom // Whether the message was sent to the waiting room.
msg?.isChatToAllPanelist // Whether the chat message was sent to the webinar panelists.
msg?.isComment // Whether the chat message is a comment responding to a thread.
msg?.isThread // Whether the chat message is a thread with comments.
msg?.receiverDisplayName // The display name of the user on the receiving end of a private message.
msg?.receiverUserId // The Zoom user ID of the user on the receiving end of a private message.
msg?.senderDisplayName // The display name of the user who sent the message.
msg?.senderUserId // The Zoom user ID of the user who sent the message.
msg?.threadId // The unique identifier associated with a thread
msg?.time // The time at which the message was sent.
}
}
ZoomSDK.getInstance().inMeetingService.addListener(messageListener)
@Override
public void onChatMessageReceived(@Nullable InMeetingChatMessage msg) {
if (msg != null) {
msg.getContent();
msg.getChatMessageType();
msg.isChatToAll();
msg.getMsgId();
msg.isChatToWaitingroom();
msg.isChatToAllPanelist();
msg.isComment();
msg.isThread();
msg.getReceiverDisplayName();
msg.getReceiverUserId();
msg.getSenderDisplayName();
msg.getSenderUserId();
msg.getThreadId();
msg.getTime();
}
}
Delete messages
To delete a message sent by the current user, use the msgId.
chatController.deleteChatMessage(messageId)
chatController.deleteChatMessage(messageId);
Parse text format
The SDK supports receiving various styles of chat messages. The styles are included as a list of IRichTextStyleItem objects. These items contain two components: a RichTextStyle enum indicating the type of style, and a list of IRichTextStyleOffsets describing ranges including each style.
val styles = msg?.textStyleItemList
styles?.forEach {
val styleType = it.textStyle
it.textStyleOffsetList.forEach {offset ->
offset.positionStart
offset.positionEnd
}
}
List<IRichTextStyleItem> styles = msg.getTextStyleItemList();
for (IRichTextStyleItem style : styles) {
for (IRichTextStyleOffset offset : style.getTextStyleOffsetList()) {
offset.getPositionStart();
offset.getPositionEnd();
}
}