@@ -22,7 +22,6 @@ type BotAPI struct {
2222 Token string `json:"token"`
2323 Debug bool `json:"debug"`
2424 Self User `json:"-"`
25- Updates chan Update `json:"-"`
2625 Client * http.Client `json:"-"`
2726}
2827
@@ -395,8 +394,8 @@ func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) {
395394}
396395
397396// UpdatesChan starts a channel for getting updates.
398- func (bot * BotAPI ) UpdatesChan (config UpdateConfig ) error {
399- bot . Updates = make (chan Update , 100 )
397+ func (bot * BotAPI ) UpdatesChan (config UpdateConfig ) ( <- chan Update , error ) {
398+ updatesChan : = make (chan Update , 100 )
400399
401400 go func () {
402401 for {
@@ -412,29 +411,29 @@ func (bot *BotAPI) UpdatesChan(config UpdateConfig) error {
412411 for _ , update := range updates {
413412 if update .UpdateID >= config .Offset {
414413 config .Offset = update .UpdateID + 1
415- bot . Updates <- update
414+ updatesChan <- update
416415 }
417416 }
418417 }
419418 }()
420419
421- return nil
420+ return updatesChan , nil
422421}
423422
424423// ListenForWebhook registers a http handler for a webhook.
425- func (bot * BotAPI ) ListenForWebhook (pattern string ) http.Handler {
426- bot . Updates = make (chan Update , 100 )
424+ func (bot * BotAPI ) ListenForWebhook (pattern string ) ( <- chan Update , http.Handler ) {
425+ updatesChan : = make (chan Update , 100 )
427426
428427 handler := http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
429428 bytes , _ := ioutil .ReadAll (r .Body )
430429
431430 var update Update
432431 json .Unmarshal (bytes , & update )
433432
434- bot . Updates <- update
433+ updatesChan <- update
435434 })
436435
437436 http .HandleFunc (pattern , handler )
438437
439- return handler
438+ return updatesChan , handler
440439}
0 commit comments