telegram-bot-api/updates.go

36 lines
715 B
Go
Raw Normal View History

package tgbotapi
2015-06-29 18:04:48 +02:00
import (
"log"
"time"
)
// 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 {
2015-06-29 18:04:48 +02:00
if bot.Debug == true {
panic(err)
} else {
log.Println(err)
2015-06-30 05:28:55 +02:00
log.Println("Fail to GetUpdates,Retry in 3 Seconds...")
2015-06-29 18:04:48 +02:00
time.Sleep(time.Second * 3)
}
} else {
for _, update := range updates {
if update.UpdateID >= config.Offset {
config.Offset = update.UpdateID + 1
bot.Updates <- update
}
}
}
}
}()
return bot.Updates, nil
}