Repository navigation
feat(triggers): add contact blocked/unblocked the bot events for telegram - #1691
Merged
Merged
Conversation
…gram Telegram reports a block as a my_chat_member update in the private chat (bot status -> kicked) and an unblock as kicked -> member. The webhook now forwards the old status and the user, and the worker fires the new contactBlockedBot / contactUnblockedBot trigger and webhook events for the existing contact (never creating one), deduping Telegram retries in Redis. Older bots never deliver the update (subscribed before my_chat_member was added, or without a webhook secret), so a one-off script `pnpm --filter worker backfill:telegram-webhooks` re-registers every connected bot and gives secretless bots a secret token. Co-Authored-By: Claude Opus 5.5 <[email protected]>
hello-jackytruong
referenced
this pull request
in hello-jackytruong/ChatWorkAI
Nov 22, 2026
…gram (#1691) Telegram reports a block as a my_chat_member update in the private chat (bot status -> kicked) and an unblock as kicked -> member. The webhook now forwards the old status and the user, and the worker fires the new contactBlockedBot / contactUnblockedBot trigger and webhook events for the existing contact (never creating one), deduping Telegram retries in Redis. Older bots never deliver the update (subscribed before my_chat_member was added, or without a webhook secret), so a one-off script `pnpm --filter worker backfill:telegram-webhooks` re-registers every connected bot and gives secretless bots a secret token. Co-authored-by: Deathgiver <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
A customer asked for a trigger that fires when a contact blocks the Telegram bot.
Telegram already tells us: a block arrives as a
my_chat_memberupdate for theprivate chat (bot status goes to
kicked), an unblock askicked→member. Wereceived it but only fed it to the leaderboard group picker.
contactBlockedBot/contactUnblockedBot(webhook
contact_blocked_bot/contact_unblocked_bot, payload addschannel). Simple conditions, listed under a new Telegram group in theTriggers and Webhooks menus; the public API, CLI and MCP accept them through
allConditions; templates copy them as they are. All 21 locales translated.my_chat_member. The worker sends private chats totelegram-bot-block.ts:it fires only for an existing contact (never creates one, no MAC cost),
claims each update once in Redis so a Telegram retry does not fire twice, and
emits inside a channel-originated context so outbound webhooks deliver it.
Private chats are no longer written to
TelegramChat; groups are unchanged.not subscribed to
my_chat_member, and bots without a webhook secret havetheir audience updates dropped (an unverified one could fire forged
triggers).
apps/worker/scripts/reregister-telegram-webhooks.tsre-registersevery connected bot with the current
allowed_updatesand gives secretlessbots a secret: it calls
setWebhookfirst and saves the secret after, soupdates in between are still accepted. A bot that already has a secret keeps
it, revoked tokens are skipped, and the script is safe to re-run.
No migration. Docs:
docs/bot-block-trigger-events.md.Deploy notes
After deploying, run once:
It needs
NEXT_PUBLIC_BROKER_URLorNEXT_PUBLIC_BUILDER_URL, so it builds thesame webhook URL the builder registers on connect. It exits with code 1 if any
bot failed; re-run it to pick those up.
Limits
old updates.
from the trigger if needed.
Testing
pnpm lintand type checks for builder, worker, business, events, sdk,telegram, database pass. Full test suites for builder, worker, business,
events, sdk and telegram pass.
non-transition update, the group path, the webhook payloads, the condition
menu order, the public API schemas, template copy, and the re-register
script.
jsonb_setthat saves the secret was checked on Postgres: it keepssecretTextandbotId, createsmetadatawhen missing, and skips a botthat already has a secret.
that a "Contact blocked the bot → add tag" trigger runs, then unblock with
/start.
🤖 Generated with Claude Code