Message
This object represents a message.
Fields
message_idIntegerRequiredUnique message identifier inside this chat. In specific instances (e.g., message containing a video sent to a big chat), the server might automatically schedule a message instead of sending it immediately. In such cases, this field will be 0 and the relevant message will be unusable until it is actually sent
message_thread_idIntegerOptionalOptional. Unique identifier of a message thread or forum topic to which the message belongs; for supergroups and private chats only
Optional. Information about the direct messages chat topic that contains the message
Optional. 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
Optional. 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.
sender_boost_countIntegerOptionalOptional. If the sender of the message boosted the chat, the number of boosts added by the user
Optional. 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.
sender_tagStringOptionalOptional. Tag or custom title of the sender of the message; for supergroups only
dateIntegerRequiredDate the message was sent in Unix time. It is always a positive number, representing a valid date.
business_connection_idStringOptionalOptional. 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.
Chat the message belongs to
Optional. Information about the original message for forwarded messages
is_topic_messageTrueOptionalOptional. True, if the message is sent to a topic in a forum supergroup or a private chat with the bot
is_automatic_forwardTrueOptionalOptional. True, if the message is a channel post that was automatically forwarded to the connected discussion group
Optional. 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.
Optional. Information about the message that is being replied to, which may come from another chat or forum topic
Optional. For replies that quote part of the original message, the quoted part of the message
Optional. For replies to a story, the original story
reply_to_checklist_task_idIntegerOptionalOptional. Identifier of the specific checklist task that is being replied to
Optional. Bot through which the message was sent
edit_dateIntegerOptionalOptional. Date the message was last edited in Unix time
has_protected_contentTrueOptionalOptional. True, if the message can't be forwarded
is_from_offlineTrueOptionalOptional. 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
is_paid_postTrueOptionalOptional. True, if the message is a paid post. Note that such posts must not be deleted for 24 hours to receive the payment and can't be edited.
media_group_idStringOptionalOptional. The unique identifier inside this chat of a media message group this message belongs to
author_signatureStringOptionalOptional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator
paid_star_countIntegerOptionalOptional. The number of Telegram Stars that were paid by the sender of the message to send it
textStringOptionalOptional. For text messages, the actual UTF-8 text of the message
Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
Optional. Options used for link preview generation for the message, if it is a text message and link preview options were changed
Optional. Information about suggested post parameters if the message is a suggested post in a channel direct messages chat. If the message is an approved or declined suggested post, then it can't be edited.
effect_idStringOptionalOptional. Unique identifier of the message effect added to the message
Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set
Optional. Message is an audio file, information about the file
Optional. Message is a general file, information about the file
Optional. Message contains paid media; information about the paid media
Optional. Message is a photo, available sizes of the photo
Optional. Message is a sticker, information about the sticker
Optional. Message is a forwarded story
Optional. Message is a video, information about the video
Optional. Message is a video note, information about the video message
Optional. Message is a voice message, information about the file
captionStringOptionalOptional. Caption for the animation, audio, document, paid media, photo, video or voice
Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption
show_caption_above_mediaTrueOptionalOptional. True, if the caption must be shown above the message media
has_media_spoilerTrueOptionalOptional. True, if the message media is covered by a spoiler animation
Optional. Message is a checklist
Optional. Message is a shared contact, information about the contact
Optional. Message is a dice with random value
Optional. Message is a game, information about the game. More about games »
Optional. Message is a native poll, information about the poll
Optional. Message is a venue, information about the venue. For backward compatibility, when this field is set, the location field will also be set
Optional. Message is a shared location, information about the location
Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
Optional. A member was removed from the group, information about them (this member may be the bot itself)
Optional. Service message: chat owner has left
Optional. Service message: chat owner has changed
new_chat_titleStringOptionalOptional. A chat title was changed to this value
Optional. A chat photo was change to this value
delete_chat_photoTrueOptionalOptional. Service message: the chat photo was deleted
group_chat_createdTrueOptionalOptional. Service message: the group has been created
supergroup_chat_createdTrueOptionalOptional. 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.
channel_chat_createdTrueOptionalOptional. 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.
Optional. Service message: auto-delete timer settings changed in the chat
migrate_to_chat_idIntegerOptionalOptional. The group has been migrated to a supergroup with the specified identifier. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier.
migrate_from_chat_idIntegerOptionalOptional. The supergroup has been migrated from a group with the specified identifier. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier.
Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply\to\message fields even if it itself is a reply.
Optional. Message is an invoice for a payment, information about the invoice. More about payments »
Optional. Message is a service message about a successful payment, information about the payment. More about payments »
Optional. Message is a service message about a refunded payment, information about the payment. More about payments »
Optional. Service message: users were shared with the bot
Optional. Service message: a chat was shared with the bot
Optional. Service message: a regular gift was sent or received
Optional. Service message: a unique gift was sent or received
Optional. Service message: upgrade of a gift was purchased after the gift was sent
connected_websiteStringOptionalOptional. The domain name of the website on which the user has logged in. More about Telegram Login »
Optional. 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
Optional. Telegram Passport data
Optional. Service message. A user in the chat triggered another user's proximity alert while sharing Live Location.
Optional. Service message: user boosted the chat
Optional. Service message: chat background set
Optional. Service message: some tasks in a checklist were marked as done or not done
Optional. Service message: tasks were added to a checklist
Optional. Service message: the price for paid messages in the corresponding direct messages chat of a channel has changed
Optional. Service message: forum topic created
Optional. Service message: forum topic edited
Optional. Service message: forum topic closed
Optional. Service message: forum topic reopened
Optional. Service message: the 'General' forum topic hidden
Optional. Service message: the 'General' forum topic unhidden
Optional. Service message: a scheduled giveaway was created
Optional. The message is a scheduled giveaway message
Optional. A giveaway with public winners was completed
Optional. Service message: a giveaway without public winners was completed
Optional. Service message: the price for paid messages has changed in the chat
Optional. Service message: a suggested post was approved
Optional. Service message: approval of a suggested post has failed
Optional. Service message: a suggested post was declined
Optional. Service message: payment for a suggested post was received
Optional. Service message: payment for a suggested post was refunded
Optional. Service message: video chat scheduled
Optional. Service message: video chat started
Optional. Service message: video chat ended
Optional. Service message: new participants invited to a video chat
Optional. Service message: data sent by a Web App
Optional. Inline keyboard attached to the message.
login_url buttons are represented as ordinary url buttons.GramIO Usage
In GramIO, Message is accessible through context objects in update handlers:
typescript
// message context has the message directly
bot.on("message", (ctx) => {
const msg = ctx.message; // Message object
console.log(msg.message_id);
console.log(msg.text); // undefined for non-text messages
console.log(msg.from?.id); // sender user ID
console.log(msg.chat.id); // chat ID
console.log(msg.date); // Unix timestamp
});
// Check message type by checking which field is present
bot.on("message", (ctx) => {
if (ctx.message.photo) {
console.log("Got a photo!");
} else if (ctx.message.text) {
console.log("Got text:", ctx.message.text);
}
});
// Access reply
bot.on("message", (ctx) => {
if (ctx.message.reply_to_message) {
const originalText = ctx.message.reply_to_message.text;
ctx.send(`You replied to: "${originalText}"`);
}
});
// sendMessage returns a Message
const sentMsg = await bot.api.sendMessage({
chat_id: 123,
text: "Hello!",
});
console.log(sentMsg.message_id); // now you can edit/delete itTips & Gotchas
- Most fields are optional — a
Messagerepresents any type of message. Check for the specific field (text,photo,video, etc.) to determine the message type. fromcan be absent in channel posts where messages are sent on behalf of the channel.dateis a Unix timestamp (seconds since epoch). Convert withnew Date(msg.date * 1000).- Forwarded messages have
forward_origin— thefromfield still reflects the forwarder (the user who forwarded it to your bot). - GramIO context provides convenience getters — e.g.
ctx.fromis shorthand forctx.message.from.
Used By
Methods that return a Message:
- sendMessage — Send text
- sendPhoto — Send photo
- sendDocument — Send file
- sendVideo — Send video
- editMessageText — Edit message text
- copyMessage — Copy a message
See Also
- Update — The wrapper object that contains
Messagein polling/webhook updates - User — Represents
msg.from - Chat — Represents
msg.chat - MessageEntity — Represents formatting entities in
msg.entities