summaryrefslogtreecommitdiffstats
path: root/app/webhook.go
diff options
context:
space:
mode:
authorJoey Lee <jayd005@gmail.com>2018-01-27 00:37:39 +1100
committerJoram Wilander <jwawilander@gmail.com>2018-01-26 08:37:39 -0500
commit1c7f25773a77ceb9e84feabe3907e7f93f6870e4 (patch)
tree334f6d4cb875f36af4d0e4fa2930883cd170f0b0 /app/webhook.go
parent540dd9ae942787279c2fe439a9182223c1a11d2c (diff)
downloadchat-1c7f25773a77ceb9e84feabe3907e7f93f6870e4.tar.gz
chat-1c7f25773a77ceb9e84feabe3907e7f93f6870e4.tar.bz2
chat-1c7f25773a77ceb9e84feabe3907e7f93f6870e4.zip
PLT-3658 Added support for Slack attachments in outgoing webhook response (#7774) (#8102)
Diffstat (limited to 'app/webhook.go')
-rw-r--r--app/webhook.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/app/webhook.go b/app/webhook.go
index 14dec3daa..a9bb32f35 100644
--- a/app/webhook.go
+++ b/app/webhook.go
@@ -113,7 +113,7 @@ func (a *App) TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.
webhookResp := model.OutgoingWebhookResponseFromJson(resp.Body)
- if webhookResp != nil && webhookResp.Text != nil {
+ if webhookResp != nil && (webhookResp.Text != nil || len(webhookResp.Attachments) > 0) {
postRootId := ""
if webhookResp.ResponseType == model.OUTGOING_HOOK_RESPONSE_TYPE_COMMENT {
postRootId = post.Id
@@ -122,7 +122,18 @@ func (a *App) TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.
webhookResp.Props = make(model.StringInterface)
}
webhookResp.Props["webhook_display_name"] = hook.DisplayName
- if _, err := a.CreateWebhookPost(hook.CreatorId, channel, *webhookResp.Text, webhookResp.Username, webhookResp.IconURL, webhookResp.Props, webhookResp.Type, postRootId); err != nil {
+
+ text := ""
+ if webhookResp.Text != nil {
+ text = a.ProcessSlackText(*webhookResp.Text)
+ }
+ webhookResp.Attachments = a.ProcessSlackAttachments(webhookResp.Attachments)
+ // attachments is in here for slack compatibility
+ if len(webhookResp.Attachments) > 0 {
+ webhookResp.Props["attachments"] = webhookResp.Attachments
+ }
+
+ if _, err := a.CreateWebhookPost(hook.CreatorId, channel, text, webhookResp.Username, webhookResp.IconURL, webhookResp.Props, webhookResp.Type, postRootId); err != nil {
l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.create_post.error"), err)
}
}