summaryrefslogtreecommitdiffstats
path: root/bridge/slack
diff options
context:
space:
mode:
authorPatrick Connolly <patrick.c.connolly@gmail.com>2017-11-03 15:32:28 -0400
committerWim <wim@42.be>2017-11-03 20:32:28 +0100
commitbea0bbd0c2921343c70d4a0ef78df61ce884cbc2 (patch)
tree720623c80df354f460a1c3a0092a498438fa14ea /bridge/slack
parent0530503ef28b2cbf71bb8a9d6867e2cafe9c2a7c (diff)
downloadmatterbridge-msglm-bea0bbd0c2921343c70d4a0ef78df61ce884cbc2.tar.gz
matterbridge-msglm-bea0bbd0c2921343c70d4a0ef78df61ce884cbc2.tar.bz2
matterbridge-msglm-bea0bbd0c2921343c70d4a0ef78df61ce884cbc2.zip
Allow slack messages with variables (eg. @here) to be formatted correctly. (slack) (#288)
Diffstat (limited to 'bridge/slack')
-rw-r--r--bridge/slack/slack.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go
index c09d6f90..11a84a12 100644
--- a/bridge/slack/slack.go
+++ b/bridge/slack/slack.go
@@ -340,6 +340,7 @@ func (b *Bslack) handleSlackClient(mchan chan *MMMessage) {
}
m.Raw = ev
m.Text = b.replaceMention(m.Text)
+ m.Text = b.replaceVariable(m.Text)
m.Text = b.replaceChannel(m.Text)
// when using webhookURL we can't check if it's our webhook or not for now
if ev.BotID != "" && b.Config.WebhookURL == "" {
@@ -387,6 +388,7 @@ func (b *Bslack) handleMatterHook(mchan chan *MMMessage) {
m.Username = message.UserName
m.Text = message.Text
m.Text = b.replaceMention(m.Text)
+ m.Text = b.replaceVariable(m.Text)
m.Text = b.replaceChannel(m.Text)
m.Channel = message.ChannelName
if m.Username == "slackbot" {
@@ -408,6 +410,7 @@ func (b *Bslack) userName(id string) string {
return ""
}
+// @see https://api.slack.com/docs/message-formatting#linking_to_channels_and_users
func (b *Bslack) replaceMention(text string) string {
results := regexp.MustCompile(`<@([a-zA-z0-9]+)>`).FindAllStringSubmatch(text, -1)
for _, r := range results {
@@ -416,6 +419,7 @@ func (b *Bslack) replaceMention(text string) string {
return text
}
+// @see https://api.slack.com/docs/message-formatting#linking_to_channels_and_users
func (b *Bslack) replaceChannel(text string) string {
results := regexp.MustCompile(`<#[a-zA-Z0-9]+\|(.+?)>`).FindAllStringSubmatch(text, -1)
for _, r := range results {
@@ -424,6 +428,16 @@ func (b *Bslack) replaceChannel(text string) string {
return text
}
+// @see https://api.slack.com/docs/message-formatting#variables
+func (b *Bslack) replaceVariable(text string) string {
+ results := regexp.MustCompile(`<!([a-zA-Z0-9]+)(\|.+?)?>`).FindAllStringSubmatch(text, -1)
+ for _, r := range results {
+ text = strings.Replace(text, r[0], "@"+r[1], -1)
+ }
+ return text
+}
+
+// @see https://api.slack.com/docs/message-formatting#linking_to_urls
func (b *Bslack) replaceURL(text string) string {
results := regexp.MustCompile(`<(.*?)(\|.*?)?>`).FindAllStringSubmatch(text, -1)
for _, r := range results {