updates.go (view raw)
1package tgbotapi
2
3// UpdatesChan returns a chan that is called whenever a new message is gotten.
4func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) {
5 bot.Updates = make(chan Update, 100)
6
7 go func() {
8 for {
9 updates, err := bot.GetUpdates(config)
10 if err != nil {
11 panic(err)
12 }
13
14 for _, update := range updates {
15 if update.UpdateID >= config.Offset {
16 config.Offset = update.UpdateID + 1
17 bot.Updates <- update
18 }
19 }
20 }
21 }()
22
23 return bot.Updates, nil
24}