From bd7a7fcedfde5a4e22dc7e12f4622e1c82eb49d2 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Sun, 28 Jun 2026 22:18:28 +0700 Subject: [PATCH] fix(server): clear Telegram webhook at startup before owner DM Move DeleteWebhook ahead of the deploynotify owner DM and polling so the webhook is cleared first thing once the bot is ready, instead of just before getUpdates. DropPendingUpdates=false keeps the lossless cutover. --- cmd/server/main.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 4b70537..e24db05 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -144,6 +144,15 @@ func main() { log.Warn("OWNER_ID unset; all Private + Protected commands will be denied") } + // Clear any webhook left over from the AWS deployment at startup, before the + // owner DM and before polling. getUpdates (long polling, below) returns HTTP + // 409 while a webhook is set. drop_pending_updates=false preserves Telegram's + // buffered queue so the poller drains updates that arrived during cutover + // (lossless cut). + if _, err := b.DeleteWebhook(rootCtx, &bot.DeleteWebhookParams{DropPendingUpdates: false}); err != nil { + log.Warn("deleteWebhook failed; getUpdates may 409 if a webhook is still set", "err", err) + } + deploynotify.Run(rootCtx, deploynotify.Config{ Bot: b, Store: deploynotify.NewStore(provider.Collection("deploynotify")), @@ -173,13 +182,7 @@ func main() { // Long polling is the sole Telegram transport (no webhook, no public // ingress). Telegram permits exactly one getUpdates consumer per bot token, - // so deploy exactly one replica. Clear any webhook left over from the AWS - // deployment first — getUpdates returns HTTP 409 while a webhook is set. - // drop_pending_updates=false preserves Telegram's buffered queue so the - // poller drains updates that arrived during cutover (lossless cut). - if _, err := b.DeleteWebhook(rootCtx, &bot.DeleteWebhookParams{DropPendingUpdates: false}); err != nil { - log.Warn("deleteWebhook failed; getUpdates may 409 if a webhook is still set", "err", err) - } + // so deploy exactly one replica. The webhook was cleared at startup above. go func() { log.Info("telegram long polling started") b.Start(rootCtx) // returns when rootCtx is cancelled