summaryrefslogtreecommitdiffstats
path: root/bridge/matrix
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-11-21 23:50:27 +0100
committerWim <wim@42.be>2017-11-21 23:50:27 +0100
commit34227a7a39219a0a7f6de4fb5cd55632fedb48d3 (patch)
tree4acf4ab05e6a5110208ed4fb3c00c6a52ac47ebb /bridge/matrix
parent71cb9b2d1dd96b309134187cd38155c22f086060 (diff)
downloadmatterbridge-msglm-34227a7a39219a0a7f6de4fb5cd55632fedb48d3.tar.gz
matterbridge-msglm-34227a7a39219a0a7f6de4fb5cd55632fedb48d3.tar.bz2
matterbridge-msglm-34227a7a39219a0a7f6de4fb5cd55632fedb48d3.zip
Add support for uploading images/video (matrix). Closes #302
Diffstat (limited to 'bridge/matrix')
-rw-r--r--bridge/matrix/matrix.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/bridge/matrix/matrix.go b/bridge/matrix/matrix.go
index bbf85e9b..5572be5a 100644
--- a/bridge/matrix/matrix.go
+++ b/bridge/matrix/matrix.go
@@ -1,7 +1,10 @@
package bmatrix
import (
+ "bytes"
+ "mime"
"regexp"
+ "strings"
"sync"
"github.com/42wim/matterbridge/bridge/config"
@@ -87,6 +90,43 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
matrix.TextMessage{"m.emote", msg.Username + msg.Text})
return "", nil
}
+
+ if msg.Extra != nil {
+ // check if we have files to upload (from slack, telegram or mattermost)
+ if len(msg.Extra["file"]) > 0 {
+ for _, f := range msg.Extra["file"] {
+ fi := f.(config.FileInfo)
+ content := bytes.NewReader(*fi.Data)
+ sp := strings.Split(fi.Name, ".")
+ mtype := mime.TypeByExtension("." + sp[len(sp)-1])
+ if strings.Contains(mtype, "image") ||
+ strings.Contains(mtype, "video") {
+ flog.Debugf("uploading file: %s %s", fi.Name, mtype)
+ res, err := b.mc.UploadToContentRepo(content, mtype, int64(len(*fi.Data)))
+ if err != nil {
+ flog.Errorf("file upload failed: %#v", err)
+ }
+ if strings.Contains(mtype, "video") {
+ flog.Debugf("sendVideo %s", res.ContentURI)
+ _, err = b.mc.SendVideo(channel, fi.Name, res.ContentURI)
+ if err != nil {
+ flog.Errorf("sendVideo failed: %#v", err)
+ }
+ }
+ if strings.Contains(mtype, "image") {
+ flog.Debugf("sendImage %s", res.ContentURI)
+ _, err = b.mc.SendImage(channel, fi.Name, res.ContentURI)
+ if err != nil {
+ flog.Errorf("sendImage failed: %#v", err)
+ }
+ }
+ flog.Debugf("result: %#v", res)
+ }
+ }
+ return "", nil
+ }
+ }
+
b.mc.SendText(channel, msg.Username+msg.Text)
return "", nil
}