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.
This commit is contained in:
tiennm99 committed 2026-06-28 22:18:28 +07:00
1 parent 8edd0f8c27
commit d4f1bbfc83
1 file changed
+10 -7
+10 -7
View File
@@ -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