Repository navigation
feat: add group history backfill and offline auto-reply - #42
Merged
williamcachamwri merged 2 commits intoJun 14, 2026
Merged
Conversation
Add two Telegram commands and harden startup against Zalo rate limits. - /history [N]: backfill recent GROUP chat history into the current topic via getGroupChatHistory, replayed through the existing message pipeline so already-synced messages dedupe themselves. DM topics are rejected because Zalo exposes no 1-1 history API. - /autoreply on|off|status: bridge-level offline auto-reply for DMs. Implemented locally (new src/zalo/autoReply.ts) instead of zca-js createAutoReply, which is zBusiness-only and fails on personal accounts. State persists to data/autoreply.json. Anti-ban hardening: - Auto-reply answers DMs only, with a 30-min per-peer cooldown, a global cap of 12 replies/hour, and a randomized 3-8s human-like delay (never instant). - Fix startup member-cache warmup that fired every getGroupInfo/getUserInfo call at once (setTimeout 0 despite a "2s stagger" comment); it is now serialized with a real 2s gap to avoid tripping Zalo's rate limiter (code 221). Register both commands in the Telegram command menu.
- /history: replay messages by awaiting the live handler one-by-one (new replayHistoryMessages) instead of fire-and-forget listener.emit, so ordering is preserved even for slow media; skip poll messages so a replayed poll-create event can't spawn a duplicate live Telegram poll. - auto-reply: only answer text DMs (gate on msgType) so stickers/media don't get a canned reply; suppress the Zalo self-echo via sentMsgStore so the reply is not re-forwarded into the Telegram topic. - auto-reply rate limiting: track global-cap reservations by unique id so a failed send can no longer drop another reply's slot when timestamps collide; on send failure keep the per-peer cooldown (don't hammer a failing peer) and release only this reservation. - /autoreply confirmation: derive the cooldown/cap numbers from the exported constants instead of a hardcoded "10 phút" that disagreed with the 30-min value. - startup: stop marking all group topics "loaded" up-front so the lazy per-message warmup can win during the 2s-staggered backfill; messages in not-yet-warmed groups now resolve member names instead of hitting an empty cache.
Contributor
Author
|
Correctness
Anti-ban rate limiting
Misc
Two review notes were intentionally left as-is:
|
Owner
|
I will test it. |
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.
Add two Telegram commands and harden startup against Zalo rate limits.
Anti-ban hardening:
Register both commands in the Telegram command menu.