Repository navigation
Conversation
A Telegram bot has one webhook, and anything holding its token can replace it with one call. Telegram tells nobody: updates simply go elsewhere and our ingress route sees silence, not errors. In production a second app re-registered a shared bot's webhook and the inbox missed six days of messages unnoticed. Every ten minutes the API now asks Telegram (getWebhookInfo) where each connected bot delivers. If the URL is not under our ingress prefix, or no webhook is set, the account is marked error with provider_status webhook_taken_over or webhook_missing, and owners and admins get an in-app notification and an email. The card on Connections explains it and offers Reconnect, which is the existing resume call and registers our webhook again. - Only a successful Telegram answer changes anything; network errors, revoked tokens and unreadable credentials are logged and skipped. - The mark is conditional on the account still being connected with the same connected_at, so a reconnect during the check is never overwritten, and only one API replica alerts. - A flagged account is no longer connected, so it is not re-checked and the alert is not repeated. - channelIngressBaseUrl moves to lib/channel-ingress-url.ts so the route and the watch share one definition of our URL.
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.
Problem
A Telegram bot has exactly one webhook, and anything holding its token can replace it with a single
setWebhookcall. Telegram tells nobody: updates simply go somewhere else, and our ingress route sees silence, not errors.In production (2026-11-20 → 11-26), another app that shared a workspace's bot token re-registered its own webhook. The inbox missed six days of customer messages, and nothing on our side noticed: no failed requests, no errors, no alert.
Fix
Every 10 minutes (first check 1 minute after start) the API asks Telegram
getWebhookInfofor each connected Telegram bot in workspaces with Telegram enabled.CHANNEL_INGRESS_PUBLIC_URL || APP_URL+/api/channel-ingress/telegram_bot/), the account is markedstatus = error,provider_status = webhook_taken_over.webhook_missing.POST /channel-accounts/:id/resumecall, which already accepts any account that is not connected and registers our webhook again with a fresh route key and secret.Safety
connectedwith the sameconnected_atit had when checked. A reconnect that lands while Telegram is being asked is left alone. The same condition means only one API replica flips the row and sends the alert.connected, so later cycles skip it until someone reconnects.app.example.com.evil.test/...) still fails the prefix check, and there's a test for it.channelIngressBaseUrlmoved tolib/channel-ingress-url.ts, so the connect/resume routes and the watch share one definition of our URL.Tests
packages/adapter-telegram:getTelegramWebhookInforeturns the URL and pending count, handles an empty URL, and rejects malformed answers.telegram-webhook-watch.integration.test.ts(9 tests): classification (ours, foreign, lookalike, removed). A healthy bot is untouched. A taken-over bot is marked and only the owner is alerted, once; the next cycle does not ask again. A removed webhook is marked. An unreachable Telegram changes nothing. A reconnect during the check is not overwritten.Release
No migration. API and web change;
worker: skip.