all repos — telegram-bot-api @ f6cf1bb7824bd6bdb3f30e7932c10f653d5e27b1

Golang bindings for the Telegram Bot API

should not panic in production env
Jqs7 7@jqs7.com
Tue, 30 Jun 2015 00:04:48 +0800
commit

f6cf1bb7824bd6bdb3f30e7932c10f653d5e27b1

parent

7b9b7856fc1005a6d04f039704c70aee26d50ade

1 files changed, 19 insertions(+), 7 deletions(-)

jump to
M updates.goupdates.go

@@ -1,5 +1,10 @@

package tgbotapi +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)

@@ -8,15 +13,22 @@ go func() {

for { 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 + if bot.Debug == true { + panic(err) + } else { + log.Println(err) + log.Println("Retry in 3 Seconds") + time.Sleep(time.Second * 3) + } + } else { + for _, update := range updates { + if update.UpdateID >= config.Offset { + config.Offset = update.UpdateID + 1 + bot.Updates <- update + } } } + } }()