Telegram: edited messages go through processMessage, so they are dropped or answered twice instead of reaching onMessageUpdated

Open
#1,176 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
api, backend

Research direction

Start in packages/adapter-telegram/src/index.ts at collectUpdateTasks and handleIncomingMessageUpdate, then compare how the Slack and Teams adapters call processMessageUpdated. Route the three Telegram edit update types through that path and check the adapter tests for edit handling. Done means edits invoke onMessageUpdated without starting typing or being treated as new messages; the issue says a PR with tests and doc updates is already ready.

Written by the indexing model from the issue text.

Description

Hope you're doing well! On Telegram, an edited message is handled like a brand new message with the original message ID, so the Chat dedupe drops it within 10 minutes and answers it as a new message after that, and onMessageUpdated never fires.

What this code is for

collectUpdateTasks in packages/adapter-telegram/src/index.ts reads each Telegram update and decides where it goes: new messages to chat.processMessage, slash commands to chat.processSlashCommand, and business chats through handleBusinessMessageUpdate. Since #788, edits have their own path in core, chat.processMessageUpdated, which calls the onMessageUpdated handlers.

Current behaviour

A user in a group sends "can someone look at this", then edits it to "can someone look at this @mybot".

  1. Telegram sends an edited_message update with the same message_id and the new text.
  2. collectUpdateTasks picks it up in the same expression as new messages (update.message ?? update.edited_message ?? update.channel_post ?? update.edited_channel_post) and passes it to handleIncomingMessageUpdate (L1021-L1027).
  3. handleIncomingMessageUpdate starts typing in private chats and calls chat.processMessage (L1229-L1262).
  4. The message ID is encodeMessageId(chat.id, message_id) (L2888), the same ID the original message had.
  5. Core checks dedupe:telegram:${id}, which the original message set for 10 minutes (chat.ts L134, L2613-L2629), and skips the edit as a duplicate.
  6. The bot never sees the mention, and onMessageUpdated is never called.

edited_business_message goes the same way. It sets isEdit, but that only skips slash commands, and the edit still starts typing and reaches chat.processMessage (L1077-L1081, L1212-L1226).

collectUpdateTasks calling handleIncomingMessageUpdate

collectUpdateTasks hands edits to handleIncomingMessageUpdate, which starts typing and parses them as new messages, Functions view in Architect

Expected behaviour

edited_message, edited_channel_post, and edited_business_message go to chat.processMessageUpdated, the way Slack's message_changed and Teams' editMessage do. Telegram only sends the new version, so previousMessage would be undefined. An edit wouldn't start typing or run a slash command.

Minimal repro

I ran this on main (990411e) with a real Chat, createMemoryState(), and createTelegramAdapter, posting updates to bot.webhooks.telegram:

  1. A group message "hello all", then an edited_message for the same message_id that adds @mybot with a mention entity: no handler runs.
  2. A private message "hi", then an edited_message "hi there" within 10 minutes: onDirectMessage runs once for "hi", and the edit is dropped.
  3. The same private edit sent after the dedupe entry expires: onDirectMessage runs again, so the bot answers a second time.
  4. In both edit cases a sendChatAction typing call goes out, and onMessageUpdated never fires.
flowchart LR

classDef box fill:#eef1ff,stroke:#4c5bd4,color:#111827
classDef bad fill:#ffd6d6,stroke:#cc0000,color:#111827,stroke-width:3px

U["edited_message or edited_channel_post"] --> C["collectUpdateTasks"]
BZ["edited_business_message"] --> BH["handleBusinessMessageUpdate"]
C --> H["handleIncomingMessageUpdate"]
H --> T["startTypingForPrivateMessage"]
BH --> T
H --> P["chat.processMessage"]
BH --> P
P --> D{"dedupe key already set?"}
D -->|"within 10 minutes"| X["edit dropped"]
D -->|"after 10 minutes"| Y["handled as a new message"]

class U,BZ,C,BH,H,T,P box
class D,X,Y bad
Prior work

#788 added processMessageUpdated and mentioned that other adapters could opt in later, #1120 did that for Teams, and #887 asked for business edits to use the message updated path. Thanks to everyone who worked on those, they made this one really easy to follow. apps/docs/content/docs/handling-events.mdx (L329) still says only Slack emits these events, which is out of date since #1120.

A couple of questions
  • Would you like edited_business_message included in the same change, as #887 suggested? I assumed yes.
  • Is it OK to skip the typing indicator for edits? It felt right since nothing is being replied to yet, but happy to keep it if you'd prefer.

I have a PR ready that routes all three edit kinds this way, with tests and doc updates, and I'm glad to change anything. Any feedback or tips are very welcome!

Dominant language
TypeScript
Stars
2.5k
Forks
355
Avg merge
2d 15h
Merged PRs (30d)
42

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel/chat

All issues in vercel/chat

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.