all repos — telegram-bot-api @ 5b2104f97410bc2eabe9897539047809ac1ddda4

Golang bindings for the Telegram Bot API

updates.go (view raw)

 1package tgbotapi
 2
 3// 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		updates, err := bot.GetUpdates(config)
 9		if err != nil {
10			panic(err)
11		}
12
13		for _, update := range updates {
14			if update.UpdateId > config.Offset {
15				config.Offset = update.UpdateId + 1
16			}
17
18			bot.Updates <- update
19		}
20	}()
21
22	return bot.Updates, nil
23}