telegram-bot-api/updates.go

38 lines
657 B
Go
Raw Normal View History

package tgbotapi
2015-06-29 18:04:48 +02:00
import (
"log"
"time"
)
// UpdatesChan starts a channel for getting updates.
func (bot *BotAPI) UpdatesChan(config UpdateConfig) error {
bot.Updates = make(chan Update, 100)
go func() {
for {
updates, err := bot.GetUpdates(config)
if err != nil {
if bot.Debug {
2015-06-29 18:04:48 +02:00
panic(err)
} else {
log.Println(err)
log.Println("Failed to get updates, retrying in 3 seconds...")
2015-06-29 18:04:48 +02:00
time.Sleep(time.Second * 3)
}
continue
}
for _, update := range updates {
if update.UpdateID >= config.Offset {
config.Offset = update.UpdateID + 1
bot.Updates <- update
}
}
}
}()
return nil
}