Class Message

Hierarchy (view full)

Constructors

Properties

animation?: Animation

Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set

audio?: Audio

Message is an audio file, information about the file

author?: User

Sender of the message; may be empty for messages sent to channels. For backward compatibility, if the message was sent on behalf of a chat, the field contains a fake sender user in non-channel chats

authorOffline?: true

True, if the message was sent by an implicit action, for example, as an away or a greeting business message, or as a scheduled message

authorSignature?: string

Signature of the post author for messages in channels, or the custom title of an anonymous group administrator

autoDelTimerChanged?: {
    autoDelTime: number;
}

Service message: auto-delete timer settings changed in the chat

Type declaration

  • autoDelTime: number
    • New auto-delete time for messages in the chat; in seconds
automaticForward?: boolean

True, if the message is a channel post that was automatically forwarded to the connected discussion group

boostAdded?: {
    count: number;
}

Service message: user boosted the chat

Type declaration

  • count: number
    • Number of boosts added by the user
businessId?: string

Unique identifier of the business connection from which the message was received. If non-empty, the message belongs to a chat of the corresponding business account that is independent from any potential bot chat which might share the same identifier

caption?: string

Caption for the animation, audio, document, photo, video or voice

captionEntities?: MessageEntities

For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption

channelChatCreated?: true

Service message: the channel has been created. This field can't be received in a message coming through updates, because bot can't be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel

chat?: Chat

Sender of the message when sent on behalf of a chat. For example, the supergroup itself for messages sent by its anonymous administrators or a linked channel for messages automatically forwarded to the channel's discussion group. For backward compatibility, if the message was sent on behalf of a chat, the field from contains a fake sender user in non-channel chats.

chatBackgroundSet?: ChatBackground

Service message: chat background set

chatShared?: ChatShared

Service message: a chat was shared with the bot

connectedWebsite?: string

The domain name of the website on which the user has logged in. More about Telegram Login

contact?: Contact

Message is a shared contact, information about the contact

content?: string

For text messages, the actual UTF-8 text of the message

createdUnixTime: number

Date the message was sent in Unix time. It is always a positive number, representing a valid date

deleteChatPhoto?: true

Service message: the chat photo was deleted

dice?: Dice

Message is a dice with random value

document?: Document

Message is a general file, information about the file

editedUnixTime?: number

Date the message was last edited in Unix time

effectId?: string

Unique identifier of the message effect added to the message

entities?: MessageEntities

For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text

externalReply?: ExternalReplyInfo

Information about the message that is being replied to, which may come from another chat or forum topic

forum?: Forum

If the message is sent to a forum topic

forumClosed?: true

Service message: forum topic closed

forumCreated?: ForumTopic

Service message: forum topic created

forumEdited?: ForumTopic

Service message: forum topic edited

forumTopicReopened?: true

Service message: forum topic reopened

forwardOrigin?: MessageOrigin

Information about the original message for forwarded messages

game?: Game

Message is a game, information about the game. More about games

generalForumHidden?: true

Service message: the 'General' forum topic hidden

generalForumUnhidden?: true

Service message: the 'General' forum topic unhidden

giveaway?: Giveaway

The message is a scheduled giveaway message

giveawayCompleted?: GiveawayCompleted

Service message: a giveaway without public winners was completed

giveawayCreated?: {
    starCount?: number;
}

Service message: a scheduled giveaway was created

Type declaration

  • OptionalstarCount?: number
    • The number of Telegram Stars to be split between giveaway winners; for Telegram Star giveaways only
giveawayWinners?: GiveawayWinners

A giveaway with public winners was completed

groupChatCreated?: true

Service message: the group has been created

id: string

Unique message identifier inside this chat

inTopic?: boolean

True, if the message is sent to a forum topic

leftChatMember?: User

A member was removed from the group, information about them (this member may be the bot itself)

linkPreviewOpts?: LinkPreviewOptions

Options used for link preview generation for the message, if it is a text message and link preview options were changed

location?: Location

Message is a shared location, information about the location

member?: ChatMember

Member that were added to the message group or supergroup and information about them

migrateFromChatId?: string

The supergroup has been migrated from a group with the specified identifier

newChatMembers?: User[]

New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)

newChatPhoto?: Photo[]

A chat photo was change to this value

newChatTitle?: string

A chat title was changed to this value

originalMessage?: Message

For replies in the same chat and message thread, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply

paidMedia?: PaidMediaInfo

Message contains paid media; information about the paid media

passport?: PassportData

Telegram Passport data

photo?: Photo[]

Message is a photo, available sizes of the photo

poll?: Poll

Message is a native poll, information about the poll

protectedContent?: true

True, if the message can't be forwarded

proximityAlertTriggered?: {
    distance: number;
    traveler: User;
    watcher: User;
}

Service message. A user in the chat triggered another user's proximity alert while sharing Live Location

Type declaration

  • distance: number
    • The distance between the users
  • traveler: User
    • User that triggered the alert
  • watcher: User
    • User that set the alert
quote?: TextQuote

For replies that quote part of the original message, the quoted part of the message

refundedPayment?: RefundedPayment

Message is a service message about a refunded payment, information about the payment. More about payments

senderBoostCount?: number

If the sender of the message boosted the chat, the number of boosts added by the user

senderBusinessBot?: User

The bot that actually sent the message on behalf of the business account. Available only for outgoing messages sent on behalf of the connected business account.

senderChat?: Chat

Chat that sent the message originally

showAboveMedia?: true

True, if the caption must be shown above the message media

sticker?: Sticker

Message is a sticker, information about the sticker

story?: Story

For replies to a story, the original message

successfulPayment?: SuccessfulPayment

Message is a service message about a successful payment, information about the payment. More about payments

supergroupChatCreated?: true

Service message: the supergroup has been created. This field can't be received in a message coming through updates, because bot can't be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup

threadId?: string

Unique identifier of a message thread or a forum topic to which the message belongs; for supergroups only

usersShared?: UsersShared

Service message: users were shared with the bot

venue?: Venue

Message is a venue, information about the venue

viaBot?: User

Bot through which the message was sent

video?: Video

Message is a video, information about the video

videoChatEnded?: {
    duration: number;
}

Service message: video chat ended

Type declaration

  • duration: number
    • Video chat duration in seconds
videoChatParticiInvited?: VideoChatParticipantsInvited

Service message: new participants invited to a video chat

videoChatScheduled?: VideoChatScheduled

Service message: video chat scheduled

videoChatStarted?: true

Service message: video chat started

videoNote?: VideoNote

Message is a video note, information about the video message

voice?: Voice

Message is a voice message, information about the file

webApp?: {
    data: string;
    text: string;
}

Service message: data sent by a Web App

Type declaration

  • data: string
    • The data. Be aware that a bad client can send arbitrary data in this field
  • text: string
    • Text of the web_app keyboard button from which the Web App was opened. Be aware that a bad client can send arbitrary data in this field
writeAccessAllowed?: {
    appName?: string;
    authorAttachmentMenu?: boolean;
    authorRequest?: boolean;
}

Service message: the user allowed the bot to write messages after adding it to the attachment or side menu, launching a Web App from a link, or accepting an explicit request from a Web App sent by the method requestWriteAccess

Type declaration

  • OptionalappName?: string
    • Name of the Web App, if the access was granted when the Web App was launched from a link
  • OptionalauthorAttachmentMenu?: boolean
    • True, if the access was granted when the bot was added to the attachment or side menu
  • OptionalauthorRequest?: boolean
    • True, if the access was granted after the user accepted an explicit request from a Web App sent by the method requestWriteAccess

Accessors

  • get createdAt(): Date
  • Date the message was sent. It is always a positive number, representing a valid date

    Returns Date

  • get createdTimestamp(): number
  • Return the timestamp message was sent, in milliseconds

    Returns number

  • get editedTimestamp(): null | Date
  • Return the timestamp message was last edited, in milliseconds

    Returns null | Date

Methods

  • Protected

    Updates the current instance with new data and returns a clone of the updated instance

    Parameters

    • data: Record<string, any>

      The data to update the instance with

    Returns Base

    A clone of the updated instance

  • Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message.

    Parameters

    • chatId: string | number

      Unique identifier for the target chat or username of the target channel (in the format @channelusername)

    • Optionaloptions: Omit<{
          caption?: string;
          captionEntities?: MessageEntity[];
          chatId: string | number;
          disableNotification?: boolean;
          fromChatId: string | number;
          messageId: string | number;
          messageThreadId?: string | number;
          parseMode?: string;
          protectContent?: boolean;
          replyMarkup?:
              | InlineKeyboardMarkup
              | ForceReply
              | ReplyKeyboardMarkup
              | ReplyKeyboardRemove;
          replyParameters?: ReplyParameters;
          showCaptionAboveMedia?: boolean;
      }, "chatId" | "messageId" | "fromChatId">

      out parameters

    Returns Promise<number>

    Returns the message id of the sent message on success.

  • Use this method to delete a message, including service messages, with the following limitations:

    • A message can only be deleted if it was sent less than 48 hours ago.
    • Service messages about a supergroup, channel, or forum topic creation can't be deleted.
    • A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
    • Bots can delete outgoing messages in private chats, groups, and supergroups.
    • Bots can delete incoming messages in private chats.
    • Bots granted can_post_messages permissions can delete outgoing messages in channels.
    • If the bot is an administrator of a group, it can delete any message there.
    • If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.

    Returns Promise<true>

    Returns True on success.

  • Use this method to edit text and game messages.

    Parameters

    • text: string

      New text of the message, 1-4096 characters after entities parsing

    • Optionaloptions: Omit<{
          businessConnectionId?: string;
          chatId?: string | number;
          entities?: MessageEntity[];
          inlineMessageId?: string | number;
          linkPreviewOptions?: LinkPreviewOptions;
          messageId?: string | number;
          parseMode?: ParseMode;
          replyMarkup?: InlineKeyboardMarkup;
          text: string;
      }, "text" | "chatId" | "messageId">

      out parameters

    Returns Promise<boolean | Message & {
        content: string;
        editedAt: Date;
        editedTimestamp: number;
        editedUnixTime: number;
    }>

    On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.

  • Use this method to edit captions of messages.

    Parameters

    • Optionalcaption: string

      New caption of the message, 0-1024 characters after entities parsing

    • Optionaloptions: Omit<{
          businessConnectionId?: string;
          caption?: string;
          captionEntities?: MessageEntity[];
          chatId?: string | number;
          inlineMessageId?: string | number;
          messageId?: string | number;
          parseMode?: ParseMode;
          replyMarkup?: InlineKeyboardMarkup;
          showCaptionAboveMedia?: boolean;
      }, "caption" | "chatId" | "messageId">

      out parameters

    Returns Promise<boolean | Message & {
        caption?: string;
        editedAt: Date;
        editedTimestamp: number;
        editedUnixTime: number;
    }>

    On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.

  • Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation.

    Parameters

    • latitude: number

      Latitude of new location

    • longitude: number

      Longitude of new location

    • Optionaloptions: Omit<{
          businessConnectionId?: string;
          chatId?: string | number;
          heading?: number;
          horizontalAccuracy?: number;
          inlineMessageId?: string | number;
          latitude: number;
          livePeriod?: number;
          longitude: number;
          messageId?: string | number;
          proximityAlertRadius?: number;
          replyMarkup?: InlineKeyboardMarkup;
      },
          | "chatId"
          | "messageId"
          | "latitude"
          | "longitude">

      out parameters

    Returns Promise<true | Message & {
        editedAt: Date;
        editedTimestamp: number;
        editedUnixTime: number;
        location: Location;
    }>

    On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.

  • Use this method to edit animation, audio, document, photo, or video messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL.

    Parameters

    • media: InputMedia

      An object for a new media content of the message

    • Optionaloptions: Omit<{
          businessConnectionId?: string;
          chatId?: string | number;
          inlineMessageId?: string | number;
          media: InputMedia;
          messageId?: string | number;
          replyMarkup?: InlineKeyboardMarkup;
      }, "media" | "chatId" | "messageId">

      out parameters

    Returns Promise<true | Message & {
        editedAt: Date;
        editedTimestamp: number;
        editedUnixTime: number;
    }>

    On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.

  • Use this method to edit only the reply markup of messages.

    Parameters

    • replyMarkup: InlineKeyboardMarkup

      An object for an inline keyboard

    • Optionaloptions: Omit<{
          businessConnectionId?: string;
          chatId?: string | number;
          inlineMessageId?: string | number;
          messageId?: string | number;
          replyMarkup?: InlineKeyboardMarkup;
      }, "media" | "chatId" | "messageId">

      out parameters

    Returns Promise<true | Message & {
        editedAt: Date;
        editedTimestamp: number;
        editedUnixTime: number;
    }>

    On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.

  • Use this method to forward messages of any kind. Service messages and messages with protected content can't be forwarded.

    Parameters

    • chatId: string | number

      Unique identifier for the target chat or username of the target channel (in the format @channelusername)

    • Optionaloptions: Omit<{
          chatId: string | number;
          disableNotification?: boolean;
          fromChatId: string | number;
          messageId: string | number;
          messageThreadId?: string | number;
          protectContent?: boolean;
      },
          | "chatId"
          | "messageThreadId"
          | "messageId"
          | "fromChatId">

      out parameters

    Returns Promise<Message>

    On success, the sent Message is returned.

  • Checking if the message has been edited

    Returns this is Message & {
        editedAt: Date;
        editedTimestamp: number;
        editedUnixTime: number;
    }

  • Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a channel.

    Parameters

    • Optionalnotification: boolean

      Pass True if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels and private chats

    • OptionalbusinessConnectionId: string

      Unique identifier of the business connection on behalf of which the message will be pinned

    Returns Promise<true>

    Returns True on success.

  • Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. In albums, bots must react to the first message.

    Parameters

    • reaction:
          | string
          | ReactionType
          | ReactionType[]
          | ReactionType
          | ReactionType[]

      A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. Paid reactions can't be used by bots

    • OptionalisBig: boolean

      Pass True to set the reaction with a big animation

    Returns Promise<true>

    Returns True on success.

  • Reply to the current message

    Parameters

    • text: string

      Text of the message to be sent, 1-4096 characters after entities parsing

    • Optionaloptions: Omit<{
          businessConnectionId?: string;
          chatId: string | number;
          disableNotification?: boolean;
          entities?: MessageEntity[];
          linkPreviewOptions?: LinkPreviewOptions;
          messageEffectId?: string;
          messageThreadId?: string | number;
          parseMode?: ParseMode;
          protectContent?: boolean;
          replyMarkup?:
              | InlineKeyboardMarkup
              | ForceReply
              | ReplyKeyboardMarkup
              | ReplyKeyboardRemove;
          replyParameters?: ReplyParameters;
          text: string;
      }, "text" | "chatId" | "messageThreadId">

      out parameters

    Returns Promise<Message & {
        content: string;
    }>

    On success, the sent Message is returned.

  • Use this method to stop updating a live location message before live_period expires.

    Parameters

    • Optionaloptions: Omit<{
          businessConnectionId?: string;
          chatId?: string | number;
          inlineMessageId?: string;
          messageId?: string | number;
          replyMarkup?: InlineKeyboardMarkup;
      }, "chatId" | "messageId">

      out parameters

    Returns Promise<true | Message & {
        editedAt: Date;
        editedTimestamp: number;
        editedUnixTime: number;
        location: Location;
    }>

    On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned.

  • Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a channel.

    Parameters

    • OptionalbusinessConnectionId: string

      Unique identifier of the business connection on behalf of which the message will be unpinned

    Returns Promise<true>

    Returns True on success.