import { ChatError } from './ChatError'; import type { ChatMessageReaction } from './ChatMessageReaction'; import type { ChatMessageThread } from './ChatMessageThread'; /** * The conversation types. */ export declare enum ChatMessageChatType { /** * One-to-one chat. */ PeerChat = 0, /** * Group chat. */ GroupChat = 1, /** * Chat room. */ ChatRoom = 2 } /** * The message directions. */ export declare enum ChatMessageDirection { /** * This message is sent from the local client. */ SEND = "send", /** * The message is received by the local client. */ RECEIVE = "rec" } /** * The message sending states. */ export declare enum ChatMessageStatus { /** * The message is created to be sent. */ CREATE = 0, /** * The message is being delivered. */ PROGRESS = 1, /** * The message is successfully delivered. */ SUCCESS = 2, /** * The message fails to be delivered. */ FAIL = 3 } /** * The attachment file download states. */ export declare enum ChatDownloadStatus { /** * The file message download is pending. */ PENDING = -1, /** * The SDK is downloading the file message. */ DOWNLOADING = 0, /** * The SDK successfully downloads the file message. */ SUCCESS = 1, /** * The SDK fails to download the file message. */ FAILED = 2 } /** * The message types. */ export declare enum ChatMessageType { /** * Text message. */ TXT = "txt", /** * Image message. */ IMAGE = "img", /** * Video message. */ VIDEO = "video", /** * Location message. */ LOCATION = "loc", /** * Voice message. */ VOICE = "voice", /** * File message. */ FILE = "file", /** * Command message. */ CMD = "cmd", /** * Custom message. */ CUSTOM = "custom" } /** * Converts the conversation type from int to string. * * @param params The conversation type of the int type. * @returns The conversation type of the string type. */ export declare function ChatMessageChatTypeFromNumber(params: number): ChatMessageChatType; /** * Converts the message direction from string to enum. * * @param params The message direction of the string type. * @returns The message direction of the enum type. */ export declare function ChatMessageDirectionFromString(params: string): ChatMessageDirection; /** * Converts the message status from int to enum. * * @param params The message status of the int type. * @returns The message status of the enum type. */ export declare function ChatMessageStatusFromNumber(params: number): ChatMessageStatus; /** * Converts the message status from enum to string. * * @param params The message status of the enum type. * @returns The message status of the string type. */ export declare function ChatMessageStatusToString(params: ChatMessageStatus): string; /** * Converts the message download status from int to string. * * @param params The message download status of the int type. * @returns The message download status of the string type. */ export declare function ChatDownloadStatusFromNumber(params: number): ChatDownloadStatus; /** * Converts the message download status from int to string. * * @param params The message download status of the int type. * @returns The message download status of the string type. */ export declare function ChatDownloadStatusToString(params: ChatDownloadStatus): string; /** * Converts the message type from string to enum. * * @param params The message type of the string type. * @returns The message type of the enum type. */ export declare function ChatMessageTypeFromString(params: string): ChatMessageType; /** * The message status change listener. */ export interface ChatMessageStatusCallback { /** * Occurs when a message is uploaded or downloaded. * * @param progress The message upload/download progress value. The value range is 0 to 100 in percentage. */ onProgress?(localMsgId: string, progress: number): void; /** * Occurs when a message error occurs. * * @param error A description of the error. See {@link ChatError}. */ onError(localMsgId: string, error: ChatError): void; /** * Occurs when a message is successfully delivered. * * @param message The message that is successfully delivered. */ onSuccess(message: ChatMessage): void; } /** * The message class that defines a message that is to be sent or received. * * For example, construct a text message to send: * * ```typescript * let msg = ChatMessage.createTextMessage( * 'asteriskhx2', * Date.now().toString(), * ChatMessageChatType.PeerChat * ); * ``` */ export declare class ChatMessage { static TAG: string; /** * The message ID generated on the server. */ msgId: string; /** * The local message ID. */ localMsgId: string; /** * The conversation ID. */ conversationId: string; /** * The user ID of the message sender. */ from: string; /** * The user ID of the message recipient: * * - For the one-to-one chat, it is the user ID of the message recipient; * - For the group chat, it is the group ID; * - For the chat room chat, it is the chat room ID; * - For a message thread, it is the ID of the message thread. */ to: string; /** * The Unix timestamp when the message is created locally. The unit is millisecond. */ localTime: number; /** * The Unix timestamp when the server receives the message. The unit is millisecond. */ serverTime: number; /** * Whether the delivery receipt is required, which is to check whether the message is delivered successfully. * * - `true`: Yes. * - (Default) `false`: No. */ hasDeliverAck: boolean; /** * Whether the message read receipt is required. * * - `true`: Yes. * - (Default) `false`: No. */ hasReadAck: boolean; /** * Whether read receipts are required for group messages. * * - `true`: Yes. * - (Default) `false`: No. */ needGroupAck: boolean; /** * The number of members that have read the group message. */ groupAckCount: number; /** * Whether the message is read. * * - `true`: Yes. * - (Default) `false`: No. */ hasRead: boolean; /** * The conversation type. See {@link ChatType}. */ chatType: ChatMessageChatType; /** * The message direction. See {@link ChatMessageDirection} */ direction: ChatMessageDirection; /** * The message sending status. See {@link ChatMessageStatus}. */ status: ChatMessageStatus; /** * The extension attribute of the message. */ attributes: Object; /** * The message body. See {@link ChatMessageBody}. */ body: ChatMessageBody; /** * Whether it is a message in a message thread. * * - `true`: Yes. In this case, you need to set the user ID of the message recipient to the message thread ID. See {@link #to}. * - `false`: No. * * **Note** * This parameter is valid only for group chat. */ isChatThread: boolean; /** * Whether it is a online message. * * - `true`: Yes. In this case, if the application is running in the background, a notification window may pop up. * - `false`: No. */ isOnline: boolean; /** * Constructs a message. */ constructor(params: { msgId?: string; localMsgId?: string; conversationId?: string; from?: string; to?: string; localTime?: number; serverTime?: number; hasDeliverAck?: boolean; hasReadAck?: boolean; needGroupAck?: boolean; groupAckCount?: number; hasRead?: boolean; chatType?: number; direction?: string; status?: number; attributes?: any; body: any; isChatThread?: boolean; isOnline?: boolean; }); private static getBody; private static createSendMessage; /** * Creates a text message for sending. * * @param targetId The user ID of the message recipient. * - For a one-to-one chat, it is the user ID of the peer user. * - For a group chat, it is the group ID. * - For a chat room, it is the chat room ID. * @param content The text content. * @param chatType The conversation type. See {@link ChatType}. * @param opt The extension parameters of the message. * - targetLanguageCodes: The language code. See {@link ChatTextMessageBody#targetLanguageCodes}. * - isChatThread: Whether this message is a threaded message. * - `true`: Yes. * - (Default) `false`: No. * @returns The message instance. */ static createTextMessage(targetId: string, content: string, chatType?: ChatMessageChatType, opt?: { isChatThread?: boolean; targetLanguageCodes?: Array; }): ChatMessage; /** * Creates a message with a file attachment for sending. * * @param targetId The user ID of the message recipient. * - For a one-to-one chat, it is the user ID of the peer user. * - For a group chat, it is the group ID. * - For a chat room, it is the chat room ID. * @param filePath The file path. * @param chatType The conversation type. See {@link ChatType}. * @param opt The extension parameters of the message. * - displayName: The file name. * - isChatThread: Whether this message is a threaded message. * - `true`: Yes. * - (Default) `false`: No. * @returns The message instance. */ static createFileMessage(targetId: string, filePath: string, chatType?: ChatMessageChatType, opt?: { displayName: string; isChatThread?: boolean; }): ChatMessage; /** * Creates an image message for sending. * * @param targetId The user ID of the message recipient. * - For a one-to-one chat, it is the user ID of the peer user. * - For a group chat, it is the group ID. * - For a chat room, it is the chat room ID. * @param filePath The image path. * @param chatType The conversation type. See {@link ChatType}. * @param opt The extension parameters of the message. * - displayName: The image name. * - thumbnailLocalPath: The image thumbnail path. * - sendOriginalImage: Whether to send the original image. * - `true`: Yes. * - (Default) `false`: If the image is equal to or greater than 100 KB, the SDK will compress it before sending the compressed image. * - width: The image width in pixels. * - height: The image height in pixels. * - isChatThread: Whether this message is a threaded message. * - `true`: Yes. * - (Default) `false`: No. * @returns The message instance. */ static createImageMessage(targetId: string, filePath: string, chatType?: ChatMessageChatType, opt?: { displayName: string; thumbnailLocalPath?: string; sendOriginalImage?: boolean; width: number; height: number; isChatThread?: boolean; }): ChatMessage; /** * Creates a video message for sending. * * @param targetId The user ID of the message recipient. * - For a one-to-one chat, it is the user ID of the peer user. * - For a group chat, it is the group ID. * - For a chat room, it is the chat room ID. * @param filePath The path of the video file. * @param chatType The conversation type. See {@link ChatType}. * @param opt The extension parameters of the message. * - displayName: The video file name. * - thumbnailLocalPath: The path of the thumbnail of the first frame of video. * - duration: The video duration in seconds. * - width: The video thumbnail width in pixels. * - height: The video thumbnail height in pixels. * - isChatThread: Whether this message is a threaded message. * - `true`: Yes. * - (Default) `false`: No. * @returns The message instance. */ static createVideoMessage(targetId: string, filePath: string, chatType?: ChatMessageChatType, opt?: { displayName: string; thumbnailLocalPath: string; duration: number; width: number; height: number; isChatThread?: boolean; }): ChatMessage; /** * Creates a voice message for sending. * * @param targetId The user ID of the message recipient. * - For a one-to-one chat, it is the user ID of the peer user. * - For a group chat, it is the group ID. * - For a chat room, it is the chat room ID. * @param filePath The path of the voice file. * @param chatType The conversation type. See {@link ChatType}. * @param opt The extension parameters of the message. * - displayName: The voice file name. * - duration: The voice duration in seconds. * - isChatThread: Whether this message is a threaded message. * - `true`: Yes. * - (Default) `false`: No. * @returns The message instance. */ static createVoiceMessage(targetId: string, filePath: string, chatType?: ChatMessageChatType, opt?: { displayName: string; duration: number; isChatThread?: boolean; }): ChatMessage; /** * Creates a location message for sending. * * @param targetId The user ID of the message recipient. * - For a one-to-one chat, it is the user ID of the peer user. * - For a group chat, it is the group ID. * - For a chat room, it is the chat room ID. * @param latitude The latitude. * @param longitude The longitude. * @param chatType The conversation type. See {@link ChatType}. * @param opt The extension parameters of the message. * - address: The location details. * - isChatThread: Whether this message is a threaded message. * - `true`: Yes. * - (Default) `false`: No. * @returns The message instance. */ static createLocationMessage(targetId: string, latitude: string, longitude: string, chatType?: ChatMessageChatType, opt?: { address: string; isChatThread?: boolean; }): ChatMessage; /** * Creates a command message for sending. * * @param targetId The user ID of the message recipient. * - For a one-to-one chat, it is the user ID of the peer user. * - For a group chat, it is the group ID. * - For a chat room, it is the chat room ID. * @param action The command action. * @param chatType The conversation type. See {@link ChatType}. * @param opt The extension parameters of the message. * - isChatThread: Whether this message is a threaded message. * - `true`: Yes. * - (Default) `false`: No. * - deliverOnlineOnly: Whether this command message is delivered only to the online users. * - (Default) `true`: Yes. * - `false`: No. The command message is delivered to users, regardless of their online or offline status. * @returns The message instance. */ static createCmdMessage(targetId: string, action: string, chatType?: ChatMessageChatType, opt?: { isChatThread?: boolean; deliverOnlineOnly?: boolean; }): ChatMessage; /** * Creates a custom message for sending. * * @param targetId The user ID of the message recipient. * - For a one-to-one chat, it is the user ID of the peer user. * - For a group chat, it is the group ID. * - For a chat room, it is the chat room ID. * @param event The custom event. * @param chatType The conversation type. See {@link ChatType}. * @param opt The extension parameters of the message. * - params: The dictionary of custom parameters. * - isChatThread: Whether this message is a threaded message. * - `true`: Yes. * - (Default) `false`: No. * @returns The message instance. */ static createCustomMessage(targetId: string, event: string, chatType?: ChatMessageChatType, opt?: { params: any; isChatThread?: boolean; }): ChatMessage; /** * Creates a received message instance. * * @param params The received message. * @returns The message object. */ static createReceiveMessage(params: any): ChatMessage; /** * Gets the list of Reactions. */ get reactionList(): Promise>; /** * Gets the count of read receipts of a group message. */ get groupReadCount(): Promise; /** * Gets details of a message thread. */ get threadInfo(): Promise; } /** * The message body base class. */ export declare class ChatMessageBody { /** * The message type. See {@link ChatMessageType}. */ type: ChatMessageType; constructor(type: string); } /** * The text message body class. */ export declare class ChatTextMessageBody extends ChatMessageBody { /** * The text message content. */ content: string; /** * The target language for translation. See {@link https://docs.microsoft.com/en-us/azure/cognitive-services/translator/language-support}. */ targetLanguageCodes?: Array; /** * The translation. * * It is a KV object, where the key is the target language and the value is the translation. */ translations?: any; constructor(params: { type: string; content: string; targetLanguageCodes?: Array; translations?: any; }); } /** * The location message body class. */ export declare class ChatLocationMessageBody extends ChatMessageBody { /** * The address. */ address: string; /** * The latitude. */ latitude: string; /** * The longitude. */ longitude: string; constructor(params: { type: string; address: string; latitude: string; longitude: string; }); } /** * The file message body class. */ export declare class ChatFileMessageBody extends ChatMessageBody { /** * The local path of the file. */ localPath: string; /** * The token to download the file attachment. */ secret: string; /** * The path of the attachment file in the server. */ remotePath: string; /** * The download status of the attachment file. See {@link ChatDownloadStatus}. */ fileStatus: ChatDownloadStatus; /** * The size of the file in bytes. */ fileSize: number; /** * The file name. */ displayName: string; constructor(params: { type: string; localPath: string; secret?: string; remotePath?: string; fileStatus?: number; fileSize?: number; displayName: string; }); } /** * The image message body class. */ export declare class ChatImageMessageBody extends ChatFileMessageBody { /** Whether to send the original image. * - `true`: Yes. * - (Default) `false`: No. If the image is smaller than 100 KB, the SDK sends the original image. If the image is equal to or greater than 100 KB, the SDK will compress it before sending the compressed image. */ sendOriginalImage: boolean; /** * The local path or the URI of the thumbnail as a string. */ thumbnailLocalPath: string; /** * The URL of the thumbnail on the server. */ thumbnailRemotePath: string; /** * The secret to access the thumbnail. A secret is required for verification for thumbnail download. */ thumbnailSecret: string; /** * The download status of the thumbnail. See {@link ChatDownloadStatus} */ thumbnailStatus: ChatDownloadStatus; /** * The image width in pixels. */ width: number; /** * The image height in pixels. */ height: number; constructor(params: { type: string; localPath: string; secret?: string; remotePath?: string; fileStatus?: number; fileSize?: number; displayName: string; sendOriginalImage?: boolean; thumbnailLocalPath?: string; thumbnailRemotePath?: string; thumbnailSecret?: string; thumbnailStatus?: number; width?: number; height?: number; }); } /** * The video message body class. */ export declare class ChatVideoMessageBody extends ChatFileMessageBody { /** * The video duration in seconds. */ duration: number; /** * The local path of the video thumbnail. */ thumbnailLocalPath: string; /** * The URL of the thumbnail on the server. */ thumbnailRemotePath: string; /** * The secret to download the video thumbnail. */ thumbnailSecret: string; /** * The download status of the video thumbnail. See {@link ChatDownloadStatus} */ thumbnailStatus: ChatDownloadStatus; /** * The video width in pixels. */ width: number; /** * The video height in pixels. */ height: number; constructor(params: { type: string; localPath: string; secret?: string; remotePath?: string; fileStatus?: number; fileSize?: number; displayName: string; duration?: number; thumbnailLocalPath?: string; thumbnailRemotePath?: string; thumbnailSecret?: string; thumbnailStatus?: ChatDownloadStatus; width?: number; height?: number; }); } /** * The voice message body. */ export declare class ChatVoiceMessageBody extends ChatFileMessageBody { /** * The voice duration in seconds. */ duration: number; constructor(params: { type: string; localPath: string; secret?: string; remotePath?: string; fileStatus?: number; fileSize?: number; displayName: string; duration?: number; }); } /** * The command message body. */ export declare class ChatCmdMessageBody extends ChatMessageBody { /** * The command action. */ action: string; /** * Whether this command message is delivered only to online users. * - (Default)`false`: The command message is delivered to users, regardless of their online or offline status. * - `true`: The message is delivered to the online users only, so the offline users won't receive the message when they log in later. */ deliverOnlineOnly: boolean; constructor(params: { action: string; deliverOnlineOnly?: boolean; }); } /** * The custom message body. */ export declare class ChatCustomMessageBody extends ChatMessageBody { /** * The event. */ event: string; /** * The custom params map. */ params: any; constructor(params: { event: string; params?: any; }); }