1
0
mirror of synced 2024-11-25 13:16:02 +03:00

minor fixes

This commit is contained in:
DmitryZagorulko 2018-06-01 12:08:22 +03:00
parent 41914051e4
commit 3ff174150a
9 changed files with 41 additions and 10 deletions

View File

@ -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

View File

@ -8,3 +8,5 @@ http_server:
sentry_dsn: ~
log_level: 5
debug: false

View File

@ -8,3 +8,5 @@ http_server:
sentry_dsn: ~
log_level: 5
debug: false

View File

@ -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
}

View File

@ -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"))
}

View File

@ -12,7 +12,7 @@
<input name="connectionId" type="hidden" value="{{.Conn.ID}}">
<div class="row">
<div class="input-field col s12">
<input placeholder="API Url" id="api_url" name="api_url" type="text" class="validate" value="{{.Conn.APIURL}}">
<input placeholder="CRM Url" id="api_url" name="api_url" type="text" class="validate" value="{{.Conn.APIURL}}">
</div>
</div>
<div class="row">

View File

@ -4,7 +4,8 @@
<div id="msg"></div>
<div class="row">
<div class="input-field col s12">
<input placeholder="API Url" id="api_url" name="api_url" type="text" class="validate">
<input placeholder="CRM Url" id="api_url" name="api_url" type="text" class="validate"
{{if .Conn.APIURL}} value="{{.Conn.APIURL}}" {{end}}>
</div>
</div>
<div class="row">

View File

@ -27,3 +27,4 @@ error_creating_webhook: Error while creating webhook
error_adding_bot: Error while adding bot
error_save: An error occurred while saving, contact technical support
missing_credentials: "Necessary credentials: {{.Credentials}}"
error_activity_mg: Check the activity with MessageGateway in CRM settings

View File

@ -27,3 +27,4 @@ error_creating_webhook: Ошибка при создании webhook
error_adding_bot: Ошибка при добавлении бота
error_save: Ошибка при сохранении, обратитесь в службу технической поддержки
missing_credentials: "Необходимые методы: {{.Credentials}}"
error_activity_mg: Проверьте активность интеграции с MessageGateway в настройках CRM