Closed Borzoff closed 3 months ago
Hello, how to handle the moment when the token stops working while Polling is already running
I want to handle the moment when the token revoke
func startBot(token string, wg *sync.WaitGroup) { defer wg.Done() bot, err := gotgbot.NewBot(token, nil) if err != nil { if strings.Contains(err.Error(), "Unauthorized") { log.Printf("Invalid token for bot: %s", token) return } log.Printf("Failed to create a bot with the token %s: %v", token, err) return } dispatcher := ext.NewDispatcher(&ext.DispatcherOpts{ // If an error is returned by a handler, log it and continue going. Error: func(b *gotgbot.Bot, ctx *ext.Context, err error) ext.DispatcherAction { log.Println("an error occurred while handling update:", err.Error()) return ext.DispatcherActionNoop }, MaxRoutines: ext.DefaultMaxRoutines, }) dispatcher.AddHandler(handlers.NewCommand("start", handler.Start)) updater := ext.NewUpdater(dispatcher, nil) err = updater.StartPolling(bot, &ext.PollingOpts{ DropPendingUpdates: true, GetUpdatesOpts: &gotgbot.GetUpdatesOpts{ Timeout: 9, RequestOpts: &gotgbot.RequestOpts{ Timeout: time.Second * 10, }, }, }) if err != nil { log.Printf("Не удалось запустить polling для бота с токеном %s: %v", token, err) } log.Printf("%s bot launched", bot.User.Username) updater.Idle() }
go version
go.mod
Found one of the options: Pass the UnhandledErrFunc parameter to Updater and process it there
Description of the problem / feature request
Hello, how to handle the moment when the token stops working while Polling is already running
Feature requests
I want to handle the moment when the token revoke
Bugs
System information:
go version
: go1.21.0 windows/amd64go.mod
file): v2.0.0-rc.28