4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-07-13 19:36:28 +00:00

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 <shara@protonmail.com>
This commit is contained in:
Guillaume Lazzara
2020-01-09 18:14:01 +01:00
committed by Wim
parent 810c150781
commit c9d5f4c898
5 changed files with 205 additions and 43 deletions

View File

@ -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 {