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