Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a chat message with typed content. Messages are the fundamental data unit for communication in channels.

example
// Sending a text message
const params = new SendTextMessageParams({ text: 'Hello!' });
const result = await channel.sendMessage(params);
if (result.isOk) {
const message: Message<TextMessageContent> = result.data;
console.log('Sent message ID:', message.messageId);
console.log('Sender:', message.senderUserId);
}

// Creating media message params from a file
const imgResult = await Message.createSendImageMessageParams(imageFile);
if (imgResult.isOk) {
await channel.sendMediaMessage(imgResult.data);
}

Type Parameters

  • T extends Record<string, any>

    The type of the message content payload

Hierarchy

  • Message

Index

Accessors

  • get messageId(): string
  • The unique server-side message ID

    Returns string

  • get content(): T
  • The message content payload

    Returns T

  • get messageType(): string
  • The registered message type identifier (e.g. 'RC:TxtMsg')

    Returns string

  • get isPersisted(): boolean
  • Whether this message type is persisted in storage

    Returns boolean

  • get isCounted(): boolean
  • Whether this message type is counted in unread count

    Returns boolean

  • get isStatusMessage(): boolean
  • Whether this is a status (transient) message

    Returns boolean

  • get clientId(): number
  • The local client-side message ID

    Returns number

  • get sentReceipt(): boolean
  • Whether a read receipt has been sent for this message

    Returns boolean

Properties

sentTime: number = 0

Timestamp (ms) when the message was sent

senderUserId: string = ''

The user ID of the message sender

metadata: Map<string, string> = ...

Key-value metadata (expansion) attached to the message

modifyInfo: null | MessageModifyInfo = null

Information about message modification, or null if not modified

hasChanged: boolean = false

Whether the message has been changed

needReceipt: boolean = true

Whether read receipt is requested for this message

directedUserIds: string[] = []

List of target user IDs for directed messages

disableUpdateLastMessage: boolean = false

Whether this message should not update the channel's last message

direction: MessageDirection = MessageDirection.SEND

The direction of the message (sent or received)

disableNotification: boolean = false

Whether push notification is disabled for this message

Methods

  • setMetadata(metadata: Record<string, string>): Promise<NCResult<void>>
  • Updates or adds metadata (expansion) key-value pairs for this message.

    example
    await message.setMetadata({ reaction: 'thumbsup', priority: 'high' });
    

    Parameters

    • metadata: Record<string, string>

      Key-value pairs to set or update

    Returns Promise<NCResult<void>>

    A promise resolving to the operation result

  • deleteMetadata(keys: string[]): Promise<NCResult<void>>
  • Deletes metadata (expansion) keys from this message.

    example
    await message.deleteMetadata(['reaction', 'priority']);
    

    Parameters

    • keys: string[]

      The metadata keys to delete

    Returns Promise<NCResult<void>>

    A promise resolving to the operation result

  • requestSpeechToText(): Promise<NCResult<void>>
  • Requests speech-to-text conversion for this voice message. The result will be delivered via {@link MessageHandlerParams.onSpeechToTextComplete}.

    example
    const result = await voiceMessage.requestSpeechToText();
    

    Returns Promise<NCResult<void>>

    A promise resolving to the operation result

  • requestStreamMessage(): Promise<NCResult<void>>
  • Requests the full content of a stream message. Stream message chunks will be delivered via MessageHandlerParams.onStreamMessageRequestDelta.

    example
    const result = await streamMessage.requestStreamMessage();
    

    Returns Promise<NCResult<void>>

    A promise resolving to the operation result

  • downloadMedia(): Promise<NCResult<void>>
  • Opens the remote media URL for this message in a new browser tab via window.open. Supported for message types that register CustomMessageRegistration.remoteFileUrlField (built-in image, file, GIF, HD voice, short video, and custom media types).

    In non-browser environments or when window.open is unavailable, returns failure with {@link ErrorCode.NOT_SUPPORT}.

    Returns Promise<NCResult<void>>

    Success when the URL was opened, or an error (empty URL, unsupported message type, or no window.open)

  • toObject(): Record<string, any>
  • Returns Record<string, any>