From c9d5f4c8989ddf2465a20aac46537369c654b580 Mon Sep 17 00:00:00 2001 From: Guillaume Lazzara Date: Thu, 9 Jan 2020 18:14:01 +0100 Subject: Add support for WhatsApp media (jpeg/png/gif) bridging (#974) * Whatsapp image bridging * Prevent double message in telegram when media with caption received Co-authored-by: imShara --- bridge/telegram/telegram.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'bridge/telegram/telegram.go') diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go index 33d55bcd..c7ead21f 100644 --- a/bridge/telegram/telegram.go +++ b/bridge/telegram/telegram.go @@ -8,7 +8,7 @@ import ( "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" - "github.com/go-telegram-bot-api/telegram-bot-api" + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" ) const ( @@ -81,8 +81,8 @@ func (b *Btelegram) Send(msg config.Message) (string, error) { // Upload a file if it exists if msg.Extra != nil { for _, rmsg := range helper.HandleExtra(&msg, b.General) { - if _, err := b.sendMessage(chatid, rmsg.Username, rmsg.Text); err != nil { - b.Log.Errorf("sendMessage failed: %s", err) + if _, msgErr := b.sendMessage(chatid, rmsg.Username, rmsg.Text); msgErr != nil { + b.Log.Errorf("sendMessage failed: %s", msgErr) } } // check if we have files to upload (from slack, telegram or mattermost) @@ -97,7 +97,14 @@ func (b *Btelegram) Send(msg config.Message) (string, error) { } // Post normal message - return b.sendMessage(chatid, msg.Username, msg.Text) + // TODO: recheck it. + // Ignore empty text field needs for prevent double messages from whatsapp to telegram + // when sending media with text caption + if msg.Text != "" { + return b.sendMessage(chatid, msg.Username, msg.Text) + } + + return "", nil } func (b *Btelegram) getFileDirectURL(id string) string { -- cgit v1.2.3