diff options
author | Patrick Connolly <patrick.c.connolly@gmail.com> | 2018-12-02 02:55:35 +0800 |
---|---|---|
committer | Wim <wim@42.be> | 2018-12-01 19:55:35 +0100 |
commit | e538a4d30459e9da1a021400b5de85894b4efabc (patch) | |
tree | ead4f82d5459fe0d3465f7e3656243cd613c07a6 /bridge/slack | |
parent | f94c2b40a3e8eb45054bda1b71eb6fd3f9bc9e6d (diff) | |
download | matterbridge-msglm-e538a4d30459e9da1a021400b5de85894b4efabc.tar.gz matterbridge-msglm-e538a4d30459e9da1a021400b5de85894b4efabc.tar.bz2 matterbridge-msglm-e538a4d30459e9da1a021400b5de85894b4efabc.zip |
Update nlopes/slack to 4.1-dev (#595)
Diffstat (limited to 'bridge/slack')
-rw-r--r-- | bridge/slack/slack.go | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index a38bbb53..9b64f7a4 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -303,12 +303,13 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) { return msg.ID, err } - messageParameters := b.prepareMessageParameters(&msg) - // Upload a file if it exists. if msg.Extra != nil { - for _, rmsg := range helper.HandleExtra(&msg, b.General) { - _, _, err = b.rtm.PostMessage(channelInfo.ID, rmsg.Username+rmsg.Text, *messageParameters) + extraMsgs := helper.HandleExtra(&msg, b.General) + for i := range extraMsgs { + rmsg := &extraMsgs[i] + rmsg.Text = rmsg.Username + rmsg.Text + _, err = b.postMessage(rmsg, channelInfo) if err != nil { b.Log.Error(err) } @@ -318,7 +319,7 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) { } // Post message. - return b.postMessage(&msg, messageParameters, channelInfo) + return b.postMessage(&msg, channelInfo) } func (b *Bslack) updateTopicOrPurpose(msg *config.Message, channelInfo *slack.Channel) (bool, error) { @@ -391,9 +392,10 @@ func (b *Bslack) editMessage(msg *config.Message, channelInfo *slack.Channel) (b if msg.ID == "" { return false, nil } - + messageOptions := b.prepareMessageOptions(msg) for { - _, _, _, err := b.rtm.UpdateMessage(channelInfo.ID, msg.ID, msg.Text) + messageOptions = append(messageOptions, slack.MsgOptionText(msg.Text, false)) + _, _, _, err := b.rtm.UpdateMessage(channelInfo.ID, msg.ID, messageOptions...) if err == nil { return true, nil } @@ -405,13 +407,15 @@ func (b *Bslack) editMessage(msg *config.Message, channelInfo *slack.Channel) (b } } -func (b *Bslack) postMessage(msg *config.Message, messageParameters *slack.PostMessageParameters, channelInfo *slack.Channel) (string, error) { +func (b *Bslack) postMessage(msg *config.Message, channelInfo *slack.Channel) (string, error) { // don't post empty messages if msg.Text == "" { return "", nil } + messageOptions := b.prepareMessageOptions(msg) + messageOptions = append(messageOptions, slack.MsgOptionText(msg.Text, false)) for { - _, id, err := b.rtm.PostMessage(channelInfo.ID, msg.Text, *messageParameters) + _, id, err := b.rtm.PostMessage(channelInfo.ID, messageOptions...) if err == nil { return id, nil } @@ -461,7 +465,7 @@ func (b *Bslack) uploadFile(msg *config.Message, channelID string) { } } -func (b *Bslack) prepareMessageParameters(msg *config.Message) *slack.PostMessageParameters { +func (b *Bslack) prepareMessageOptions(msg *config.Message) []slack.MsgOption { params := slack.NewPostMessageParameters() if b.GetBool(useNickPrefixConfig) { params.AsUser = true @@ -473,17 +477,23 @@ func (b *Bslack) prepareMessageParameters(msg *config.Message) *slack.PostMessag if msg.Avatar != "" { params.IconURL = msg.Avatar } + + var attachments []slack.Attachment // add a callback ID so we can see we created it - params.Attachments = append(params.Attachments, slack.Attachment{CallbackID: "matterbridge_" + b.uuid}) + attachments = append(attachments, slack.Attachment{CallbackID: "matterbridge_" + b.uuid}) // add file attachments - params.Attachments = append(params.Attachments, b.createAttach(msg.Extra)...) + attachments = append(attachments, b.createAttach(msg.Extra)...) // add slack attachments (from another slack bridge) if msg.Extra != nil { for _, attach := range msg.Extra[sSlackAttachment] { - params.Attachments = append(params.Attachments, attach.([]slack.Attachment)...) + attachments = append(attachments, attach.([]slack.Attachment)...) } } - return ¶ms + + var opts []slack.MsgOption + opts = append(opts, slack.MsgOptionAttachments(attachments...)) + opts = append(opts, slack.MsgOptionPostMessageParameters(params)) + return opts } func (b *Bslack) createAttach(extra map[string][]interface{}) []slack.Attachment { |