diff options
author | Wim <wim@42.be> | 2017-11-13 00:20:31 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2017-11-13 00:20:31 +0100 |
commit | 36a800c3f57ed1880ed6530db0542c979f6c69e7 (patch) | |
tree | 045b287bd5087558e3756f870a4336061490ef60 /bridge/slack | |
parent | 6d21f84187cddf17a2758a57bc77c37ed9e7ba70 (diff) | |
download | matterbridge-msglm-36a800c3f57ed1880ed6530db0542c979f6c69e7.tar.gz matterbridge-msglm-36a800c3f57ed1880ed6530db0542c979f6c69e7.tar.bz2 matterbridge-msglm-36a800c3f57ed1880ed6530db0542c979f6c69e7.zip |
Add support for comments from slack file uploads (slack)
Diffstat (limited to 'bridge/slack')
-rw-r--r-- | bridge/slack/slack.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index 74003753..b753c1a5 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -195,9 +195,10 @@ func (b *Bslack) Send(msg config.Message) (string, 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}, + Reader: bytes.NewReader(*fi.Data), + Filename: fi.Name, + Channels: []string{schannel.ID}, + InitialComment: fi.Comment, }) if err != nil { flog.Errorf("uploadfile %#v", err) @@ -294,16 +295,21 @@ func (b *Bslack) handleSlack() { if message.Raw.File != nil { // limit to 1MB for now if message.Raw.File.Size <= 1000000 { + comment := "" data, err := b.downloadFile(message.Raw.File.URLPrivateDownload) if err != nil { flog.Errorf("download %s failed %#v", message.Raw.File.URLPrivateDownload, err) } else { - msg.Extra["file"] = append(msg.Extra["file"], config.FileInfo{Name: message.Raw.File.Name, Data: data}) + results := regexp.MustCompile(`.*?commented: (.*)`).FindAllStringSubmatch(msg.Text, -1) + if len(results) > 0 { + comment = results[0][1] + } + msg.Extra["file"] = append(msg.Extra["file"], config.FileInfo{Name: message.Raw.File.Name, Data: data, Comment: comment}) } + flog.Debugf("Message is %#v", msg) + b.Remote <- msg } } - flog.Debugf("Message is %#v", msg) - b.Remote <- msg } } |