-
Notifications
You must be signed in to change notification settings - Fork 5
Conversation
gwinn
commented
May 29, 2018
- route for mg webhook (sending messages from mg to telegram)
- minor fixes
migrations/1527515265_app.up.sql
Outdated
@@ -0,0 +1,19 @@ | |||
alter table connection | |||
add constraint connection_client_id_key unique (api_key), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем тут unique? Чтобы пользователь одной црм узнал, что в другоой црм такой же ключ?
migrations/1527515265_app.up.sql
Outdated
alter table connection | ||
add constraint connection_client_id_key unique (api_key), | ||
add constraint connection_api_key_key unique (api_url), | ||
add constraint connection_api_url_key unique (mg_url), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а он разве не одинаковый для всех у нас?
migrations/1527515265_app.up.sql
Outdated
add constraint bot_token_key unique (token); | ||
|
||
alter table bot | ||
rename column client_id to connection_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не вижу констрейнта связи между таблицами
migrations/1527515265_app.up.sql
Outdated
alter column api_url set not null; | ||
|
||
alter table bot | ||
alter column client_id type integer using client_id::integer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
на бою например строка вида 0c4c3dcf...
. Зачем ее пытаетесь преообразовать в integer
и что там по смыслу получится?
models.go
Outdated
MGToken string `gorm:"mg_token" json:"mg_token,omitempty"` | ||
ClientID string `gorm:"client_id type:varchar(70);not null;unique" json:"clientId,omitempty"` | ||
APIKEY string `gorm:"api_key type:varchar(100);not null;unique" json:"api_key,omitempty"` | ||
APIURL string `gorm:"api_url type:varchar(100);not null;unique" json:"api_url,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
для урлов надоо хотя бы 255 делать. 100 не так много для урла
telegram.go
Outdated
return | ||
} | ||
|
||
c := getConnectionById(b.ConnectionID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
между моделями нужно просто связь сделать и в getBotByToken
сделать выборку с Preload
telegram.go
Outdated
} | ||
|
||
c := getConnectionById(b.ConnectionID) | ||
if c.MGURL == "" || c.MGToken == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тогда и эта проверка не понадобится
telegram.go
Outdated
data, st, err := client.Messages(snd) | ||
if err != nil { | ||
logger.Error(token, err.Error(), st, data) | ||
w.WriteHeader(http.StatusInternalServerError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в raven не пишется
telegram.go
Outdated
data, st, err := client.UpdateMessages(snd) | ||
if err != nil { | ||
logger.Error(token, err.Error(), st, data) | ||
w.WriteHeader(http.StatusInternalServerError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в raven не пишется
telegram.go
Outdated
if msg.Type == "message_sent" { | ||
msg, err := bot.Send(tgbotapi.NewMessage(msg.Data.ExternalChatID, msg.Data.Content)) | ||
if err != nil { | ||
logger.Error(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ошибки от телеграма я бы в равен логгироовал. а тоо может у нас там ниче не работает, а мы не узнаем даже