summaryrefslogtreecommitdiffstats
path: root/api/post.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-12-03 14:56:10 -0500
committerJoramWilander <jwawilander@gmail.com>2015-12-03 14:56:10 -0500
commit0466d0fde9fb0bc9452fca531e96490ae274eb55 (patch)
tree302c7eeebb7dc642abf5d83d64fe56287268c65c /api/post.go
parent3e455959c62a094911d7b435d46627f8c37a3394 (diff)
downloadchat-0466d0fde9fb0bc9452fca531e96490ae274eb55.tar.gz
chat-0466d0fde9fb0bc9452fca531e96490ae274eb55.tar.bz2
chat-0466d0fde9fb0bc9452fca531e96490ae274eb55.zip
Convert links in Slack attachment text to Markdown format
Diffstat (limited to 'api/post.go')
-rw-r--r--api/post.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/api/post.go b/api/post.go
index 81cc9a1c6..6785a8c44 100644
--- a/api/post.go
+++ b/api/post.go
@@ -177,7 +177,22 @@ 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})")
+ aText = linkRegex.ReplaceAllString(aText, "${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)
}
}