all repos — telegram-bot-api @ 4acb279a6785a43eeff7064c0b32ae306937b4d5

Golang bindings for the Telegram Bot API

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				}
18
19				bot.Updates <- update
20			}
21		}
22	}()
23
24	return bot.Updates, nil
25}