sending text stub
This commit is contained in:
parent
f8577e9efd
commit
de6ee9462a
@ -1 +1 @@
|
||||
alter table mg_user rename to user;
|
||||
alter table mg_user rename to users;
|
||||
|
@ -69,9 +69,9 @@ func (c Connection) getBotsByClientID() Bots {
|
||||
return b
|
||||
}
|
||||
|
||||
func getBotByChannelAndCID(connectionID int, ch uint64) *Bot {
|
||||
func getBot(cid int, ch uint64) *Bot {
|
||||
var bot Bot
|
||||
orm.DB.First(&bot, "connection_id = ? AND channel = ?", connectionID, ch)
|
||||
orm.DB.First(&bot, "connection_id = ? AND channel = ?", cid, ch)
|
||||
|
||||
return &bot
|
||||
}
|
||||
|
40
telegram.go
40
telegram.go
@ -15,6 +15,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||
"github.com/getsentry/raven-go"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"github.com/retailcrm/mg-transport-api-client-go/v1"
|
||||
)
|
||||
|
||||
@ -76,7 +77,11 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string
|
||||
var client = v1.New(c.MGURL, c.MGToken)
|
||||
|
||||
if update.Message != nil {
|
||||
if update.Message.Text != "" {
|
||||
if update.Message.Text == "" {
|
||||
setLocale(update.Message.From.LanguageCode)
|
||||
update.Message.Text = localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: getMessageID(update.Message)})
|
||||
}
|
||||
|
||||
nickname := update.Message.From.UserName
|
||||
user := getUserByExternalID(update.Message.From.ID)
|
||||
|
||||
@ -156,10 +161,13 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string
|
||||
logger.Debugf("telegramWebhookHandler Type: SendMessage, Bot: %v, Message: %v, Response: %v", b.ID, snd, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if update.EditedMessage != nil {
|
||||
if update.EditedMessage.Text != "" {
|
||||
if update.EditedMessage.Text == "" {
|
||||
setLocale(update.EditedMessage.From.LanguageCode)
|
||||
update.EditedMessage.Text = localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: getMessageID(update.Message)})
|
||||
}
|
||||
|
||||
snd := v1.UpdateData{
|
||||
Message: v1.UpdateMessage{
|
||||
Message: v1.Message{
|
||||
@ -183,7 +191,6 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string
|
||||
logger.Debugf("telegramWebhookHandler Type: UpdateMessage, Bot: %v, Message: %v, Response: %v", b.ID, snd, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
@ -229,7 +236,7 @@ func mgWebhookHandler(w http.ResponseWriter, r *http.Request) {
|
||||
uid, _ := strconv.Atoi(msg.Data.ExternalMessageID)
|
||||
cid, _ := strconv.ParseInt(msg.Data.ExternalChatID, 10, 64)
|
||||
|
||||
b := getBotByChannelAndCID(c.ID, msg.Data.ChannelID)
|
||||
b := getBot(c.ID, msg.Data.ChannelID)
|
||||
if b.ID == 0 || !b.Active {
|
||||
logger.Error(msg.Data.ChannelID, "mgWebhookHandler: missing or deactivated")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@ -377,3 +384,26 @@ func UploadUserAvatar(url string) (picURLs3 string, err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func getMessageID(data *tgbotapi.Message) string {
|
||||
switch {
|
||||
case data.Sticker != nil:
|
||||
return "sticker"
|
||||
case data.Audio != nil:
|
||||
return "audio"
|
||||
case data.Contact != nil:
|
||||
return "contact"
|
||||
case data.Document != nil:
|
||||
return "document"
|
||||
case data.Location != nil:
|
||||
return "location"
|
||||
case data.Video != nil:
|
||||
return "video"
|
||||
case data.Voice != nil:
|
||||
return "voice"
|
||||
case data.Photo != nil:
|
||||
return "photo"
|
||||
default:
|
||||
return "undefined"
|
||||
}
|
||||
}
|
||||
|
@ -28,3 +28,13 @@ 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
|
||||
|
||||
sticker: "[sticker]"
|
||||
audio: "[audio file]"
|
||||
contact: "[contact]"
|
||||
document: "[document]"
|
||||
location: "[location]"
|
||||
video: "[video]"
|
||||
voice: "[voice message]"
|
||||
photo: "[image]"
|
||||
undefined: "[undefined message format]"
|
||||
|
@ -28,3 +28,13 @@ error_adding_bot: Ошибка при добавлении бота
|
||||
error_save: Ошибка при сохранении, обратитесь в службу технической поддержки
|
||||
missing_credentials: "Необходимые методы: {{.Credentials}}"
|
||||
error_activity_mg: Проверьте активность интеграции с MessageGateway в настройках CRM
|
||||
|
||||
sticker: "[стикер]"
|
||||
audio: "[аудио файл]"
|
||||
contact: "[контакт]"
|
||||
document: "[документ]"
|
||||
location: "[местонахождение]"
|
||||
video: "[видео]"
|
||||
voice: "[голосовое сообщение]"
|
||||
photo: "[изображение]"
|
||||
other: "[неопределенный формат сообщения]"
|
||||
|
Loading…
Reference in New Issue
Block a user