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 if bot.Debug {
17 panic(err)
18 } else {
19 log.Println(err)
20 log.Println("Failed to get updates, retrying in 3 seconds...")
21 time.Sleep(time.Second * 3)
22 }
23
24 continue
25 }
26
27 for _, update := range updates {
28 if update.UpdateID >= config.Offset {
29 config.Offset = update.UpdateID + 1
30 bot.Updates <- update
31 }
32 }
33 }
34 }()
35
36 return nil
37}