Skip to content

Commit

Permalink
Add omitempty to legacy fields in Attachment struct
Browse files Browse the repository at this point in the history
When using `Blocks` in `Attachment` with `Text` and `Fallback` fields,
slack api returns `invalid_attachments` error.
`Attachment` shouldn't have these legacy fields.
  • Loading branch information
0gajun authored and james-lawrence committed Nov 2, 2019
1 parent 2613fda commit dda08e2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type ConfirmationField struct {
// Attachment contains all the information for an attachment
type Attachment struct {
Color string `json:"color,omitempty"`
Fallback string `json:"fallback"`
Fallback string `json:"fallback,omitempty"`

CallbackID string `json:"callback_id,omitempty"`
ID int `json:"id,omitempty"`
Expand All @@ -75,7 +75,7 @@ type Attachment struct {
Title string `json:"title,omitempty"`
TitleLink string `json:"title_link,omitempty"`
Pretext string `json:"pretext,omitempty"`
Text string `json:"text"`
Text string `json:"text,omitempty"`

ImageURL string `json:"image_url,omitempty"`
ThumbURL string `json:"thumb_url,omitempty"`
Expand Down
3 changes: 1 addition & 2 deletions chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ func TestPostMessage(t *testing.T) {
opt: []MsgOption{
MsgOptionAttachments(
Attachment{
Text: "text",
Blocks: blocks,
}),
},
expected: url.Values{
"attachments": []string{`[{"fallback":"","text":"text","blocks":` + blockStr + `}]`},
"attachments": []string{`[{"blocks":` + blockStr + `}]`},
"channel": []string{"CXXX"},
"token": []string{"testing-token"},
},
Expand Down

0 comments on commit dda08e2

Please sign in to comment.