all repos — telegram-bot-api @ 7473250643e8f0913ba9306b6b7611e56beaf2e5

Golang bindings for the Telegram Bot API

Merge pull request #2 from jqs7/master

should not panic in production env
Syfaro syfaro@foxpaw.in
Mon, 29 Jun 2015 22:36:37 -0500
commit

7473250643e8f0913ba9306b6b7611e56beaf2e5

parent

7b9b7856fc1005a6d04f039704c70aee26d50ade

1 files changed, 18 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,13 +13,19 @@ 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("Fail to GetUpdates,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 + } } } }