From 46810dab09c4d66de560c21ce9e8ca92363b7a28 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 28 Aug 2019 11:17:11 +0300 Subject: [PATCH 1/2] send animation as file --- src/routing.go | 6 +++++- src/telegram.go | 2 ++ translate/translate.en.yml | 1 + translate/translate.es.yml | 1 + translate/translate.ru.yml | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/routing.go b/src/routing.go index f50a528..52956e4 100644 --- a/src/routing.go +++ b/src/routing.go @@ -1029,6 +1029,10 @@ func setAttachment(attachments *tgbotapi.Message, client *v1.MgClient, snd *v1.S snd.Message.Type = v1.MsgTypeImage snd.Message.Note = attachments.Caption + case "animation": + fileID = attachments.Animation.FileID + snd.Message.Type = v1.MsgTypeFile + caption += ".mp4" case "document": fileID = attachments.Document.FileID snd.Message.Type = v1.MsgTypeFile @@ -1052,7 +1056,7 @@ func setAttachment(attachments *tgbotapi.Message, client *v1.MgClient, snd *v1.S item := v1.Item{} fileUrl := fmt.Sprintf("https://api.telegram.org/file/bot%s/%s", botToken, file.FilePath) switch { - case t == "sticker" || t == "voice": + case t == "sticker" || t == "voice" || t == "animation": item, _, err = getItemData( client, fileUrl, diff --git a/src/telegram.go b/src/telegram.go index f191c93..cf6da0e 100644 --- a/src/telegram.go +++ b/src/telegram.go @@ -41,6 +41,8 @@ func getMessageID(data *tgbotapi.Message) string { return "audio" case data.Contact != nil: return "contact" + case data.Animation != nil: + return "animation" case data.Document != nil: return "document" case data.Location != nil: diff --git a/translate/translate.en.yml b/translate/translate.en.yml index e279ea3..a55880c 100644 --- a/translate/translate.en.yml +++ b/translate/translate.en.yml @@ -39,6 +39,7 @@ audio: "[audio file]" contact: "[contact]" document: "[document]" location: "[location]" +animation: "[animation]" video: "[video]" voice: "[voice message]" photo: "[photo]" diff --git a/translate/translate.es.yml b/translate/translate.es.yml index b4877f0..e08ab47 100644 --- a/translate/translate.es.yml +++ b/translate/translate.es.yml @@ -40,6 +40,7 @@ audio: "[archivo de audio]" contact: "[contacto]" document: "[documento]" location: "[localidad]" +animation: "[animación]" video: "[video]" voice: "[mensaje de voz]" photo: "[foto]" diff --git a/translate/translate.ru.yml b/translate/translate.ru.yml index 7e29629..4329710 100644 --- a/translate/translate.ru.yml +++ b/translate/translate.ru.yml @@ -39,6 +39,7 @@ audio: "[аудио файл]" contact: "[контакт]" document: "[документ]" location: "[местонахождение]" +animation: "[анимация]" video: "[видео]" voice: "[голосовое сообщение]" photo: "[изображение]" From 2ce3f44898e0fbd1a47420a681881fb232a3123c Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 28 Aug 2019 11:41:30 +0300 Subject: [PATCH 2/2] pass item id as name --- src/routing.go | 13 ++++++++++++- translate/translate.en.yml | 1 - translate/translate.es.yml | 1 - translate/translate.ru.yml | 1 - 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/routing.go b/src/routing.go index 52956e4..be48f96 100644 --- a/src/routing.go +++ b/src/routing.go @@ -1056,7 +1056,7 @@ func setAttachment(attachments *tgbotapi.Message, client *v1.MgClient, snd *v1.S item := v1.Item{} fileUrl := fmt.Sprintf("https://api.telegram.org/file/bot%s/%s", botToken, file.FilePath) switch { - case t == "sticker" || t == "voice" || t == "animation": + case t == "sticker" || t == "voice": item, _, err = getItemData( client, fileUrl, @@ -1065,6 +1065,17 @@ func setAttachment(attachments *tgbotapi.Message, client *v1.MgClient, snd *v1.S if err != nil { return err } + case t == "animation": + item, _, err = getItemData( + client, + fileUrl, + caption, + ) + if err != nil { + return err + } + + item.Caption = item.ID + ".mp4" default: item, err = convertAndUploadImage( client, diff --git a/translate/translate.en.yml b/translate/translate.en.yml index a55880c..e279ea3 100644 --- a/translate/translate.en.yml +++ b/translate/translate.en.yml @@ -39,7 +39,6 @@ audio: "[audio file]" contact: "[contact]" document: "[document]" location: "[location]" -animation: "[animation]" video: "[video]" voice: "[voice message]" photo: "[photo]" diff --git a/translate/translate.es.yml b/translate/translate.es.yml index e08ab47..b4877f0 100644 --- a/translate/translate.es.yml +++ b/translate/translate.es.yml @@ -40,7 +40,6 @@ audio: "[archivo de audio]" contact: "[contacto]" document: "[documento]" location: "[localidad]" -animation: "[animación]" video: "[video]" voice: "[mensaje de voz]" photo: "[foto]" diff --git a/translate/translate.ru.yml b/translate/translate.ru.yml index 4329710..7e29629 100644 --- a/translate/translate.ru.yml +++ b/translate/translate.ru.yml @@ -39,7 +39,6 @@ audio: "[аудио файл]" contact: "[контакт]" document: "[документ]" location: "[местонахождение]" -animation: "[анимация]" video: "[видео]" voice: "[голосовое сообщение]" photo: "[изображение]"