Nodes/ComfyUI Autonomous Telegram Bot/TG Edit Message Image ◀️
ComfyUI Node

TG Edit Message Image ◀️

Replace the picture in a message you already sent

By CoolBreeze164·Created 13 days ago·Updated 2 days ago· 3
TG Edit Message Image ◀️
  • IMAGE
  • trigger
  • message
  • message_id
  • trigger
◄bot_token►
◄chat_id—►
◄message_id—►
◄caption►
◄parse_mode▾►
◄show_caption_above_mediafalse►
◄file_nameimage►
◄format▾►
◄as_filefalse►

A low-res draft, then the refined pass, in the same bubble. That's the sales pitch for this one. Your bot posts a quick 12-step preview, the user reacts, the hires fix finishes, and the message updates in place instead of the chat filling up with near-identical pictures.

It's the media counterpart to Edit Message Text, and it's built differently underneath: rather than editing a text field, this calls editMessageMedia with a whole new media object attached.

Sending a replacement, not a new photo

The node encodes your IMAGE through Pillow into the format you chose (PNG by default; WEBP and JPG are the other options), uploads those bytes as a new file, and tells Telegram to swap them into the existing message. The new media object carries its own caption, parse_mode and show_caption_above_media, so you can change the caption in the same call.

It uses the first image of the batch, and only the first. Send Image(s) will happily post ten; this editor takes images_to_bytes(IMAGE, format)[0] and moves on. If you feed it a batch expecting the last frame or the whole set, you'll be editing in the wrong picture and wondering why.

as_file changes the media type from photo to document - the same compression escape hatch the sender has. Note the caption field is still sent along, and Telegram applies its usual caption rules to documents too.

Inputs

bot_token, chat_id and message_id. And that message_id has to be the ID of a message your bot sent - take it from Send Image(s) message_id, not from the Listener, whose message_id is the user's message and will get you a hard API error.

IMAGE is the replacement picture, format picks PNG/WEBP/JPG, file_name names the attachment (default image). caption is 0–1024 characters, parse_mode is None/HTML/Markdown/MarkdownV2. show_caption_above_media moves the caption over the image. trigger is the untyped ordering input - wire it from the sender, because "edit a message that doesn't exist yet" is the natural failure of an unordered graph.

Outputs

message (Telegram's response DICT for the edited message), message_id (the same ID, chainable), trigger (passthrough). On a failure that survives the pack's five retry attempts, message and message_id come back as silent blockers so nothing downstream tries to edit a stale ID - and the workflow still finishes, which matters a lot under Run (Instant).

The trap nobody expects

Sends and edits are not equally forgiving. Telegram's media-replacement endpoint is fussier about what it considers a valid swap than its text-edit endpoint is - and this pack classifies a Telegram 400 as a permanent error that isn't retried, so it raises out of the node and becomes a ComfyUI execution error. That's the one class of problem here that will stop your Run (Instant) loop dead rather than quietly skipping a reply.

Practical version: if you're replacing an image with an image, you're fine. If you're using this node as a general "change what's in this message" tool and the recipient message was something else entirely, expect an error rather than magic. Check the console log - it names the Telegram method and description.

Also worth flagging: this node re-encodes the pixels it sends, so the replacement carries no ComfyUI workflow metadata. Your outgoing images stay clean; it's the video editors that don't.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/CoolBreeze164/ComfyUI-Autonomous-Telegram-Bot
python -m pip install -r ComfyUI-Autonomous-Telegram-Bot/requirements.txt

python_embeded\python.exe for the pip step on Windows portable. Needs httpx, numpy, pillow (that's the encoder here) and av>=14.2.0. Manager route: search ComfyUI Autonomous Telegram Bot, install, restart. Find it under Autonomous Telegram Bot ◀️/edit.

Common issues

  • Wrong image replaced / nothing changed visually - make sure your IMAGE socket is the one picture you meant, not the head of a batch.
  • Errors about not being able to edit the message - the message_id didn't come from a sender, or the chat ID doesn't match the message's chat.
  • Posterised or banded result - JPG at a low quality footprint; switch format to PNG, or as_file to skip Telegram's photo re-encode.
  • Edit runs before the send - trigger, and a chat_id/message_id pair that actually flow from the sender's outputs.
  • Timing out on a big image - media uploads get a longer 120-second read allowance per attempt, five attempts total; a 6 MB PNG over a bad connection is the usual reason a reply feels late.
CategoryAutonomous Telegram Bot ◀️/edit

Inputs (11)

NameTypeDefaultDescription
bot_tokenSTRINGTelegram bot token from BotFather
chat_idINTUnique identifier for the target chat
message_idINTUnique Identifier of the message to edit
IMAGEIMAGEthe image(s) to send
captionSTRINGMedia caption, 0-1024 characters after entities parsing
parse_modeCOMBOMode for parsing entities in the photo caption. See https://core.telegram.org/bots/api#formatting-options for more details.
show_caption_above_mediaBOOLEANfalsePass True, if the caption must be shown above the message media
file_nameSTRINGimagethe file name for this media
formatCOMBOimage format
as_fileBOOLEANfalsePass True to send the media as file without compression
triggeropt*Optional trigger to enforce execution order

Outputs (3)

NameTypeDescription
messageDICT—
message_idINT—
trigger*—