From fa2076111093de02b6d724477afce629528db3f1 Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 10 Dec 2017 15:08:23 +0100 Subject: Add support for Audio/Voice files (telegram). Closes #314 --- bridge/telegram/telegram.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'bridge/telegram/telegram.go') diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go index c2f69c3d..328850ea 100644 --- a/bridge/telegram/telegram.go +++ b/bridge/telegram/telegram.go @@ -179,6 +179,12 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { if message.Document != nil { b.handleDownload(message.Document, &fmsg) } + if message.Voice != nil { + b.handleDownload(message.Voice, &fmsg) + } + if message.Audio != nil { + b.handleDownload(message.Audio, &fmsg) + } if message.ForwardFrom != nil { text = "Forward from " + message.ForwardFrom.FirstName @@ -242,6 +248,23 @@ func (b *Btelegram) handleDownload(file interface{}, msg *config.Message) { text := "" fileid := "" switch v := file.(type) { + case *tgbotapi.Audio: + size = v.FileSize + url = b.getFileDirectURL(v.FileID) + urlPart := strings.Split(url, "/") + name = urlPart[len(urlPart)-1] + text = " " + url + fileid = v.FileID + case *tgbotapi.Voice: + size = v.FileSize + url = b.getFileDirectURL(v.FileID) + urlPart := strings.Split(url, "/") + name = urlPart[len(urlPart)-1] + text = " " + url + if !strings.HasSuffix(name, ".ogg") { + name = name + ".ogg" + } + fileid = v.FileID case *tgbotapi.Sticker: size = v.FileSize url = b.getFileDirectURL(v.FileID) -- cgit v1.2.3