1
0
mirror of synced 2024-11-25 21:26:02 +03:00

Merge pull request #9 from gwinn/master

minor fixes
This commit is contained in:
Alex Lushpai 2018-06-01 12:17:03 +03:00 committed by GitHub
commit f880b6f8fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 10 deletions

View File

@ -14,6 +14,7 @@ type TransportConfig struct {
Database DatabaseConfig `yaml:"database"` Database DatabaseConfig `yaml:"database"`
SentryDSN string `yaml:"sentry_dsn"` SentryDSN string `yaml:"sentry_dsn"`
HTTPServer HTTPServerConfig `yaml:"http_server"` HTTPServer HTTPServerConfig `yaml:"http_server"`
Debug bool `yaml:"debug"`
} }
// DatabaseConfig struct // DatabaseConfig struct

View File

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

View File

@ -8,3 +8,5 @@ http_server:
sentry_dsn: ~ sentry_dsn: ~
log_level: 5 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) { func connectHandler(w http.ResponseWriter, r *http.Request) {
setLocale(r.Header.Get("Accept-Language")) 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 { res := struct {
Conn *Connection Conn *Connection
@ -153,7 +159,7 @@ func addBotHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
bot.Debug = false bot.Debug = config.Debug
wr, err := bot.SetWebhook(tgbotapi.NewWebhook("https://" + config.HTTPServer.Host + "/telegram/" + bot.Token)) wr, err := bot.SetWebhook(tgbotapi.NewWebhook("https://" + config.HTTPServer.Host + "/telegram/" + bot.Token))
if err != nil { if err != nil {
@ -439,7 +445,7 @@ func createHandler(w http.ResponseWriter, r *http.Request) {
} }
if status >= http.StatusBadRequest { 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) logger.Error(c.APIURL, status, errr.ApiErr, data)
return return
} }

View File

@ -96,7 +96,7 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string
Lastname: update.Message.From.LastName, Lastname: update.Message.From.LastName,
Language: update.Message.From.LanguageCode, Language: update.Message.From.LanguageCode,
}, },
Channel: c.Bots[0].Channel, Channel: b.Channel,
} }
data, st, err := client.Messages(snd) data, st, err := client.Messages(snd)
@ -106,6 +106,10 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
if config.Debug {
logger.Debugf("Bot: %v, Message: %v, Response: %v", b.ID, snd, data)
}
} }
if update.EditedMessage != nil { if update.EditedMessage != nil {
@ -117,7 +121,7 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string
Text: update.EditedMessage.Text, Text: update.EditedMessage.Text,
}, },
}, },
Channel: c.Bots[0].Channel, Channel: b.Channel,
} }
data, st, err := client.UpdateMessages(snd) data, st, err := client.UpdateMessages(snd)
@ -127,6 +131,10 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
if config.Debug {
logger.Debugf("Bot: %v, Message: %v, Response: %v", b.ID, snd, data)
}
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
@ -177,7 +185,10 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
if config.Debug {
logger.Debugf("%v", msg) logger.Debugf("%v", msg)
}
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
w.Write([]byte("Message sent")) w.Write([]byte("Message sent"))
} }
@ -191,7 +202,10 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
if config.Debug {
logger.Debugf("%v", msg) logger.Debugf("%v", msg)
}
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
w.Write([]byte("Message updated")) w.Write([]byte("Message updated"))
} }
@ -205,7 +219,10 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
if config.Debug {
logger.Debugf("%v", msg) logger.Debugf("%v", msg)
}
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
w.Write([]byte("Message deleted")) w.Write([]byte("Message deleted"))
} }

View File

@ -12,7 +12,7 @@
<input name="connectionId" type="hidden" value="{{.Conn.ID}}"> <input name="connectionId" type="hidden" value="{{.Conn.ID}}">
<div class="row"> <div class="row">
<div class="input-field col s12"> <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> </div>
<div class="row"> <div class="row">

View File

@ -4,7 +4,8 @@
<div id="msg"></div> <div id="msg"></div>
<div class="row"> <div class="row">
<div class="input-field col s12"> <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> </div>
<div class="row"> <div class="row">

View File

@ -27,3 +27,4 @@ error_creating_webhook: Error while creating webhook
error_adding_bot: Error while adding bot error_adding_bot: Error while adding bot
error_save: An error occurred while saving, contact technical support error_save: An error occurred while saving, contact technical support
missing_credentials: "Necessary credentials: {{.Credentials}}" 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_adding_bot: Ошибка при добавлении бота
error_save: Ошибка при сохранении, обратитесь в службу технической поддержки error_save: Ошибка при сохранении, обратитесь в службу технической поддержки
missing_credentials: "Необходимые методы: {{.Credentials}}" missing_credentials: "Необходимые методы: {{.Credentials}}"
error_activity_mg: Проверьте активность интеграции с MessageGateway в настройках CRM