diff options
author | Wim <wim@42.be> | 2017-09-21 22:35:21 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-09-21 22:35:21 +0200 |
commit | c4b75e5754c58758c920c79b0458171e98269961 (patch) | |
tree | a1070f27993de91489d26cea03f7e47ebccf9738 /bridge/mattermost | |
parent | 6a7adb20a8f9f54d408f573763bc86d2670a0cf7 (diff) | |
download | matterbridge-msglm-c4b75e5754c58758c920c79b0458171e98269961.tar.gz matterbridge-msglm-c4b75e5754c58758c920c79b0458171e98269961.tar.bz2 matterbridge-msglm-c4b75e5754c58758c920c79b0458171e98269961.zip |
Download files from slack and reupload to mattermost (slack/mattermost). Closes #255
Refactor message.Extra to a map[string][]interface{} to have a bit more flexibility
for stuffing extra stuff.
For attached files from slack, files < 1MB size get downloaded (in memory), and get
put into Extra["file"][]config.FileInfo (containing a pointer to the buffer and
the filename). This is not async so slack channels with lots of attached files
may suffer a slowdown. (the download timeout is set at 5 seconds).
Diffstat (limited to 'bridge/mattermost')
-rw-r--r-- | bridge/mattermost/mattermost.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index bedd07a8..985d0d76 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -26,7 +26,7 @@ type MMMessage struct { UserID string ID string Event string - Extra []interface{} + Extra map[string][]interface{} } type Bmattermost struct { @@ -179,6 +179,21 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) { } return msg.ID, b.mc.DeleteMessage(msg.ID) } + if msg.Extra != nil { + for _, f := range msg.Extra["file"] { + fi := f.(config.FileInfo) + id, err := b.mc.UploadFile(*fi.Data, b.mc.GetChannelId(channel, ""), fi.Name) + if err != nil { + flog.Debugf("ERROR %#v", err) + return "", err + } + message = "uploaded a file: " + fi.Name + if b.Config.PrefixMessagesWithNick { + message = nick + "uploaded a file: " + fi.Name + } + return b.mc.PostMessageWithFiles(b.mc.GetChannelId(channel, ""), message, []string{id}) + } + } if msg.ID != "" { return b.mc.EditMessage(msg.ID, message) } @@ -225,7 +240,7 @@ func (b *Bmattermost) handleMatterClient(mchan chan *MMMessage) { continue } - m := &MMMessage{} + m := &MMMessage{Extra: make(map[string][]interface{})} props := message.Post.Props if props != nil { @@ -237,7 +252,7 @@ func (b *Bmattermost) handleMatterClient(mchan chan *MMMessage) { message.Username = props["override_username"].(string) } if _, ok := props["attachments"].([]interface{}); ok { - m.Extra = props["attachments"].([]interface{}) + m.Extra["attachments"] = props["attachments"].([]interface{}) } } // do not post our own messages back to irc |