summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-12-04 08:36:46 -0500
committerChristopher Speller <crspeller@gmail.com>2015-12-04 08:36:46 -0500
commitd6c5a78f746d3943c66f261b37174e7702cb8780 (patch)
tree01f4255dd637ccdfeeac10c0c9d16415ec79cbe5
parent04727955cd73864d23be9da7fb999d23e93a20e0 (diff)
parent9d804853f3c23bf528f0b8cb07034b208b97fa76 (diff)
downloadchat-d6c5a78f746d3943c66f261b37174e7702cb8780.tar.gz
chat-d6c5a78f746d3943c66f261b37174e7702cb8780.tar.bz2
chat-d6c5a78f746d3943c66f261b37174e7702cb8780.zip
Merge pull request #1603 from mattermost/plt-1192
PLT-1192 Convert links in Slack attachment text to Markdown format
-rw-r--r--api/post.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/api/post.go b/api/post.go
index 81cc9a1c6..40c5efe8c 100644
--- a/api/post.go
+++ b/api/post.go
@@ -153,9 +153,6 @@ func CreateWebhookPost(c *Context, channelId, text, overrideUsername, overrideIc
linkWithTextRegex := regexp.MustCompile(`<([^<\|]+)\|([^>]+)>`)
text = linkWithTextRegex.ReplaceAllString(text, "[${2}](${1})")
- linkRegex := regexp.MustCompile(`<\s*(\S*)\s*>`)
- text = linkRegex.ReplaceAllString(text, "${1}")
-
post := &model.Post{UserId: c.Session.UserId, ChannelId: channelId, Message: text, Type: postType}
post.AddProp("from_webhook", "true")
@@ -177,7 +174,21 @@ func CreateWebhookPost(c *Context, channelId, text, overrideUsername, overrideIc
if len(props) > 0 {
for key, val := range props {
- if key != "override_icon_url" && key != "override_username" && key != "from_webhook" {
+ if key == "attachments" {
+ if list, success := val.([]interface{}); success {
+ // parse attachment links into Markdown format
+ for i, aInt := range list {
+ attachment := aInt.(map[string]interface{})
+ if _, ok := attachment["text"]; ok {
+ aText := attachment["text"].(string)
+ aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})")
+ attachment["text"] = aText
+ list[i] = attachment
+ }
+ }
+ post.AddProp(key, list)
+ }
+ } else if key != "override_icon_url" && key != "override_username" && key != "from_webhook" {
post.AddProp(key, val)
}
}