1
0
mirror of synced 2024-11-25 13:16:02 +03:00

Process only text messages from Telegram

This commit is contained in:
Ilyas Salikhov 2018-06-01 15:14:29 +03:00
parent b6f48255ef
commit d56f97052b

View File

@ -84,60 +84,64 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string
var client = v1.New(c.MGURL, c.MGToken) var client = v1.New(c.MGURL, c.MGToken)
if update.Message != nil { if update.Message != nil {
snd := v1.SendData{ if update.Message.Text != "" {
Message: v1.SendMessage{ snd := v1.SendData{
Message: v1.Message{ Message: v1.SendMessage{
ExternalID: strconv.Itoa(update.Message.MessageID), Message: v1.Message{
Type: "text", ExternalID: strconv.Itoa(update.Message.MessageID),
Text: update.Message.Text, Type: "text",
Text: update.Message.Text,
},
SentAt: time.Now(),
}, },
SentAt: time.Now(), User: v1.User{
}, ExternalID: strconv.Itoa(update.Message.From.ID),
User: v1.User{ Nickname: update.Message.From.UserName,
ExternalID: strconv.Itoa(update.Message.From.ID), Firstname: update.Message.From.FirstName,
Nickname: update.Message.From.UserName, Lastname: update.Message.From.LastName,
Firstname: update.Message.From.FirstName, Language: update.Message.From.LanguageCode,
Lastname: update.Message.From.LastName, },
Language: update.Message.From.LanguageCode, Channel: b.Channel,
}, }
Channel: b.Channel,
}
data, st, err := client.Messages(snd) data, st, err := client.Messages(snd)
if err != nil { if err != nil {
raven.CaptureErrorAndWait(err, nil) raven.CaptureErrorAndWait(err, nil)
logger.Error(token, err.Error(), st, data) logger.Error(token, err.Error(), st, data)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
if config.Debug { if config.Debug {
logger.Debugf("telegramWebhookHandler Type: SendMessage, Bot: %v, Message: %v, Response: %v", b.ID, snd, data) logger.Debugf("telegramWebhookHandler Type: SendMessage, Bot: %v, Message: %v, Response: %v", b.ID, snd, data)
}
} }
} }
if update.EditedMessage != nil { if update.EditedMessage != nil {
snd := v1.UpdateData{ if update.EditedMessage.Text != "" {
Message: v1.UpdateMessage{ snd := v1.UpdateData{
Message: v1.Message{ Message: v1.UpdateMessage{
ExternalID: strconv.Itoa(update.EditedMessage.MessageID), Message: v1.Message{
Type: "text", ExternalID: strconv.Itoa(update.EditedMessage.MessageID),
Text: update.EditedMessage.Text, Type: "text",
Text: update.EditedMessage.Text,
},
}, },
}, Channel: b.Channel,
Channel: b.Channel, }
}
data, st, err := client.UpdateMessages(snd) data, st, err := client.UpdateMessages(snd)
if err != nil { if err != nil {
raven.CaptureErrorAndWait(err, nil) raven.CaptureErrorAndWait(err, nil)
logger.Error(token, err.Error(), st, data) logger.Error(token, err.Error(), st, data)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
if config.Debug { if config.Debug {
logger.Debugf("telegramWebhookHandler Type: UpdateMessage, Bot: %v, Message: %v, Response: %v", b.ID, snd, data) logger.Debugf("telegramWebhookHandler Type: UpdateMessage, Bot: %v, Message: %v, Response: %v", b.ID, snd, data)
}
} }
} }