Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

MG webhook route #6

Merged
merged 7 commits into from
May 31, 2018
Merged

MG webhook route #6

merged 7 commits into from
May 31, 2018

Conversation

gwinn
Copy link
Member

@gwinn gwinn commented May 29, 2018

  • route for mg webhook (sending messages from mg to telegram)
  • minor fixes

@@ -0,0 +1,19 @@
alter table connection
add constraint connection_client_id_key unique (api_key),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем тут unique? Чтобы пользователь одной црм узнал, что в другоой црм такой же ключ?

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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а он разве не одинаковый для всех у нас?

add constraint bot_token_key unique (token);

alter table bot
rename column client_id to connection_id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не вижу констрейнта связи между таблицами

alter column api_url set not null;

alter table bot
alter column client_id type integer using client_id::integer,
Copy link
Member

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"`
Copy link
Member

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)
Copy link
Member

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 == "" {
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ошибки от телеграма я бы в равен логгироовал. а тоо может у нас там ниче не работает, а мы не узнаем даже

@gwinn gwinn merged commit e8f58da into retailcrm:master May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants