github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/model/slack_attachment.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "fmt" 8 ) 9 10 type SlackAttachment struct { 11 Id int64 `json:"id"` 12 Fallback string `json:"fallback"` 13 Color string `json:"color"` 14 Pretext string `json:"pretext"` 15 AuthorName string `json:"author_name"` 16 AuthorLink string `json:"author_link"` 17 AuthorIcon string `json:"author_icon"` 18 Title string `json:"title"` 19 TitleLink string `json:"title_link"` 20 Text string `json:"text"` 21 Fields []*SlackAttachmentField `json:"fields"` 22 ImageURL string `json:"image_url"` 23 ThumbURL string `json:"thumb_url"` 24 Footer string `json:"footer"` 25 FooterIcon string `json:"footer_icon"` 26 Timestamp interface{} `json:"ts"` // This is either a string or an int64 27 Actions []*PostAction `json:"actions,omitempty"` 28 } 29 30 type SlackAttachmentField struct { 31 Title string `json:"title"` 32 Value interface{} `json:"value"` 33 Short bool `json:"short"` 34 } 35 36 func StringifySlackFieldValue(a []*SlackAttachment) []*SlackAttachment { 37 var nonNilAttachments []*SlackAttachment 38 for _, attachment := range a { 39 if attachment == nil { 40 continue 41 } 42 nonNilAttachments = append(nonNilAttachments, attachment) 43 44 var nonNilFields []*SlackAttachmentField 45 for _, field := range attachment.Fields { 46 if field == nil { 47 continue 48 } 49 nonNilFields = append(nonNilFields, field) 50 51 if field.Value != nil { 52 // Ensure the value is set to a string if it is set 53 field.Value = fmt.Sprintf("%v", field.Value) 54 } 55 } 56 attachment.Fields = nonNilFields 57 } 58 return nonNilAttachments 59 }