diff --git a/bot.go b/bot.go index 60519cd..7ae3b47 100644 --- a/bot.go +++ b/bot.go @@ -456,7 +456,7 @@ func (bot *BotAPI) GetWebhookInfo() (WebhookInfo, error) { } // 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 @@ func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (updatesChannel, error) { } // 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) { diff --git a/bot_test.go b/bot_test.go index 40010d3..a2e35d6 100644 --- a/bot_test.go +++ b/bot_test.go @@ -485,10 +485,9 @@ func ExampleNewBotAPI() { 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 { diff --git a/types.go b/types.go index 05c7840..e691028 100644 --- a/types.go +++ b/types.go @@ -37,11 +37,11 @@ type Update struct { 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 }