diff --git a/config.go b/config.go index 8190ae0..a7de236 100644 --- a/config.go +++ b/config.go @@ -14,6 +14,7 @@ type TransportConfig struct { Database DatabaseConfig `yaml:"database"` SentryDSN string `yaml:"sentry_dsn"` HTTPServer HTTPServerConfig `yaml:"http_server"` + Debug bool `yaml:"debug"` } // DatabaseConfig struct diff --git a/config.yml.dist b/config.yml.dist index 605ba80..357105b 100644 --- a/config.yml.dist +++ b/config.yml.dist @@ -8,3 +8,5 @@ http_server: sentry_dsn: ~ log_level: 5 + +debug: false diff --git a/config_test.yml.dist b/config_test.yml.dist index 1132bce..090e513 100644 --- a/config_test.yml.dist +++ b/config_test.yml.dist @@ -8,3 +8,5 @@ http_server: sentry_dsn: ~ log_level: 5 + +debug: false diff --git a/routing.go b/routing.go index 5db0f45..435ed05 100644 --- a/routing.go +++ b/routing.go @@ -92,7 +92,13 @@ func makeHandler(fn func(http.ResponseWriter, *http.Request, string)) http.Handl func connectHandler(w http.ResponseWriter, r *http.Request) { setLocale(r.Header.Get("Accept-Language")) - p := Connection{} + + account := r.URL.Query() + rx := regexp.MustCompile(`/+$`) + ra := rx.ReplaceAllString(account.Get("account"), ``) + p := Connection{ + APIURL: ra, + } res := struct { Conn *Connection @@ -153,7 +159,7 @@ func addBotHandler(w http.ResponseWriter, r *http.Request) { return } - bot.Debug = false + bot.Debug = config.Debug wr, err := bot.SetWebhook(tgbotapi.NewWebhook("https://" + config.HTTPServer.Host + "/telegram/" + bot.Token)) if err != nil { @@ -439,7 +445,7 @@ func createHandler(w http.ResponseWriter, r *http.Request) { } if status >= http.StatusBadRequest { - http.Error(w, errr.ApiErr, http.StatusBadRequest) + http.Error(w, localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "error_activity_mg"}), http.StatusBadRequest) logger.Error(c.APIURL, status, errr.ApiErr, data) return } diff --git a/telegram.go b/telegram.go index 03f5593..c0b6d6c 100644 --- a/telegram.go +++ b/telegram.go @@ -96,7 +96,7 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string Lastname: update.Message.From.LastName, Language: update.Message.From.LanguageCode, }, - Channel: c.Bots[0].Channel, + Channel: b.Channel, } data, st, err := client.Messages(snd) @@ -106,6 +106,10 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string w.WriteHeader(http.StatusInternalServerError) return } + + if config.Debug { + logger.Debugf("Bot: %v, Message: %v, Response: %v", b.ID, snd, data) + } } if update.EditedMessage != nil { @@ -117,7 +121,7 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string Text: update.EditedMessage.Text, }, }, - Channel: c.Bots[0].Channel, + Channel: b.Channel, } data, st, err := client.UpdateMessages(snd) @@ -127,6 +131,10 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string w.WriteHeader(http.StatusInternalServerError) return } + + if config.Debug { + logger.Debugf("Bot: %v, Message: %v, Response: %v", b.ID, snd, data) + } } w.WriteHeader(http.StatusOK) @@ -177,7 +185,10 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) { return } - logger.Debugf("%v", msg) + if config.Debug { + logger.Debugf("%v", msg) + } + w.WriteHeader(http.StatusOK) w.Write([]byte("Message sent")) } @@ -191,7 +202,10 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) { return } - logger.Debugf("%v", msg) + if config.Debug { + logger.Debugf("%v", msg) + } + w.WriteHeader(http.StatusOK) w.Write([]byte("Message updated")) } @@ -205,7 +219,10 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) { return } - logger.Debugf("%v", msg) + if config.Debug { + logger.Debugf("%v", msg) + } + w.WriteHeader(http.StatusOK) w.Write([]byte("Message deleted")) } diff --git a/templates/form.html b/templates/form.html index 2e235c1..058b6a3 100644 --- a/templates/form.html +++ b/templates/form.html @@ -12,7 +12,7 @@