From 6f187903522dc629c4c4f3171775f83021dcc4e5 Mon Sep 17 00:00:00 2001 From: Wim Date: Fri, 3 Nov 2017 23:10:16 +0100 Subject: Add support to upload files to slack, from bridges with private urls like slack/mattermost/telegram. (slack) --- bridge/slack/slack.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'bridge') diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index 11a84a12..74003753 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -187,6 +187,25 @@ func (b *Bslack) Send(msg config.Message) (string, error) { b.sc.UpdateMessage(schannel.ID, ts[1], message) return "", nil } + + if msg.Extra != nil { + // check if we have files to upload (from slack, telegram or mattermost) + if len(msg.Extra["file"]) > 0 { + var err error + for _, f := range msg.Extra["file"] { + fi := f.(config.FileInfo) + _, err = b.sc.UploadFile(slack.FileUploadParameters{ + Reader: bytes.NewReader(*fi.Data), + Filename: fi.Name, + Channels: []string{schannel.ID}, + }) + if err != nil { + flog.Errorf("uploadfile %#v", err) + } + } + } + } + _, id, err := b.sc.PostMessage(schannel.ID, message, np) if err != nil { return "", err -- cgit v1.2.3