Repository navigation
feat(messages): edit a sent message with tg messages edit - #187
Open
ertembiyik wants to merge 17 commits into
Open
ertembiyik wants to merge 17 commits into
ertembiyik wants to merge 17 commits into
Conversation
tg messages edit --chat <peer> --id <id> --message <text> replaces the text of a message, or the caption of a message with a file, through messages.editMessage. It prints the edited message as tg messages get does and stores it in the cache at once, so search follows without a daemon. Telegram's refusals are TELEGRAM_ERROR with the reason in details.telegramError. Read-only mode refuses the command and allowedChats applies. Refs neoromantic#23 Co-Authored-By: Claude Fable 5.2 <[email protected]>
main now has neoromantic#178 (neoromantic#186) and neoromantic#179 (neoromantic#188). No conflict. Co-Authored-By: Claude Fable 5.2 <[email protected]>
main is now the 0.14.0 release (neoromantic#189). This PR's changelog entries move back under Unreleased: a plain merge left them in the released section. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This was referenced Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. README and CHANGELOG: both sides kept. main dropped MessagesHistory.getMany (neoromantic#174): the item is read with get. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155). Co-Authored-By: Claude Fable 5.2 <[email protected]>
main now has neoromantic#195: Knip in bun run check, and long as a runtime dependency. No conflict; the check is clean. Co-Authored-By: Claude Fable 5.2 <[email protected]>
main now has neoromantic#196, a test time budget only. No conflict; the check is clean. Co-Authored-By: Claude Fable 5.2 <[email protected]>
README, access.ts and messages.ts conflicted only with main's oxfmt reformat and were resolved by keeping main's code with this branch's edit lines; the edit's e2e, unit and integration tests and its fake-client and access additions moved to main's colocated layout (src/test/*, *.test-utils.ts, edit-message.test.ts beside its module). The merge also brought the code under main's oxlint/landmines rules (no prose comments, inferred return types), reused createAccountCacheDb and raised the integration file's allowed raised-timeout count to 8. Co-Authored-By: Claude Fable 5.2 <[email protected]>
messages.editMessage takes the same rich_message field as messages.sendMessage, so tg messages edit takes the same two flags as tg send. The flag parsing, the request part and the hints for RICH_MESSAGE_* refusals move to one module that both commands use. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Telegram accepts messages.editMessage with rich_message for a message that holds a file, then stores neither the rich text nor the caption the message had. A rich edit now reads the message first and refuses with INVALID_ARGS when it has an attachment other than a link preview. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The check went through the media classifier, which gives nothing for an expired photo or file, a giveaway or media this version doesn't know, so a rich edit of such a message still reached Telegram. It now refuses whenever the message has media other than a link preview. The fake client answers a rich edit as Telegram does (empty text, the blocks in richMessage) and answers channels.getMessages, so the tests cover the cached text of a rich edit, the way back to plain text and a supergroup. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…chat The response was matched by message ID alone, so an edit of the same ID in another chat carried by the same response would have been stored under the chat that was named. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ssages-edit # Conflicts: # CHANGELOG.md # src/commands/send.ts # src/test/fake-client-cli.test-utils.ts
Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ssages-edit # Conflicts: # CHANGELOG.md
…ssages-edit # Conflicts: # CHANGELOG.md # README.md # src/test/fake-client-cli.test-utils.ts Co-Authored-By: Claude Fable 5.2 <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
tg messages edit --chat <peer> --id <id> --message <text>replaces the text of a message you sent, or the caption of a message with a file. It is the edit part of #23, with the command shape that issue proposes. Refs #23The need: fixing a sent message meant a raw
tg api messages.editMessagecall with a hand-built input peer, and the cache kept the old text until a daemon or a--freshread replaced it.Before (0.13.1; 0.14.0 is the same here)
After (real output of the e2e fake: Alice's chat, message 12 was "See you at nine.")
(
chatandsenderare folded onto one line here; nothing else is changed.)A refusal says what is wrong. Message 14 is Alice's:
messageMESSAGE_NOT_MODIFIEDMessage 12 already has this textMESSAGE_ID_INVALIDTelegram has no message 12 in this chat that can be editedMESSAGE_AUTHOR_REQUIREDYou can't edit message 12: it was sent by someone elseMESSAGE_EDIT_TIME_EXPIREDMessage 12 is too old: Telegram no longer allows editing itMESSAGE_TOO_LONG,MEDIA_CAPTION_TOO_LONGThe text is too long for a message/… for the caption of a media messageCHAT_WRITE_FORBIDDEN,CHAT_ADMIN_REQUIREDYou do not have permission to edit messages in this chatAny other failure goes through
reportHistoryError, as fortg messages read.How it works
messages.editMessagewith the peer, the ID and the text.--chatresolves as it does fortg messages getandread.updateEditMessageorupdateEditChannelMessage) is written tomessages_cache, as tg send doesn't add the sent message to the cache #19 does fortg send, and read back as the itemtg messages getprints. Sotg messages searchfinds the new text, and no longer the old, without a daemon.COMMAND_ACCESSmarks itwritewithchatArgs: ['chat']: read-only mode refuses it before it connects, andallowedChatsapplies. The access e2e tests pick both up from the table.--idmust be a message ID, and an empty--messageisINVALID_ARGS.Decisions you may want to change:
editedis alwaystrueandmessagecan benull. If the response holds no message, or the cache write fails, the edit is still done, so the command succeeds andmessageisnull.MESSAGE_NOT_MODIFIEDis an error, not a quiet success: this call changed nothing.--markdownand--htmlmake it a rich message (see the update below).details.telegramErroris a new detail key, the error's name;tg apialready hasdetails.telegramErrorCodefor the number.-mis an alias of--message, as intg send.Left out, on purpose:
mediaofmessages.editMessage), and removing a caption.The shared fake client (
src/__e2e__/helpers/fake-client-cli.ts) now answersmessages.editMessage. This touchessrc/commands/access.ts,src/commands/messages.ts, README and CHANGELOG, as #183 does; I'll rebase whichever lands later.Update:
mainmerged in (5443e73)mainmoved to oxfmt and oxlint with the landmines rules, and moved every test beside its code. This branch follows: the same behaviour and output, the code restyled, prose comments and explicit return types removed.src/test/messages-edit.e2e.test.tsandsrc/commands/messages/edit-message.test.ts; the fake client issrc/test/fake-client-cli.test-utils.tsand the live step is insrc/test/telegram.integration.test.ts. Paths and totals elsewhere in this description predate the move..oxlintrc.json: the allowed count of raised timeouts insrc/test/telegram.integration.test.tsgoes from 7 to 8, for the live step this PR adds. Each of feat(messages): edit a sent message with tg messages edit #187, feat(messages): delete messages with tg messages delete #190, feat(messages): forward messages with tg messages forward #191 and feat(messages): pin and unpin a message with tg messages pin and unpin #192 does this, so the count needs one more per PR that lands.bun run checkclean (format, lint, types, Knip),bun run test1206 pass,bun run test:e2e348 pass, 0 fail. Totals are lower than before becausemainmerged and removed many tests.Update:
--markdownand--html(377c39e, 24b005f, e96dfc5)#175 is on
main, so the edit command takes the same two flags astg send:$ tg messages edit --chat @alice --id 12 --markdown -m "# Plan"messages.editMessagetakesrich_messageexactly asmessages.sendMessagedoes; there is no separate method for rich edits. With a flag the request carriesrichMessage(inputRichMessageMarkdownorinputRichMessageHTML) and nomessage; without one it is the plain request as before.formatin the result:markdown,html, ornullfor plain text, as intg send.messages.getMessagesorchannels.getMessages, one more request, only with a flag) and givesINVALID_ARGS(exit 3) when it has any media other than a link preview, including kinds the cache can't classify (an expired photo or file, a giveaway, media this version doesn't know). This matches the Bot API, whereeditMessageTexttakesrich_messageandeditMessageCaptiondoes not. A text message with a link preview becomes rich; a plain edit of a caption works as before.INVALID_ARGS(exit 3) before the network. ARICH_MESSAGE_*refusal isTELEGRAM_ERRORwith the name indetails.telegramErrorand the samesuggestiontg sendgives.RICH_MESSAGE_*hints moved fromsrc/commands/send.tstosrc/commands/send/rich-message.ts;tg sendbehaves as before.richMessage. Each new test fails when its behaviour is broken (checked by breaking the cache fallback, the media rule and the channel lookup in turn).bun run checkclean,bun run test1213 pass,bun run test:e2e352 pass, 0 fail.messages.getMessageseach time and deleted after:richMessagewith those blocks,editDateset, the cached text is the blocks as Markdown;MESSAGE_NOT_MODIFIED; markup with no content:RICH_MESSAGE_EMPTYwith its suggestion;INVALID_ARGS, the caption intact; a plain edit of the caption works;How I checked it
E2E with the fake client (8 tests): the text replaced, printed and stored; the new text searchable and the old one not; a supergroup (
updateEditChannelMessage) and Saved Messages; a message the cache didn't hold; a refusal with the cached message left as it was; an empty text and a bad--idrefused offline; no credentials. The access suite adds read-only andallowedChatsrefusals for the new command from the table.Unit tests (11): the request, each refusal in the table above, other Telegram errors passed on with the unknown-chat hint, and a response without a message.
Live, by hand, on a personal account in Saved Messages: sent one message with a bold entity through
tg api, edited it with this command, and read it back withmessages.getMessages: the new text,editDateset, the bold entity gone. The same text again gaveMESSAGE_NOT_MODIFIEDwith the message above.tg messages getwithout--freshandtg messages searchshowed the new text. Then deleted the message.A step in the live smoke suite (
src/__integration__/): send to Saved Messages, edit, check Telegram and the cache. Written, not run: I have no test session.Not verified live: a supergroup or channel, a caption, and the refusals other than
MESSAGE_NOT_MODIFIED.bun run check: clean.bun run test: 2334 pass, 0 fail.bun run test:e2e: 460 pass, 0 fail.Tests pass locally and use made-up data only
README, docs and affected demos follow the product content standard (
docs/cli-commands.md,docs/configuration.md,docs/api-design.md, README, CHANGELOG)Title follows the repo's commit style: Conventional Commits (
feat: …,fix: …) unlessAGENTS.mdsays otherwiseUpdate: second code review (b22fbfb)
A second, independent review of this branch. Each point below was first shown by a failing test, then fixed.
mainthat the review also pointed at, unchanged here: the access guard and the command resolve the account and the chat separately; a cached username can outlive its owner; flags a command does not declare are ignored; the activity log write after a successful request can turn it into a failure.After these commits:
bun run checkclean,bun run test1214 pass,bun run test:e2e352 pass, 0 fail.Update:
mainmerged in (649eef9)mainup to #220 merged in, no conflicts. One follow-up commit (84d1019): the command acts on the chat theallowedChatscheck resolved (checkedChat), astg sendandtg messages readdo since #220. No test of its own: the handoff is tested onmainfortg send; here the command's e2e file was run once by hand withallowedChatsset, and every case whose chat was in the list passed.After the merge:
bun run checkclean,bun run test1225 pass,bun run test:e2e353 pass, 0 fail.Update:
mainmerged in (853a651)mainup to 0.15.1 and #232 merged in. Conflicts:CHANGELOG.md(the entry of this PR now sits under the new## [Unreleased]),src/commands/send.tsand the fake client of the e2e tests.edit-message.tsimports its types withimport typeand readsRpcErrorthroughawait import();src/cli.test.tspasses.@usernamethrough Telegram, not the cache (freshUsername), astg sendandtg messages readdo since fix(send): resolve @username through Telegram for writes #222, so a username that moved never edits a message of its previous owner.After the merge:
bun run checkclean,bun run test1237 pass,bun run test:e2e379 pass, 0 fail.Update:
mainmerged in (ac85803)mainup to 0.15.2 (#234) merged in. One conflict:CHANGELOG.md(the entry of this PR stays under## [Unreleased], above the new 0.15.2 section). No code change in this PR.After the merge:
bun run checkclean,bun run test1237 pass,bun run test:e2e379 pass, 0 fail.Update:
mainmerged in (392c8d8)No changes beyond the conflicts in
CHANGELOG.md,README.mdandsrc/test/fake-client-cli.test-utils.ts. Checks:bun run checkclean, unit 1357 pass, e2e 452 pass, 0 fail.🤖 Generated with Claude Code