The message class that defines a message that is to be sent or received.

For example, construct a text message to send:

  let msg = ChatMessage.createTextMessage(
'asteriskhx2',
Date.now().toString(),
ChatMessageChatType.PeerChat
);

Constructors

  • Constructs a message.

    Parameters

    • params: {
          attributes?: any;
          body: any;
          chatType?: number;
          conversationId?: string;
          deliverOnlineOnly?: boolean;
          direction?: string;
          from?: string;
          groupAckCount?: number;
          hasDeliverAck?: boolean;
          hasRead?: boolean;
          hasReadAck?: boolean;
          isBroadcast?: boolean;
          isChatThread?: boolean;
          isContentReplaced?: boolean;
          isOnline?: boolean;
          localMsgId?: string;
          localTime?: number;
          msgId?: string;
          needGroupAck?: boolean;
          receiverList?: string[];
          serverTime?: number;
          status?: number;
          to?: string;
      }
      • Optionalattributes?: any
      • body: any
      • OptionalchatType?: number
      • OptionalconversationId?: string
      • OptionaldeliverOnlineOnly?: boolean
      • Optionaldirection?: string
      • Optionalfrom?: string
      • OptionalgroupAckCount?: number
      • OptionalhasDeliverAck?: boolean
      • OptionalhasRead?: boolean
      • OptionalhasReadAck?: boolean
      • OptionalisBroadcast?: boolean
      • OptionalisChatThread?: boolean
      • OptionalisContentReplaced?: boolean
      • OptionalisOnline?: boolean
      • OptionallocalMsgId?: string
      • OptionallocalTime?: number
      • OptionalmsgId?: string
      • OptionalneedGroupAck?: boolean
      • OptionalreceiverList?: string[]
      • OptionalserverTime?: number
      • Optionalstatus?: number
      • Optionalto?: string

    Returns ChatMessage

Properties

attributes: Record<string, any>

The extension attribute of the message.

Value can be an object, string, string json, numerical value, undefined, null, etc.

Note Symbol and function types are not supported.

The message body. See ChatMessageBody.

The conversation type. See ChatType.

conversationId: string = ''

The conversation ID.

deliverOnlineOnly: boolean

Whether the message is delivered only when the recipient(s) is/are online:

  • true:The message is delivered only when the recipient(s) is/are online. If the recipient is offline, the message is discarded.
  • (Default) false:The message is delivered when the recipient(s) is/are online. If the recipient(s) is/are offline, the message will not be delivered to them until they get online.

The message direction. See ChatMessageDirection.

from: string = ''

The user ID of the message sender.

groupAckCount: number = 0

The number of group members that have read a message. Upon reading a message, members in the group call ChatManager.sendGroupMessageReadAck or ChatManager.sendConversationReadAck to send a read receipt for a message or a conversation. To enable the read receipt function for group messages, you need to set ChatOptions.requireAck to true during SDK initialization and set isNeedGroupAck to true when sending a message.

hasDeliverAck: boolean = false

Whether messages have arrived at the recipient during a one-to-one chat. If delivery receipts are required, recipient need to set ChatOptions.requireDeliveryAck to true during the SDK initialization. Delivery receipts are unavailable for group messages.

  • true: Yes.
  • (Default) false: No.
hasRead: boolean = false

Whether the the message is read by the recipient during a one-to-one chat or group chat. This parameter setting has connection with the number of unread messages in a conversation. Upon reading the message, the recipient calls ChatManager.markMessageAsRead to mark a message read or ChatManager.markAllMessagesAsRead to mark all unread messages in the conversation read.

  • true: Yes.
  • (Default) false: No.
hasReadAck: boolean = false

Whether the the read receipt from the recipient is received by the sender during a one-to-one chat. Upon reading the message, the recipient calls the ChatManager.sendMessageReadAck or {@link ChatManager.sendConversationReadAck} method to send a read receipt to the sender. If read receipts are required, you need to set ChatOptions.requireAck to true during the SDK initialization.

  • true: Yes.
  • (Default) false: No.
isBroadcast: boolean

Whether it is a global broadcast message.

isChatThread: boolean

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 to.
  • false: No.

Note

This parameter is valid only for group chat.

isContentReplaced: boolean

Whether the message content is replaced.

It is valid after ChatOptions.useReplacedMessageContents is enabled.

isOnline: 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.
localMsgId: string = ''

The local message ID.

localTime: number = ...

The Unix timestamp when the message is created locally. The unit is millisecond.

msgId: string = ...

The message ID generated on the server.

needGroupAck: boolean = false

Whether read receipts are required for a group message.

  • true: Yes.
  • (Default) false: No.
receiverList?: string[]

The recipient list of a targeted message.

The default value is undefined, indicating that the message is sent to all members in the group or chat room.

This property is used only for messages in groups and chat rooms.

serverTime: number = ...

The Unix timestamp when the server receives the message. The unit is millisecond.

status: ChatMessageStatus = ChatMessageStatus.CREATE

The message sending status. See ChatMessageStatus.

to: 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.
TAG: string = 'ChatMessage'

Accessors

  • get groupReadCount(): Promise<undefined | number>
  • Gets the count of read receipts of a group message.

    Returns Promise<undefined | number>

Methods

  • Creates a command message for sending.

    Parameters

    • targetId: string

      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.
    • action: string

      The command action.

    • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

      The conversation type. See ChatType.

    • Optionalopt: {
          deliverOnlineOnly?: boolean;
          isChatThread?: boolean;
          isOnline?: boolean;
          receiverList?: string[];
      }
      • OptionaldeliverOnlineOnly?: boolean
      • OptionalisChatThread?: boolean
      • OptionalisOnline?: boolean
      • OptionalreceiverList?: string[]

    Returns ChatMessage

    The message instance.

    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.
    • receiverList: The recipient list of a targeted message.
  • Creates a combined message for sending.

    Parameters

    • targetId: string

      The message recipient. The field setting is determined by the conversation type:

      • 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.
    • messageIdList: string[]

      A collection of message IDs. The list cannot be empty. It can contain a maximum of 300 message IDs.

    • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

      The conversation type. See ChatType.

    • Optionalopt: {
          compatibleText?: string;
          deliverOnlineOnly?: boolean;
          isChatThread?: boolean;
          isOnline?: boolean;
          receiverList?: string[];
          summary?: string;
          title?: string;
      }
      • OptionalcompatibleText?: string
      • OptionaldeliverOnlineOnly?: boolean
      • OptionalisChatThread?: boolean
      • OptionalisOnline?: boolean
      • OptionalreceiverList?: string[]
      • Optionalsummary?: string
      • Optionaltitle?: string

    Returns ChatMessage

    The message instance.

    opt The extension parameters of the message.

    • title: The title of the combined message.
    • summary: The summary of the combined message.
    • compatibleText: The compatible text of the combined message. This field is used for compatibility with SDK versions that do not support combined messages.
    • isChatThread: Whether this message is a threaded message.
      • true: Yes.
      • (Default) false:No.
    • isOnline: Whether it is a online message.
      • true: Yes.
      • false:No.
    • deliverOnlineOnly: Whether the message is delivered only when the recipient(s) is/are online:
      • true: - true:The message is delivered only when the recipient(s) is/are online. If the recipient is offline, the message is discarded.
      • (Default) false:The message is delivered when the recipient(s) is/are online. If the recipient(s) is/are offline, the message will not be delivered to them until they get online.
    • receiverList: The recipient list of a targeted message.
  • Creates a custom message for sending.

    Parameters

    • targetId: string

      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.
    • event: string

      The custom event.

    • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

      The conversation type. See ChatType.

    • Optionalopt: {
          deliverOnlineOnly?: boolean;
          isChatThread?: boolean;
          isOnline?: boolean;
          params: Record<string, string>;
          receiverList?: string[];
      }
      • OptionaldeliverOnlineOnly?: boolean
      • OptionalisChatThread?: boolean
      • OptionalisOnline?: boolean
      • params: Record<string, string>
      • OptionalreceiverList?: string[]

    Returns ChatMessage

    The message instance.

    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.
    • receiverList: The recipient list of a targeted message.
  • Creates a message with a file attachment for sending.

    Parameters

    • targetId: string

      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.
    • filePath: string

      The file path.

    • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

      The conversation type. See ChatType.

    • Optionalopt: {
          deliverOnlineOnly?: boolean;
          displayName: string;
          fileSize?: number;
          isChatThread?: boolean;
          isOnline?: boolean;
          receiverList?: string[];
      }
      • OptionaldeliverOnlineOnly?: boolean
      • displayName: string
      • OptionalfileSize?: number
      • OptionalisChatThread?: boolean
      • OptionalisOnline?: boolean
      • OptionalreceiverList?: string[]

    Returns ChatMessage

    The message instance.

    opt The extension parameters of the message.

    • displayName: The file name.
    • isChatThread: Whether this message is a threaded message.
      • true: Yes.
      • (Default) false: No.
    • isOnline: Whether it is a online message.
    • deliverOnlineOnly: Whether the message is delivered only when the recipient(s) is/are online.
    • fileSize: The file size.
    • receiverList: The recipient list of a targeted message.
  • Creates an image message for sending.

    Parameters

    • targetId: string

      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.
    • filePath: string

      The image path.

    • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

      The conversation type. See ChatType.

    • Optionalopt: {
          deliverOnlineOnly?: boolean;
          displayName: string;
          fileSize?: number;
          height: number;
          isChatThread?: boolean;
          isOnline?: boolean;
          receiverList?: string[];
          sendOriginalImage?: boolean;
          thumbnailLocalPath?: string;
          width: number;
      }
      • OptionaldeliverOnlineOnly?: boolean
      • displayName: string
      • OptionalfileSize?: number
      • height: number
      • OptionalisChatThread?: boolean
      • OptionalisOnline?: boolean
      • OptionalreceiverList?: string[]
      • OptionalsendOriginalImage?: boolean
      • OptionalthumbnailLocalPath?: string
      • width: number

    Returns ChatMessage

    The message instance.

    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.
    • isOnline: Whether it is a online message.
    • deliverOnlineOnly: Whether the message is delivered only when the recipient(s) is/are online.
    • fileSize: The file size.
    • receiverList: The recipient list of a targeted message.
  • Creates a location message for sending.

    Parameters

    • targetId: string

      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.
    • latitude: string

      The latitude.

    • longitude: string

      The longitude.

    • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

      The conversation type. See ChatType.

    • Optionalopt: {
          address: string;
          deliverOnlineOnly?: boolean;
          isChatThread?: boolean;
          isOnline?: boolean;
          receiverList?: string[];
      }
      • address: string
      • OptionaldeliverOnlineOnly?: boolean
      • OptionalisChatThread?: boolean
      • OptionalisOnline?: boolean
      • OptionalreceiverList?: string[]

    Returns ChatMessage

    The message instance.

    opt The extension parameters of the message.

    • address: The location details.
    • isChatThread: Whether this message is a threaded message.
      • true: Yes.
      • (Default) false: No.
    • receiverList: The recipient list of a targeted message.
  • Creates a received message instance.

    Parameters

    • params: any

      The received message.

    Returns ChatMessage

    The message object.

  • Parameters

    • params: {
          body: ChatMessageBody;
          chatType: ChatMessageChatType;
          deliverOnlineOnly?: boolean;
          isChatThread?: boolean;
          isOnline?: boolean;
          receiverList?: string[];
          targetId: string;
      }
      • body: ChatMessageBody
      • chatType: ChatMessageChatType
      • OptionaldeliverOnlineOnly?: boolean
      • OptionalisChatThread?: boolean
      • OptionalisOnline?: boolean
      • OptionalreceiverList?: string[]
      • targetId: string

    Returns ChatMessage

  • Creates a text message for sending.

    Parameters

    • targetId: string

      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.
    • content: string

      The text content.

    • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

      The conversation type. See ChatType.

    • Optionalopt: {
          deliverOnlineOnly?: boolean;
          isChatThread?: boolean;
          isOnline?: boolean;
          receiverList?: string[];
          targetLanguageCodes?: string[];
      }
      • OptionaldeliverOnlineOnly?: boolean
      • OptionalisChatThread?: boolean
      • OptionalisOnline?: boolean
      • OptionalreceiverList?: string[]
      • OptionaltargetLanguageCodes?: string[]

    Returns ChatMessage

    The message instance.

    opt The extension parameters of the message.

    • targetLanguageCodes: The language code. See ChatTextMessageBody.targetLanguageCodes.
    • isChatThread: Whether this message is a threaded message.
    • true: Yes.
    • (Default) false: No.
    • isOnline: Whether it is a online message.
    • deliverOnlineOnly: Whether the message is delivered only when the recipient(s) is/are online.
    • receiverList: The recipient list of a targeted message.
  • Creates a video message for sending.

    Parameters

    • targetId: string

      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.
    • filePath: string

      The path of the video file.

    • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

      The conversation type. See ChatType.

    • Optionalopt: {
          deliverOnlineOnly?: boolean;
          displayName: string;
          duration: number;
          fileSize?: number;
          height: number;
          isChatThread?: boolean;
          isOnline?: boolean;
          receiverList?: string[];
          thumbnailLocalPath: string;
          width: number;
      }
      • OptionaldeliverOnlineOnly?: boolean
      • displayName: string
      • duration: number
      • OptionalfileSize?: number
      • height: number
      • OptionalisChatThread?: boolean
      • OptionalisOnline?: boolean
      • OptionalreceiverList?: string[]
      • thumbnailLocalPath: string
      • width: number

    Returns ChatMessage

    The message instance.

    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.
    • isOnline: Whether it is a online message.
    • deliverOnlineOnly: Whether the message is delivered only when the recipient(s) is/are online.
    • fileSize: The file size.
    • receiverList: The recipient list of a targeted message.
  • Creates a voice message for sending.

    Parameters

    • targetId: string

      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.
    • filePath: string

      The path of the voice file.

    • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

      The conversation type. See ChatType.

    • Optionalopt: {
          deliverOnlineOnly?: boolean;
          displayName?: string;
          duration: number;
          fileSize?: number;
          isChatThread?: boolean;
          isOnline?: boolean;
          receiverList?: string[];
      }
      • OptionaldeliverOnlineOnly?: boolean
      • OptionaldisplayName?: string
      • duration: number
      • OptionalfileSize?: number
      • OptionalisChatThread?: boolean
      • OptionalisOnline?: boolean
      • OptionalreceiverList?: string[]

    Returns ChatMessage

    The message instance.

    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.
    • isOnline: Whether it is a online message.
    • deliverOnlineOnly: Whether the message is delivered only when the recipient(s) is/are online.
    • fileSize: The file size.
    • receiverList: The recipient list of a targeted message.