Skip to content

editMessageText

Use this method to edit text and game messages. 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.

Parameters

business_connection_idStringOptional
Unique identifier of the business connection on behalf of which the message to be edited was sent
chat_idIntegerStringOptional
Required if inline\message\id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
message_idIntegerOptional
Required if inline\message\id is not specified. Identifier of the message to edit
inline_message_idStringOptional
Required if chat\id and message\id are not specified. Identifier of the inline message
textStringRequired✏️ FormattableminLen 1maxLen 4096
New text of the message, 1-4096 characters after entities parsing
parse_modeStringOptional
Mode for parsing entities in the message text. See formatting options for more details.
entitiesMessageEntity[]Optional
A JSON-serialized list of special entities that appear in message text, which can be specified instead of parse\_mode
link_preview_optionsLinkPreviewOptionsOptional
Link preview generation options for the message
A JSON-serialized object for an inline keyboard.

Returns

On success, Message | True is returned.

GramIO Usage

ts
// Edit message text when a user presses a button
bot
.
on
("callback_query", async (
ctx
) => {
await
ctx
.
editText
("Updated message content!");
await
ctx
.
answer
();
});
ts
// Edit with rich text formatting — entities are built automatically, no parse_mode needed
bot
.
on
("callback_query", async (
ctx
) => {
await
ctx
.
editText
(
format
`Hello, ${
bold
("world")}! Visit ${
link
("GramIO", "https://gramio.dev")}`,
); await
ctx
.
answer
();
});
ts
// Edit text and update the inline keyboard simultaneously
bot
.
on
("callback_query", async (
ctx
) => {
const
keyboard
= new
InlineKeyboard
().
text
("Back", "go_back");
await
ctx
.
editText
("Step 2: choose an option.", {
reply_markup
:
keyboard
,
}); await
ctx
.
answer
();
});
ts
// Direct API call — edit a specific message by chat_id + message_id
await 
bot
.
api
.
editMessageText
({
chat_id
: 123456789,
message_id
: 42,
text
: "Message has been updated.",
link_preview_options
: {
is_disabled
: true },
});

Errors

CodeErrorCause
400Bad Request: message is not modifiedNew text is identical to the current content — check before calling to avoid unnecessary requests
400Bad Request: message can't be editedMessage is too old, was sent by a different bot, or is not a text or game message
400Bad Request: TEXT_TOO_LONGtext exceeds 4096 characters — use the Split plugin for long content
400Bad Request: can't parse entitiesMalformed HTML/Markdown markup or mismatched tags — use GramIO's format helper to build entities safely
400Bad Request: chat not foundInvalid or inaccessible chat_id
400Bad Request: message not foundmessage_id doesn't exist in the chat
403Forbidden: bot was blocked by the userUser blocked the bot — catch and mark user as inactive
403Forbidden: not enough rightsBot lacks edit permissions in a channel
429Too Many Requests: retry after NFlood control — check retry_after, use auto-retry plugin

TIP

Use GramIO's auto-retry plugin to handle 429 errors automatically.

Tips & Gotchas

  • Text length is 1–4096 characters. Empty strings are rejected — unlike captions, text cannot be cleared. For content that might exceed the limit, use the Split plugin.
  • parse_mode and entities are mutually exclusive. GramIO's format helper always produces entities, so never pass parse_mode alongside a formatted string — doing so causes an error.
  • link_preview_options replaces the deprecated disable_web_page_preview. Use { is_disabled: true } to suppress link previews, or { url: "..." } to force a specific URL preview.
  • Business messages have a 48-hour edit window. Messages sent via a business connection by another user (not the bot) that lack an inline keyboard can only be edited within 48 hours of sending.
  • Inline messages return true, not Message. When editing via inline_message_id, the method returns true on success instead of the Message object. Narrow the type before accessing message properties.
  • ctx.editText() on CallbackQueryContext automatically uses the correct identifier — chat_id + message_id for regular messages, inline_message_id for inline query results.

See Also