diff --git a/models.go b/models.go
index 11f0ade..7388fcb 100644
--- a/models.go
+++ b/models.go
@@ -27,12 +27,5 @@ type Bot struct {
Active bool `json:"active,omitempty"`
}
-// Mapping model
-type Mapping struct {
- ID int `gorm:"primary_key"`
- SiteCode string `gorm:"site_code" json:"site_code,omitempty"`
- BotID string `gorm:"bot_id" json:"bot_id,omitempty"`
-}
-
//Bots list
type Bots []Bot
diff --git a/repository.go b/repository.go
index 36f7dbb..5ac999c 100644
--- a/repository.go
+++ b/repository.go
@@ -1,28 +1,5 @@
package main
-func createMapping(s []Mapping) error {
- tx := orm.DB.Begin()
- if tx.Error != nil {
- return tx.Error
- }
-
- defer func() {
- if r := recover(); r != nil {
- logger.Warning(r)
- tx.Rollback()
- }
- }()
-
- for _, val := range s {
- if err := tx.Create(&val).Error; err != nil {
- tx.Rollback()
- return err
- }
- }
-
- return tx.Commit().Error
-}
-
func getConnection(uid string) (*Connection, error) {
var connection Connection
orm.DB.First(&connection, "client_id = ?", uid)
diff --git a/routing.go b/routing.go
index b189a5a..455a485 100644
--- a/routing.go
+++ b/routing.go
@@ -18,7 +18,7 @@ import (
)
var (
- templates = template.Must(template.ParseFiles("templates/header.html", "templates/form.html", "templates/home.html"))
+ templates = template.Must(template.ParseFiles("templates/layout.html", "templates/form.html", "templates/home.html"))
validPath = regexp.MustCompile("^/(save|settings)/([a-zA-Z0-9]+)$")
localizer *i18n.Localizer
bundle = &i18n.Bundle{DefaultLanguage: language.English}
@@ -91,6 +91,7 @@ func connectHandler(w http.ResponseWriter, r *http.Request) {
&p,
map[string]interface{}{
"ButConnect": localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "but_connect"}),
+ "ApiKey": localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "api_key"}),
},
}
renderTemplate(w, "home", &res)
@@ -125,7 +126,7 @@ func addBotHandler(w http.ResponseWriter, r *http.Request) {
bot, err := GetBotInfo(b.Token)
if err != nil {
logger.Error(b.Token, err.Error())
- http.Error(w, "set correct bot token", http.StatusInternalServerError)
+ http.Error(w, localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "incorrect_token"}), http.StatusInternalServerError)
return
}
@@ -244,30 +245,6 @@ func activityBotHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
-func mappingHandler(w http.ResponseWriter, r *http.Request) {
- body, err := ioutil.ReadAll(r.Body)
- if err != nil {
- raven.CaptureErrorAndWait(err, nil)
- return
- }
-
- var rec []Mapping
-
- err = json.Unmarshal(body, &rec)
- if err != nil {
- raven.CaptureErrorAndWait(err, nil)
- return
- }
-
- err = createMapping(rec)
- if err != nil {
- raven.CaptureErrorAndWait(err, nil)
- return
- }
-
- w.WriteHeader(http.StatusOK)
-}
-
func settingsHandler(w http.ResponseWriter, r *http.Request, uid string) {
setLocale(r.Header.Get("Accept-Language"))
@@ -299,14 +276,12 @@ func settingsHandler(w http.ResponseWriter, r *http.Request, uid string) {
sites.Sites,
map[string]interface{}{
"ButConnect": localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "but_connect"}),
+ "ApiKey": localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "api_key"}),
"TabSettings": localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "tab_settings"}),
"TabBots": localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "tab_bots"}),
- "TabMapping": localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "tab_mapping"}),
"TableName": localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "table_name"}),
"TableToken": localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "table_token"}),
"TableActivity": localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "table_activity"}),
- "MapSites": localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "map_sites"}),
- "MapOption": localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "map_option"}),
},
}
@@ -348,13 +323,24 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
func createHandler(w http.ResponseWriter, r *http.Request) {
setLocale(r.Header.Get("Accept-Language"))
- c := Connection{
- ClientID: GenerateToken(),
- APIURL: string([]byte(r.FormValue("api_url"))),
- APIKEY: string([]byte(r.FormValue("api_key"))),
+
+ body, err := ioutil.ReadAll(r.Body)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
}
- err := validate(c)
+ var c Connection
+
+ err = json.Unmarshal(body, &c)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ c.ClientID = GenerateToken()
+
+ err = validate(c)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
logger.Error(c.APIURL, err.Error())
@@ -388,9 +374,12 @@ func createHandler(w http.ResponseWriter, r *http.Request) {
Active: true,
Name: "MG Telegram",
ClientID: c.ClientID,
- BaseURL: config.HTTPServer.Host,
+ BaseURL: fmt.Sprintf(
+ "https://%s",
+ config.HTTPServer.Host,
+ ),
AccountURL: fmt.Sprintf(
- "%s/settings/%s",
+ "https://%s/settings/%s",
config.HTTPServer.Host,
c.ClientID,
),
@@ -398,7 +387,7 @@ func createHandler(w http.ResponseWriter, r *http.Request) {
Integrations: &v5.Integrations{
MgTransport: &v5.MgTransport{
WebhookUrl: fmt.Sprintf(
- "%s/webhook",
+ "https://%s/webhook",
config.HTTPServer.Host,
),
},
diff --git a/telegram.go b/telegram.go
index de11dd4..2a79e55 100644
--- a/telegram.go
+++ b/telegram.go
@@ -9,7 +9,6 @@ import (
func setTransportRoutes() {
http.HandleFunc("/add-bot/", addBotHandler)
http.HandleFunc("/activity-bot/", activityBotHandler)
- http.HandleFunc("/map-bot/", mappingHandler)
}
// GetBotInfo function
diff --git a/templates/form.html b/templates/form.html
index e514fd2..d9a8e3d 100644
--- a/templates/form.html
+++ b/templates/form.html
@@ -1,219 +1,78 @@
{{template "header"}}
-
-
-
-
-
-
-
-
- {{if .Bots}}
-
-
-
- {{.Locale.TableName}} |
- {{.Locale.TableToken}} |
- {{.Locale.TableActivity}} |
-
-
-
- {{range .Bots}}
-
- {{.Name}} |
- {{.Token}} |
-
-
- |
-
- {{end}}
-
-
- {{end}}
-
-
-
-
- {{ $sites := .Sites }}
- {{ $bots := .Bots }}
- {{ $locale := .Locale }}
- {{if and $sites $bots}}
-
-
-
- {{.Locale.MapSites}} |
- {{.Locale.TabBots}} |
-
-
-
- {{range $site := $sites}}
-
- {{$site.Name}} |
-
-
- |
-
- {{end}}
-
-
-
-
-
-
-
-
- {{end}}
-
-
-
-
-
+