Edits a message you already sent. The updated message comes back with "status": "updated".

💡 Send only the field matching the message's type — text for a text message, caption for media. You cannot change a message from one type to another.


Request

method is "updateMessage".

Field Type Required Description
message_id String Yes The message you want to edit.
chat_id String Yes The chat or user the message is in.
app_id String Yes The app the message belongs to.
reference Long Yes Your local id for this request. Echoed back in messageAck.
text String Conditional New body — for text messages only.
caption String Conditional New caption — for any media message (photo, video, audio, document…).
menu_ref String Optional Swap the attached menu. Set to an empty string to remove the inline menu.
inline_menu Array of Menu Optional Replace the attached menu inline. Wins over menu_ref unless menu_ref is an empty string.

Replacing media

To swap the media itself, send the field matching the original type. Each takes the same shape it had when the message was sent.

Field Use when the message type is
photo · gif · video · audio · voice · document The matching media type
text_file text_file
sticker sticker
location location
contact contact
article • url article — must be a nandbox article

Preconditions

Requirement Needed for
"Update Message" permission Editing any message.
Chat type Your API must be
--- ---
User chat Started by the user, and the original sender of the message
Group An admin
Channel An admin

Response

When Method What it tells you
Always messageAck The edit was accepted. Carries "status": "updated".
Always message The message as it now stands, also carrying "status": "updated".

SDKs

SDK Call Callback
Java api.updateMessage(messageId, text, caption, toUserId, chatId, appId); onMessagAckCallback(MessageAck msgAck)
JavaScript api.updateMessage(messageId, text, caption, toUserId, chatId, appId); onMessagAckCallback(msgAck)
Python napi.update_message(message_id=message_id, text=text, caption=caption, to_user_id=to_user_id, chat_id=chat_id, app_id=app_id) on_message_ack_callback(self, msg_ack)

There are shorthands for the common cases:

Goal Java / JavaScript Python
Edit text in a user chat api.updateTextMsg(messageId, text, toUserId, appId) napi.update_text_msg(...)
Edit a caption in a user chat api.updateMediaCaption(messageId, caption, toUserId, appId) napi.update_media_caption(...)
Edit text in a group or channel api.updateChatMsg(messageId, text, chatId, appId) napi.update_chat_msg(...)
Edit a caption in a group or channel api.updateChatMediaCaption(messageId, caption, chatId, appId) napi.update_chat_media_caption(...)

Example

Request

{
  "method": "updateMessage",
  "message_id": "d1_cdbTJTTV126179",
  "chat_id": "90090684438172188",
  "text": "Hello World!",
  "reference": 111111171,
  "app_id": "90090684293000559"
}