import type { ChatError } from './ChatError'; /** * 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 status. */ 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 download status of the attachment file. */ 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", /** * Customized message. */ CUSTOM = "custom" } /** * The message body type convert. * * @param params Integer representing message body type. * @returns The message body type. */ export declare function ChatMessageChatTypeFromNumber(params: number): ChatMessageChatType; /** * The message body type convert. * * @param params The message body type. * @returns String representing message body type. */ export declare function ChatGroupPermissionTypeToString(params: ChatMessageChatType): string; /** * The message send direction convert. * * @param params The String representing message direction. * @returns The String. */ export declare function ChatMessageDirectionFromString(params: string): ChatMessageDirection; /** * The message status type convert. * * @param params The Integer representing message status. * @returns The message status. */ export declare function ChatMessageStatusFromNumber(params: number): ChatMessageStatus; /** * The message status type convert. * * @param params The message status type. * @returns The String representing message status type. */ export declare function ChatMessageStatusToString(params: ChatMessageStatus): string; /** * The message download status type convert. * * @param params The integer representing message download status type. * @returns The message download status type. */ export declare function ChatDownloadStatusFromNumber(params: number): ChatDownloadStatus; /** * The message download status type convert. * * @param params The download status type. * @returns The String representing download status type. */ export declare function ChatDownloadStatusToString(params: ChatDownloadStatus): string; /** * The message type convert. * * @param params The string representing message type. * @returns The message type. */ export declare function ChatMessageTypeFromString(params: string): ChatMessageType; /** * The message status change listener interface. */ export interface ChatMessageStatusCallback { /** * The progress of sending or receiving messages. * * @param progress The progress value. */ onProgress(localMsgId: string, progress: number): void; /** * Error message sending or receiving. * * @param error A description of the error. See {@link ChatError}. */ onError(localMsgId: string, error: ChatError): void; /** * The message is sent or received. * @param message The message. */ onSuccess(message: ChatMessage): void; } /** * The message instance class, which represents a sent/received message. * * For example: * * Constructs a text message to send: * * ```typescript * let msg = ChatMessage.createTextMessage( * 'asteriskhx2', * Date.now().toString(), * ChatMessageChatType.PeerChat * ); * ``` */ export declare class ChatMessage { static TAG: string; /** * The server message ID. */ 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. */ to: string; /** * The local timestamp of the message. */ localTime: number; /** * The server timestamp of the message. */ serverTime: number; /** * Whether the delivery receipt is required, which is to check whether the message is delivered successfully. * * - `true`: Yes. * - `false`: No. */ hasDeliverAck: boolean; /** * Whether the message read receipt is required. * * - `true`: Yes. * - `false`: No. */ hasReadAck: boolean; /** * Whether read receipts are required for group messages. * * - `true`: Yes. * - `false`: No. */ needGroupAck: boolean; /** * The number of members that have read the group message. */ groupAckCount: number; /** * Whether the message is read. * * - `true`: Yes. * - `false`: No. */ hasRead: boolean; /** * The chat types. * * There are three chat types: one-to-one chat, group chat, and chat room. */ chatType: ChatMessageChatType; /** * The message direction. See {@link ChatMessageDirection} */ direction: ChatMessageDirection; /** * The message sending/reception status. See {@link ChatMessageStatus} */ status: ChatMessageStatus; /** * The extension attribute of the message. */ attributes: Object; /** * The message body. See {@link ChatMessageBody)}. */ body: ChatMessageBody; /** * Constructs a message. */ constructor(params: { /** * Sets the server message ID. */ msgId?: string; /** * Sets the local message ID. */ localMsgId?: string; /** * Sets the conversation ID. */ conversationId?: string; /** * Sets the message sender. */ from?: string; /** * Sets the message recipient. */ to?: string; /** * Sets the local timestamp of the message. */ localTime?: number; /** * Sets the server timestamp of the message. */ serverTime?: number; /** * Sets whether the message delivery receipt is required. * * - `true`: Yes. * - `false`: No. */ hasDeliverAck?: boolean; /** * Sets whether the message read receipt is required. * * - `true`: Yes. * - `false`: No. */ hasReadAck?: boolean; /** * Sets whether the read receipt is required for a group message. * * - `true`: Yes. * - `false`: No. */ needGroupAck?: boolean; /** * Sets the number of members that have read the group message. */ groupAckCount?: number; /** * Sets whether the message is read. * * - `true`: Yes. * - `false`: No. */ hasRead?: boolean; /** * Sets the chat type. See {@link ChatType}. */ chatType?: number; /** * Sets the message direction. See {@link ChatMessageDirectionFromString}. */ direction?: string; /** * Sets the message status. See {@link ChatMessageStatusFromNumber}. */ status?: number; /** * Sets the extension attributes of the message. */ attributes?: Object; /** * Sets the message body. */ body: Object; }); private static getBody; private static createSendMessage; /** * Creates a text message for sending. * * @param targetId The 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. * @returns The message instance. */ static createTextMessage(targetId: string, content: string, chatType?: ChatMessageChatType): ChatMessage; /** * Creates a message with file attachment for sending. * * @param targetId The 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. * @param opt The file name. * @returns The message instance. */ static createFileMessage(targetId: string, filePath: string, chatType?: ChatMessageChatType, opt?: { displayName: string; }): ChatMessage; /** * Creates an image message for sending. * * @param targetId The 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. * @param opt * @{#displayName} The image name. * @{#thumbnailLocalPath} The image thumbnail path. * @{#sendOriginalImage} Whether to send the original image. * - `true`: Sends the original image. * - (Default) `false`: Sends the thumbnail. For an image greater than 100 KB, the SDK will first compress it. * @{#width} The image width in pixels. * @{#height} The image height in pixels. * @returns The message instance. */ static createImageMessage(targetId: string, filePath: string, chatType?: ChatMessageChatType, opt?: { displayName: string; thumbnailLocalPath?: string; sendOriginalImage?: boolean; width: number; height: number; }): ChatMessage; /** * Creates a video message for sending. * * @param targetId The 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. * @param opt * @{#displayName} The video 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. * @returns The message instance. */ static createVideoMessage(targetId: string, filePath: string, chatType?: ChatMessageChatType, opt?: { displayName: string; thumbnailLocalPath: string; duration: number; width: number; height: number; }): ChatMessage; /** * Creates a video message for sending. * * @param targetId The 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. * @param opt * @{#displayName} The voice name. * @{#duration} The voice duration in seconds. * @returns The message instance. */ static createVoiceMessage(targetId: string, filePath: string, chatType?: ChatMessageChatType, opt?: { displayName: string; duration: number; }): ChatMessage; /** * Creates a location message for sending. * * @param targetId The 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. * @param opt * @{#address} The address. * @returns The message instance. */ static createLocationMessage(targetId: string, latitude: string, longitude: string, chatType?: ChatMessageChatType, opt?: { address: string; }): ChatMessage; /** * Creates a command message for sending. * * @param targetId The 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. * @returns The message instance. */ static createCmdMessage(targetId: string, action: string, chatType?: ChatMessageChatType): ChatMessage; /** * Creates a custom message for sending. * * @param targetId The 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 * @param chatType The conversation type. * @param opt * @{#params} Custom parameters. Key/value pair. It can be nested. * @returns The message instance. */ static createCustomMessage(targetId: string, event: string, chatType?: ChatMessageChatType, opt?: { params: any; }): ChatMessage; static createReceiveMessage(params: any): ChatMessage; } /** * The content part of the message. * * The base class for the concrete message type. */ export declare class ChatMessageBody { /** * The message type. See {@link ChatMessageType}. */ type: ChatMessageType; constructor(type: string); } /** * The text message body. */ export declare class ChatTextMessageBody extends ChatMessageBody { /** * The text message content. */ content: string; constructor(params: { type: string; content: string; }); } /** * The location message body. */ 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. */ export declare class ChatFileMessageBody extends ChatMessageBody { /** * The local path of the image 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 { /** * Sets whether to send the original image when sending an image. * * - (Default) `false`: Sends the thumbnail. For an image larger than 100 KB, the SDK will first compress it. * - `true`: Sends the original 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. */ 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 key of 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; /** * Checks whether to deliver to online users only. * - (Default)`false`: The command message is delivered 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; }); }