telegram-bot-api/updates.go

25 lines
508 B
Go
Raw Normal View History

package tgbotapi
// UpdatesChan returns a chan that is called whenever a new message is gotten.
func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) {
bot.Updates = make(chan Update, 100)
go func() {
for {
updates, err := bot.GetUpdates(config)
if err != nil {
panic(err)
}
for _, update := range updates {
2015-06-27 04:20:32 +02:00
if update.UpdateID >= config.Offset {
config.Offset = update.UpdateID + 1
2015-06-27 04:20:32 +02:00
bot.Updates <- update
}
}
}
}()
return bot.Updates, nil
}