all repos — telegram-bot-api @ 6205cea402341a9a968d884a545321053f5ca291

Golang bindings for the Telegram Bot API

added StopReceivingUpdates to stop updates routine

There was no way to stop the bot from fetching updates, Added StopReceivingUpdates() so we can stop updates when we are done with bot.
Arman Arman1371@gmail.com
Sat, 10 Mar 2018 01:52:21 +0330
commit

6205cea402341a9a968d884a545321053f5ca291

parent

690363a5f88ea715a2b19aa13727fc12c8cba85a

1 files changed, 16 insertions(+), 0 deletions(-)

jump to
M bot.gobot.go

@@ -28,6 +28,7 @@ Buffer int `json:"buffer"`

Self User `json:"-"` Client *http.Client `json:"-"` + shutdownChannel chan interface{} } // NewBotAPI creates a new BotAPI instance.

@@ -46,6 +47,7 @@ bot := &BotAPI{

Token: token, Client: client, Buffer: 100, + shutdownChannel: make(chan interface{}), } self, err := bot.GetMe()

@@ -480,6 +482,12 @@ ch := make(chan Update, bot.Buffer)

go func() { for { + select { + case <-bot.shutdownChannel: + return + default: + } + updates, err := bot.GetUpdates(config) if err != nil { log.Println(err)

@@ -499,6 +507,14 @@ }

}() return ch, nil +} + +// StopReceivingUpdates stops the go routine which receives updates +func (bot *BotAPI) StopReceivingUpdates() { + if bot.Debug { + log.Println("Stopping the update receiver routine...") + } + close(bot.shutdownChannel) } // ListenForWebhook registers a http handler for a webhook.