2015-06-26 06:26:24 +02:00
|
|
|
package tgbotapi
|
|
|
|
|
2015-06-26 08:19:29 +02:00
|
|
|
// Returns a chan that is called whenever a new message is gotten.
|
2015-06-26 06:26:24 +02:00
|
|
|
func (bot *BotApi) UpdatesChan(config UpdateConfig) (chan Update, error) {
|
|
|
|
bot.Updates = make(chan Update, 100)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
updates, err := bot.GetUpdates(config)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, update := range updates {
|
|
|
|
if update.UpdateId > config.Offset {
|
|
|
|
config.Offset = update.UpdateId + 1
|
|
|
|
}
|
|
|
|
|
|
|
|
bot.Updates <- update
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return bot.Updates, nil
|
|
|
|
}
|