diff options
author | Chris <ccbrown112@gmail.com> | 2017-07-12 06:43:07 -0700 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-07-12 09:43:07 -0400 |
commit | 9ee7f661c76d7ef07ac03772a7cf0394217203f3 (patch) | |
tree | 1dc5784a56f8fd39f43349425c24555d0389e257 /model/command_response.go | |
parent | 83d53ea98cf5486f89bd4280b6b5ef835da4fd22 (diff) | |
download | chat-9ee7f661c76d7ef07ac03772a7cf0394217203f3.tar.gz chat-9ee7f661c76d7ef07ac03772a7cf0394217203f3.tar.bz2 chat-9ee7f661c76d7ef07ac03772a7cf0394217203f3.zip |
PLT-7077: ignore null array items in slack attachments (#6904)
* ignore null array items in incoming webhooks / command responses
* consolidate code, process announcements in command response as well
* make a bit more idiomatic, add tests
* add missing file
Diffstat (limited to 'model/command_response.go')
-rw-r--r-- | model/command_response.go | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/model/command_response.go b/model/command_response.go index 1b2e06cdf..e3253acc0 100644 --- a/model/command_response.go +++ b/model/command_response.go @@ -5,7 +5,6 @@ package model import ( "encoding/json" - "fmt" "io" ) @@ -15,12 +14,12 @@ const ( ) type CommandResponse struct { - ResponseType string `json:"response_type"` - Text string `json:"text"` - Username string `json:"username"` - IconURL string `json:"icon_url"` - GotoLocation string `json:"goto_location"` - Attachments []*SlackAttachment `json:"attachments"` + ResponseType string `json:"response_type"` + Text string `json:"text"` + Username string `json:"username"` + IconURL string `json:"icon_url"` + GotoLocation string `json:"goto_location"` + Attachments SlackAttachments `json:"attachments"` } func (o *CommandResponse) ToJson() string { @@ -40,14 +39,8 @@ func CommandResponseFromJson(data io.Reader) *CommandResponse { return nil } - // Ensure attachment fields are stored as strings - for _, attachment := range o.Attachments { - for _, field := range attachment.Fields { - if field.Value != nil { - field.Value = fmt.Sprintf("%v", field.Value) - } - } - } + o.Text = ExpandAnnouncement(o.Text) + o.Attachments.Process() return &o } |