all repos — telegram-bot-api @ 9efd3005165e4c26a376179083da0328369ace50

Golang bindings for the Telegram Bot API

updates.go (view raw)

 1package tgbotapi
 2
 3import (
 4	"log"
 5	"time"
 6)
 7
 8// UpdatesChan starts a channel for getting updates.
 9func (bot *BotAPI) UpdatesChan(config UpdateConfig) error {
10	bot.Updates = make(chan Update, 100)
11
12	go func() {
13		for {
14			updates, err := bot.GetUpdates(config)
15			if err != nil {
16				log.Println(err)
17				log.Println("Failed to get updates, retrying in 3 seconds...")
18				time.Sleep(time.Second * 3)
19
20				continue
21			}
22
23			for _, update := range updates {
24				if update.UpdateID >= config.Offset {
25					config.Offset = update.UpdateID + 1
26					bot.Updates <- update
27				}
28			}
29		}
30	}()
31
32	return nil
33}