From d1358d12aaa4207728e8a60aa1c62b670611f9c3 Mon Sep 17 00:00:00 2001 From: Sergey Kamardin Date: Sun, 13 Sep 2015 21:56:43 +0300 Subject: [PATCH 1/2] Update webhook.go Why there is a hardcoded `bot.Token`? =) --- webhook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webhook.go b/webhook.go index 8519459..5eedb1c 100644 --- a/webhook.go +++ b/webhook.go @@ -9,10 +9,10 @@ import ( // ListenForWebhook registers a http handler for a webhook. // Useful for Google App Engine or other places where you cannot // use a normal update chan. -func (bot *BotAPI) ListenForWebhook() { +func (bot *BotAPI) ListenForWebhook(config WebhookConfig) { bot.Updates = make(chan Update, 100) - http.HandleFunc("/"+bot.Token, func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc("/"+config.Url.Path, func(w http.ResponseWriter, r *http.Request) { bytes, _ := ioutil.ReadAll(r.Body) var update Update From 2a5bad0be4554ad57b781fb1160142fbd14a730a Mon Sep 17 00:00:00 2001 From: gobwas Date: Mon, 14 Sep 2015 12:50:41 +0300 Subject: [PATCH 2/2] Move to simple pattern --- README.md | 2 +- webhook.go | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 037d7c6..07ed41f 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ func main() { log.Fatal(err) } - bot.ListenForWebhook() + bot.ListenForWebhook("/"+bot.Token) go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil) for update := range bot.Updates { diff --git a/webhook.go b/webhook.go index 5eedb1c..79060da 100644 --- a/webhook.go +++ b/webhook.go @@ -7,12 +7,10 @@ import ( ) // ListenForWebhook registers a http handler for a webhook. -// Useful for Google App Engine or other places where you cannot -// use a normal update chan. -func (bot *BotAPI) ListenForWebhook(config WebhookConfig) { +func (bot *BotAPI) ListenForWebhook(pattern string) { bot.Updates = make(chan Update, 100) - http.HandleFunc("/"+config.Url.Path, func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) { bytes, _ := ioutil.ReadAll(r.Body) var update Update