# Chat Chat is is designed to support in-session text communication. Zoom truncates messages exceeding a binary size of 10,000 bytes. As a best practice, we recommend a limit of 1000 characters per message. While in a session, users can send chat messages to each other. The following two main components within the SDK will help you implement in-session messaging features: - An instance of `ZMVideoSDKChatHelper` provides methods that can be used to send and receive messages in a session running on your app. - The `onChatNewMessageNotify` callback from your `ZMVideoSDKDelegate` confirms the delivery of a message. ## Send chat messages Users can send a message privately to a single user or publicly to the entire session. ### Send a private chat message ```swift // Get the ZMVideoSDKChatHelper to perform chat actions. if let chatHelper = ZMVideoSDK.shared()?.getChatHelper() { // Check if chat is enabled in this session. if chatHelper.isChatDisabled() == false, chatHelper.isPrivateChatDisabled() == false { // Send message to User. chatHelper.sendChat(to: user, content: message) } } ``` ```objectivec // Get the ZMVideoSDKChatHelper to perform chat actions. ZMVideoSDKChatHelper *chatHelper = [[ZMVideoSDK sharedZMVideoSDK] getChatHelper]; // Check if chat is enabled in this session. if ([chatHelper IsChatDisabled] == NO && [chatHelper IsPrivateChatDisabled] == NO) { // Send message to User. [chatHelper SendChatToUser:user Content:message]; } ``` ### Send a public chat message to all users in a session ```swift // Get the ZMVideoSDKChatHelper to perform chat actions. if let chatHelper = ZMVideoSDK.shared()?.getChatHelper() { // Check if chat is enabled in this session. if chatHelper.isChatDisabled() == false{ // Send message to all users in this session. chatHelper.sendChat(toAll: message) } } ``` ```objectivec // Get the ZMVideoSDKChatHelper to perform chat actions. ZMVideoSDKChatHelper *chatHelper = [[ZMVideoSDK sharedZMVideoSDK] getChatHelper]; // Check if chat is enabled in this session. if ([chatHelper IsChatDisabled] == NO) { // Send message to all users in this session. [chatHelper SendChatToAll:message]; } ``` ## Receive chat messages To be notified when a message is received use `onChatNewMessageNotify` within `ZMVideoSDKDelegate`. The parameter `chatMessage` contains information about the message including an `ZMVideoSDKUser` info object for both the sender and recipient (if applicable). ```swift func onChatNewMessageNotify(_ helper: ZMVideoSDKChatHelper!, message chatMessage: ZMVideoSDKChatMessage!) { // Use helper to perform chat actions. // Message contains the info about a chat message. if let content = chatMessage.content, let senderName = chatMessage.sendUser.getName() { print("\(senderName) sent a message: \(content)") } } ``` ```objectivec - (void)onChatNewMessageNotify:(ZMVideoSDKChatHelper *)helper message:(ZMVideoSDKChatMessage *)chatMessage { // Use helper to perform chat actions. // Message contains the info about a chat message. NSString *content = chatMessage.content; VideoSDKUser *sender = chatMessage.sendUser; NSLog(@"%@ sent a message: %@", [sender getName], content); } ``` For more information on how to use the `ZMVideoSDKUser` object, see [Sessions](/docs/video-sdk/macos/sessions/). ## Chat message details Here are some additional considerations to make note of while using `ZMVideoSDKChatMessage`: ```swift let isChatToAll = chatMessage.isChatToAll // Returns false for private messages. let currentUserIsSender = chatMessage.isSelfSend // Returns true if the current user sent the message. let timeMessageWasSent = chatMessage.timeStamp // The time at which the message was sent. let recipient = chatMessage.receiverUser // The recipient of a private message. ``` ```objectivec chatMessage.isChatToAll; // Returns false for private messages. chatMessage.isSelfSend; // Returns true if the current user sent the message. chatMessage.timeStamp; // The time at which the message was sent. chatMessage.receiverUser; // The recipient of a private message. ``` ## Callbacks The following is an example of a chat callback. ### Get notified when a message is delivered ```swift func onChatNewMessageNotify(_ chatHelper: ZMVideoSDKChatHelper!, chatMessage: ZMVideoSDKChatMessage!) { // Use helper to perform chat actions. // Message contains the info about a chat message. if let content = chatMessage.content, let senderName = chatMessage.sendUser.getName() { print("\(senderName) sent a message: \(content)") } } ``` ```objectivec - (void)onChatNewMessageNotify:(ZMVideoSDKChatHelper*)chatHelper chatMessage:(ZMVideoSDKChatMessage*)chatMessage { // Use helper to perform chat actions. // Message contains the info about a chat message. NSString *content = chatMessage.content; ZMVideoSDKUser *sender = [chatMessage getSendUser]; NSLog(@"%@ sent a message: %@", sender.getUserName, content); } ``` ## Send files in chat Users can transfer files in chat during the session. > Zoom deletes files sent via in-session chat when the session ends. Enable [send files via in-session chat](/docs/build/account/#in-session-advanced) in your Video SDK account portal settings and configure the following settings. - **Only allow specified file types** - Select to allow only specific file types and enter the file extensions in the text box, separated by commas. - **Maximum file size** - Select to limit the file size to 2048 MB. Check if the file transfer feature is enabled. ```swift let ret = ZMVideoSDK.shared().getSessionInfo().isFileTransferEnabled() ``` ```objectivec BOOL ret = [[[ZMVideoSDK sharedVideoSDK] getSessionInfo] isFileTransferEnabled]; ``` Get the list of allowed file types that you can transfer. ```swift let ret = ZMVideoSDK.shared().getSessionInfo().getTransferFileTypeWhiteList() ``` ```objectivec NSString *ret = [[[ZMVideoSDK sharedVideoSDK] getSessionInfo] getTransferFileTypeWhiteList]; ``` Get the maximum file size to transfer. ```swift let ret = ZMVideoSDK.shared().getSessionInfo().getMaxTransferFileSize() ``` ```objectivec unsigned long long ret = [[[ZMVideoSDK sharedVideoSDK] getSessionInfo] getMaxTransferFileSize]; ``` Send files to all users in the current session. ```swift let ret = ZMVideoSDK.shared().getSessionInfo().transferFile(filePath: String) ``` ```objectivec ZMVideoSDKErrors ret = [[[ZMVideoSDK sharedVideoSDK] getSessionInfo] transferFile:self.filePathTextF.stringValue]; ``` Send files to a certain user in the session. ```swift // Locate the user that you will like to send the file to let receiver: ZMVideoSDKUser // Send file directly let ret = receiver.transferFile(filePath: String) ``` ```objectivec ZMVideoSDKErrors ret = [_receiverUser transferFile:self.filePathTextF.stringValue]; ``` Cancel sending files. ```swift // getCurrentSendFileObj is a user-defined method, to retrieve the sending file. let sendFile: ZMVideoSDKSendFile = getCurrentSendFileObj() let ret = sendFile.cancelSend() ``` ```objectivec ZMVideoSDKSendFile *send = [self getCurrentSendFileObj]; // getCurrentSendFileObj is a user-defined method, to retrieve the sending file. ZMVideoSDKErrors ret = [send cancelSend]; ``` Start receiving files. ```swift // getCurrentReceiveFileObj is a user-defined method, to retrieve the receiving file. let receiveFile: ZMVideoSDKReceiveFile = getCurrentReceiveFileObj() let fileDomain = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).map(\.path).last let filePath = "" let downloadFilePath = "\(fileDomain)/\(filePath.count > 0 ? filePath : receiveFile.fileName)" if (receiveFile) { let ret = receiveFile.startReceive(downloadFilePath) } ``` ```objectivec ZMVideoSDKReceiveFile *receive = [self getCurrentReceiveFileObj]; //getCurrentReceiveFileObj is a user-defined method, to retrieve the receiving file. NSString *fileDomain = [NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES).lastObject copy]; NSString *filePath = @""; NSString *downloadFilePath = [NSString stringWithFormat:@"%@/%@",fileDomain,filePath.length>0?filePath:receive.fileName]; if (receive) { ZMVideoSDKErrors ret = [receive startReceive:downloadFilePath]; } else { NSLog(@"receive is null"); } ``` Cancel receiving files. ```swift // getCurrentReceiveFileObj is a user-defined method, to retrieve the receiving file. let receiveFile: ZMVideoSDKReceiveFile = getCurrentReceiveFileObj() let downloadPath = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).map(\.path).last if (receiveFile) { let ret = receiveFile.cancelReceive() } ``` ```objectivec ZMVideoSDKReceiveFile *receive = [self getCurrentReceiveFileObj]; // getCurrentReceiveFileObj is a user-defined method, to retrieve the receiving file. if (receive) { ZMVideoSDKErrors ret = [receive cancelReceive]; } else { NSLog(@"receive is null"); } ``` ### File transfer callbacks Be sure that you have [set up a delegate for callback events](/docs/video-sdk/macos/integrate/#implement-a-delegate) to receive file transfer callbacks. Get notified when you transfer a file. ```swift func onSendFile(_ sendFile: ZMVideoSDKSendFile!, status: ZMVideoSDKFileTransferStatus) { // Get the transfer status of the file and the file content here. } ``` ```objectivec - (void)onSendFile:(ZMVideoSDKSendFile *)sendFile status:(ZMVideoSDKFileTransferStatus)status { // Get the transfer status of the file and the file content here. } ``` Get notified when you receive a file from other users. ```swift func onReceiveFile(_ receiveFile: ZMVideoSDKReceiveFile!, status: ZMVideoSDKFileTransferStatus) { // Get the transfer status of the file and the file content here. } ``` ```objectivec -(void)onReceiveFile:(ZMVideoSDKReceiveFile *)receiveFile status:(ZMVideoSDKFileTransferStatus)status { // Get the transfer status of the file and the file content here. } ```