summaryrefslogtreecommitdiffstats
path: root/bridge/slack/helpers.go
diff options
context:
space:
mode:
authorAndy <flashgame73@gmail.com>2022-05-10 00:56:19 +0400
committerGitHub <noreply@github.com>2022-05-09 22:56:19 +0200
commit700b95546b4fbc4bbd094ab1804406c13634d7e2 (patch)
tree2b86658952deb8f7761fd276e89164ff3afd1526 /bridge/slack/helpers.go
parent2fa96ec0ed5d78357a11dee158cac9a9e6d7090d (diff)
downloadmatterbridge-msglm-700b95546b4fbc4bbd094ab1804406c13634d7e2.tar.gz
matterbridge-msglm-700b95546b4fbc4bbd094ab1804406c13634d7e2.tar.bz2
matterbridge-msglm-700b95546b4fbc4bbd094ab1804406c13634d7e2.zip
Improve Slack attachments formatting (slack) (#1807)
* Improve Slack attachments formatting (slack) * Add TitleLink * Add Footer * Fix linter issues
Diffstat (limited to 'bridge/slack/helpers.go')
-rw-r--r--bridge/slack/helpers.go11
1 files changed, 2 insertions, 9 deletions
diff --git a/bridge/slack/helpers.go b/bridge/slack/helpers.go
index bdacd7ee..e46e2725 100644
--- a/bridge/slack/helpers.go
+++ b/bridge/slack/helpers.go
@@ -127,7 +127,7 @@ var (
mentionRE = regexp.MustCompile(`<@([a-zA-Z0-9]+)>`)
channelRE = regexp.MustCompile(`<#[a-zA-Z0-9]+\|(.+?)>`)
variableRE = regexp.MustCompile(`<!((?:subteam\^)?[a-zA-Z0-9]+)(?:\|@?(.+?))?>`)
- urlRE = regexp.MustCompile(`<(.*?)(\|.*?)?>`)
+ urlRE = regexp.MustCompile(`<([^<\|]+)\|([^>]+)>`)
codeFenceRE = regexp.MustCompile(`(?m)^` + "```" + `\w+$`)
topicOrPurposeRE = regexp.MustCompile(`(?s)(@.+) (cleared|set)(?: the)? channel (topic|purpose)(?:: (.*))?`)
)
@@ -181,14 +181,7 @@ func (b *Bslack) replaceVariable(text string) string {
// @see https://api.slack.com/docs/message-formatting#linking_to_urls
func (b *Bslack) replaceURL(text string) string {
- for _, r := range urlRE.FindAllStringSubmatch(text, -1) {
- if len(strings.TrimSpace(r[2])) == 1 { // A display text separator was found, but the text was blank
- text = strings.Replace(text, r[0], "", 1)
- } else {
- text = strings.Replace(text, r[0], r[1], 1)
- }
- }
- return text
+ return urlRE.ReplaceAllString(text, "[${2}](${1})")
}
func (b *Bslack) replaceb0rkedMarkDown(text string) string {