1
0
mirror of synced 2024-11-29 06:56:02 +03:00

Merge pull request #11 from gwinn/master

update request logging
This commit is contained in:
Alex Lushpai 2018-06-01 14:58:55 +03:00 committed by GitHub
commit b6f48255ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,11 +32,6 @@ func GetBotName(bot *tgbotapi.BotAPI) string {
} }
func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token 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) b, err := getBotByToken(token)
if err != nil { if err != nil {
raven.CaptureErrorAndWait(err, nil) raven.CaptureErrorAndWait(err, nil)
@ -74,6 +69,10 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string
return return
} }
if config.Debug {
logger.Debugf("telegramWebhookHandler: %v", string(bytes))
}
err = json.Unmarshal(bytes, &update) err = json.Unmarshal(bytes, &update)
if err != nil { if err != nil {
raven.CaptureErrorAndWait(err, nil) raven.CaptureErrorAndWait(err, nil)
@ -113,7 +112,7 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string
} }
if config.Debug { 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 { 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) { 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) bytes, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
raven.CaptureErrorAndWait(err, nil) raven.CaptureErrorAndWait(err, nil)
@ -158,6 +152,10 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
if config.Debug {
logger.Debugf("mgWebhookHandler request: %v", string(bytes))
}
var msg v1.WebhookRequest var msg v1.WebhookRequest
err = json.Unmarshal(bytes, &msg) err = json.Unmarshal(bytes, &msg)
if err != nil { if err != nil {
@ -196,7 +194,7 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) {
} }
if config.Debug { if config.Debug {
logger.Debugf("%v", msg) logger.Debugf("mgWebhookHandler sent %v", msg)
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
@ -213,7 +211,7 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) {
} }
if config.Debug { if config.Debug {
logger.Debugf("%v", msg) logger.Debugf("mgWebhookHandler update %v", msg)
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
@ -230,7 +228,7 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) {
} }
if config.Debug { if config.Debug {
logger.Debugf("%v", msg) logger.Debugf("mgWebhookHandler delete %v", msg)
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)