From 942dca0687062d98a4dfb412ecc5191bb3b30f6d Mon Sep 17 00:00:00 2001 From: DmitryZagorulko Date: Fri, 1 Jun 2018 14:46:07 +0300 Subject: [PATCH 1/2] minor fixes --- telegram.go | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/telegram.go b/telegram.go index 2cee350..4b005b9 100644 --- a/telegram.go +++ b/telegram.go @@ -32,11 +32,6 @@ func GetBotName(bot *tgbotapi.BotAPI) string { } func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string) { - if config.Debug { - var v interface{} - json.NewDecoder(r.Body).Decode(&v) - logger.Debugf("token: %v mgWebhookHandler: %v", token, v) - } b, err := getBotByToken(token) if err != nil { raven.CaptureErrorAndWait(err, nil) @@ -74,6 +69,10 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string return } + if config.Debug { + logger.Debugf("telegramWebhookHandler: %v", string(bytes)) + } + err = json.Unmarshal(bytes, &update) if err != nil { raven.CaptureErrorAndWait(err, nil) @@ -113,7 +112,7 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string } if config.Debug { - logger.Debugf("Bot: %v, Message: %v, Response: %v", b.ID, snd, data) + logger.Debugf("telegramWebhookHandler Type: SendMessage, Bot: %v, Message: %v, Response: %v", b.ID, snd, data) } } @@ -138,7 +137,7 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string } if config.Debug { - logger.Debugf("Bot: %v, Message: %v, Response: %v", b.ID, snd, data) + logger.Debugf("telegramWebhookHandler Type: UpdateMessage, Bot: %v, Message: %v, Response: %v", b.ID, snd, data) } } @@ -146,11 +145,6 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string } func mgWebhookHandler(w http.ResponseWriter, r *http.Request) { - if config.Debug { - var v interface{} - json.NewDecoder(r.Body).Decode(&v) - logger.Debugf("mgWebhookHandler: %v", v) - } bytes, err := ioutil.ReadAll(r.Body) if err != nil { raven.CaptureErrorAndWait(err, nil) @@ -158,6 +152,10 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) { return } + if config.Debug { + logger.Debugf("mgWebhookHandler: %v", string(bytes)) + } + var msg v1.WebhookRequest err = json.Unmarshal(bytes, &msg) if err != nil { @@ -196,7 +194,7 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) { } if config.Debug { - logger.Debugf("%v", msg) + logger.Debugf("mgWebhookHandler %v", msg) } w.WriteHeader(http.StatusOK) @@ -213,7 +211,7 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) { } if config.Debug { - logger.Debugf("%v", msg) + logger.Debugf("mgWebhookHandler %v", msg) } w.WriteHeader(http.StatusOK) @@ -230,7 +228,7 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) { } if config.Debug { - logger.Debugf("%v", msg) + logger.Debugf("mgWebhookHandler %v", msg) } w.WriteHeader(http.StatusOK) From 630c5960b795506f3cf1ad84290769c547e7a2c1 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Fri, 1 Jun 2018 14:57:48 +0300 Subject: [PATCH 2/2] update request logging --- telegram.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/telegram.go b/telegram.go index 4b005b9..1d99646 100644 --- a/telegram.go +++ b/telegram.go @@ -153,7 +153,7 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) { } if config.Debug { - logger.Debugf("mgWebhookHandler: %v", string(bytes)) + logger.Debugf("mgWebhookHandler request: %v", string(bytes)) } var msg v1.WebhookRequest @@ -194,7 +194,7 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) { } if config.Debug { - logger.Debugf("mgWebhookHandler %v", msg) + logger.Debugf("mgWebhookHandler sent %v", msg) } w.WriteHeader(http.StatusOK) @@ -211,7 +211,7 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) { } if config.Debug { - logger.Debugf("mgWebhookHandler %v", msg) + logger.Debugf("mgWebhookHandler update %v", msg) } w.WriteHeader(http.StatusOK) @@ -228,7 +228,7 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) { } if config.Debug { - logger.Debugf("mgWebhookHandler %v", msg) + logger.Debugf("mgWebhookHandler delete %v", msg) } w.WriteHeader(http.StatusOK)