all repos — telegram-bot-api @ a17651c8fe1a7072a086d5da4cd93b69a0ad5ce9

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		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}