mirror of
https://github.com/42wim/matterbridge
synced 2024-11-15 06:12:55 +00:00
Use blocks not attachments (slack) (#1048)
This removes the extra space below messages, as shown in https://user-images.githubusercontent.com/923242/77235190-a3359980-6bab-11ea-8b7b-697d730ae5c1.png
This commit is contained in:
parent
0951e75c85
commit
d4acdf2f89
@ -124,10 +124,16 @@ func (b *Bslack) skipMessageEvent(ev *slack.MessageEvent) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for our callback ID
|
||||||
|
hasOurCallbackID := false
|
||||||
|
if len(ev.Blocks.BlockSet) == 1 {
|
||||||
|
block, ok := ev.Blocks.BlockSet[0].(*slack.SectionBlock)
|
||||||
|
hasOurCallbackID = ok && block.BlockID == "matterbridge_"+b.uuid
|
||||||
|
}
|
||||||
|
|
||||||
// Skip any messages that we made ourselves or from 'slackbot' (see #527).
|
// Skip any messages that we made ourselves or from 'slackbot' (see #527).
|
||||||
if ev.Username == sSlackBotUser ||
|
if ev.Username == sSlackBotUser ||
|
||||||
(b.rtm != nil && ev.Username == b.si.User.Name) ||
|
(b.rtm != nil && ev.Username == b.si.User.Name) || hasOurCallbackID {
|
||||||
(len(ev.Attachments) > 0 && ev.Attachments[0].CallbackID == "matterbridge_"+b.uuid) {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,7 +408,6 @@ func (b *Bslack) editMessage(msg *config.Message, channelInfo *slack.Channel) (b
|
|||||||
}
|
}
|
||||||
messageOptions := b.prepareMessageOptions(msg)
|
messageOptions := b.prepareMessageOptions(msg)
|
||||||
for {
|
for {
|
||||||
messageOptions = append(messageOptions, slack.MsgOptionText(msg.Text, false))
|
|
||||||
_, _, _, err := b.rtm.UpdateMessage(channelInfo.ID, msg.ID, messageOptions...)
|
_, _, _, err := b.rtm.UpdateMessage(channelInfo.ID, msg.ID, messageOptions...)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return true, nil
|
return true, nil
|
||||||
@ -427,11 +426,6 @@ func (b *Bslack) postMessage(msg *config.Message, channelInfo *slack.Channel) (s
|
|||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
messageOptions := b.prepareMessageOptions(msg)
|
messageOptions := b.prepareMessageOptions(msg)
|
||||||
messageOptions = append(
|
|
||||||
messageOptions,
|
|
||||||
slack.MsgOptionText(msg.Text, false),
|
|
||||||
slack.MsgOptionEnableLinkUnfurl(),
|
|
||||||
)
|
|
||||||
for {
|
for {
|
||||||
_, id, err := b.rtm.PostMessage(channelInfo.ID, messageOptions...)
|
_, id, err := b.rtm.PostMessage(channelInfo.ID, messageOptions...)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -497,9 +491,6 @@ func (b *Bslack) prepareMessageOptions(msg *config.Message) []slack.MsgOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var attachments []slack.Attachment
|
var attachments []slack.Attachment
|
||||||
// add a callback ID so we can see we created it
|
|
||||||
const zeroWidthSpace = "\u200b"
|
|
||||||
attachments = append(attachments, slack.Attachment{CallbackID: "matterbridge_" + b.uuid, Fallback: zeroWidthSpace})
|
|
||||||
// add file attachments
|
// add file attachments
|
||||||
attachments = append(attachments, b.createAttach(msg.Extra)...)
|
attachments = append(attachments, b.createAttach(msg.Extra)...)
|
||||||
// add slack attachments (from another slack bridge)
|
// add slack attachments (from another slack bridge)
|
||||||
@ -510,6 +501,19 @@ func (b *Bslack) prepareMessageOptions(msg *config.Message) []slack.MsgOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var opts []slack.MsgOption
|
var opts []slack.MsgOption
|
||||||
|
opts = append(opts,
|
||||||
|
// provide regular text field (fallback used in Slack notifications, etc.)
|
||||||
|
slack.MsgOptionText(msg.Text, false),
|
||||||
|
|
||||||
|
// add a callback ID so we can see we created it
|
||||||
|
slack.MsgOptionBlocks(slack.NewSectionBlock(
|
||||||
|
slack.NewTextBlockObject(slack.MarkdownType, msg.Text, false, false),
|
||||||
|
nil, nil,
|
||||||
|
slack.SectionBlockOptionBlockID("matterbridge_"+b.uuid),
|
||||||
|
)),
|
||||||
|
|
||||||
|
slack.MsgOptionEnableLinkUnfurl(),
|
||||||
|
)
|
||||||
opts = append(opts, slack.MsgOptionAttachments(attachments...))
|
opts = append(opts, slack.MsgOptionAttachments(attachments...))
|
||||||
opts = append(opts, slack.MsgOptionPostMessageParameters(params))
|
opts = append(opts, slack.MsgOptionPostMessageParameters(params))
|
||||||
return opts
|
return opts
|
||||||
|
Loading…
Reference in New Issue
Block a user