feat: forward albums as a single grouped batch#12
Merged
Conversation
Telegram delivers an album (media group) as separate messages sharing a groupedId, so each part was forwarded individually and reached the target as loose messages. Enable mtcute's messageGroupingInterval so a whole album arrives as one message_group update, and forward the unit in a single forwardMessages call that keeps the grouped layout. - route onNewMessage and onMessageGroup through one handler; with grouping enabled album messages are dispatched ONLY as message_group, so both subscriptions are required to see every message - match keywords per unit: an album's caption lives on one message but speaks for the whole post (exclude on any part drops the unit) - keep content-type filtering per message; the matching subset is still batched and stays an album at the target - salvage the surviving parts when an album member is deleted between matching and sending, instead of losing the whole batch to MESSAGE_ID_INVALID - singles are unaffected; an album waits at most 250 ms (upstream recommendation) and now needs one API call instead of N rate-limited sends, finishing sooner than before
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.
Summary
Telegram delivers an album (media group) as separate messages sharing a
groupedId, so each part was forwarded individually and reached the target as loose messages. This PR enables mtcute'smessageGroupingIntervalso a whole album arrives as onemessage_groupupdate, and forwards the unit in a singleforwardMessagescall that keeps the grouped layout at the target.Changes
src/client.ts— enableupdates.messageGroupingInterval: 250(upstream-recommended value). Singles are unaffected; an album waits at most 250 ms before forwarding.src/forwarder.ts— routeonNewMessageandonMessageGroupthrough one handler. With grouping enabled, album messages are dispatched only asmessage_group, so both subscriptions are required to see every message. Matching is wrapped so an unexpected error is logged with message ids instead of silently dropping the unit.src/filter.ts—matchesKeywordsnow evaluates a whole unit: an album's caption lives on one message but speaks for the entire post (include satisfied by any part; exclude on any part drops the unit).MESSAGE_ID_INVALIDfor the whole album; the forwarder now re-fetches the batch and retries with the surviving parts instead of losing them.isDeletedMessageErroris exported fromqueue.tsso both layers share one classification.Performance / behavior notes
catchUpwas deliberately not enabled: mtcute documents it can replay duplicate updates after an unclean shutdown, i.e. double-forwards.Testing
pnpm typecheck/pnpm lint/pnpm test(75 passed) /pnpm build/pnpm knip/pnpm format:checkall green.