all repos — telegram-bot-api @ 3293f3ad8411de32d99e443cd82aec7c3bb01a5a

Golang bindings for the Telegram Bot API

Change visibility of UpdatesChannel, closes #76
Syfaro syfaro@foxpaw.in
Thu, 26 Jan 2017 11:43:28 -0600
commit

3293f3ad8411de32d99e443cd82aec7c3bb01a5a

parent

99170e2de436c1be90d2ef23dcf533b55a973e56

3 files changed, 8 insertions(+), 9 deletions(-)

jump to
M bot.gobot.go

@@ -456,7 +456,7 @@ return info, err

} // GetUpdatesChan starts and returns a channel for getting updates. -func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (updatesChannel, error) { +func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) { ch := make(chan Update, 100) go func() {

@@ -483,7 +483,7 @@ return ch, nil

} // ListenForWebhook registers a http handler for a webhook. -func (bot *BotAPI) ListenForWebhook(pattern string) updatesChannel { +func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel { ch := make(chan Update, 100) http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
M bot_test.gobot_test.go

@@ -485,10 +485,9 @@ u.Timeout = 60

updates, err := bot.GetUpdatesChan(u) - //If you need to clear all the updates when bot just started: - //Wait to gather all the new updates (choose the time conveniently) + // Optional: wait for updates and clear them if you don't want to handle + // a large backlog of old messages time.Sleep(time.Millisecond * 500) - //discard all the updates preventing the spam after your server has been down updates.Clear() for update := range updates {
M types.gotypes.go

@@ -37,11 +37,11 @@ ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`

CallbackQuery *CallbackQuery `json:"callback_query"` } -//updatesChannel is the channel for getting updates. -type updatesChannel <-chan Update +// UpdatesChannel is the channel for getting updates. +type UpdatesChannel <-chan Update -//Clear discards all the actual incoming updates -func (ch updatesChannel) Clear() { +// Clear discards all unprocessed incoming updates. +func (ch UpdatesChannel) Clear() { for len(ch) != 0 { <-ch }