// Package telegram constructs the go-telegram bot client used for long // polling and holds the few raw Bot API calls the library does not make // reliably (see DeleteWebhook). package telegram import ( "github.com/go-telegram/bot" ) // pollingAllowedUpdates restricts getUpdates to the update kinds the modules // actually handle: text commands, inline-keyboard callbacks, and inline-mode // queries. Anything else (channel posts, edited messages, etc.) is dropped // server-side by Telegram. // // This list is a hard gate, not an optimisation. Telegram filters on its side, // so a handler for a kind missing here is never called and leaves no trace — // no log line, no error, nothing to debug from. Any module that starts handling // a new update kind must add it here in the same change. var pollingAllowedUpdates = bot.AllowedUpdates{"message", "callback_query", "inline_query"} // NewBot constructs a Telegram bot for long-polling mode (the sole transport // on self-host — b.Start runs the getUpdates loop in cmd/server): // // - WithSkipGetMe: avoid a blocking GetMe call at startup. Token validity // surfaces on the first outgoing API call instead. // - WithNotAsyncHandlers: handlers run synchronously on the library's single // update worker instead of one goroutine per update. That bounds in-flight // work to one update at a time, which suits the single-replica polling // deployment; the cost is that a slow handler delays every update queued // behind it. // - WithAllowedUpdates: only request the update kinds the bot handles. // // Callers may pass extra options that override these defaults. func NewBot(token string, opts ...bot.Option) (*bot.Bot, error) { defaults := []bot.Option{ bot.WithSkipGetMe(), bot.WithNotAsyncHandlers(), bot.WithAllowedUpdates(pollingAllowedUpdates), } return bot.New(token, append(defaults, opts...)...) }