| 1 | package slack |
| 2 | |
| 3 | const ( |
| 4 | TYPE_MESSAGE = "message" |
| 5 | TYPE_FILE = "file" |
| 6 | TYPE_FILE_COMMENT = "file_comment" |
| 7 | TYPE_CHANNEL = "channel" |
| 8 | TYPE_IM = "im" |
| 9 | TYPE_GROUP = "group" |
| 10 | ) |
| 11 | |
| 12 | // Item is any type of slack message - message, file, or file comment. |
| 13 | type Item struct { |
| 14 | Type string `json:"type"` |
| 15 | Channel string `json:"channel,omitempty"` |
| 16 | Message *Message `json:"message,omitempty"` |
| 17 | File *File `json:"file,omitempty"` |
| 18 | Comment *Comment `json:"comment,omitempty"` |
| 19 | Timestamp string `json:"ts,omitempty"` |
| 20 | } |
| 21 | |
| 22 | // NewMessageItem turns a message on a channel into a typed message struct. |
| 23 | func NewMessageItem(ch string, m *Message) Item { |
| 24 | return Item{Type: TYPE_MESSAGE, Channel: ch, Message: m} |
| 25 | } |
| 26 | |
| 27 | // NewFileItem turns a file into a typed file struct. |
| 28 | func NewFileItem(f *File) Item { |
| 29 | return Item{Type: TYPE_FILE, File: f} |
| 30 | } |
| 31 | |
| 32 | // NewFileCommentItem turns a file and comment into a typed file_comment struct. |
| 33 | func NewFileCommentItem(f *File, c *Comment) Item { |
| 34 | return Item{Type: TYPE_FILE_COMMENT, File: f, Comment: c} |
| 35 | } |
| 36 | |
| 37 | // NewChannelItem turns a channel id into a typed channel struct. |
| 38 | func NewChannelItem(ch string) Item { |
| 39 | return Item{Type: TYPE_CHANNEL, Channel: ch} |
| 40 | } |
| 41 | |
| 42 | // NewIMItem turns a channel id into a typed im struct. |
| 43 | func NewIMItem(ch string) Item { |
| 44 | return Item{Type: TYPE_IM, Channel: ch} |
| 45 | } |
| 46 | |
| 47 | // NewGroupItem turns a channel id into a typed group struct. |
| 48 | func NewGroupItem(ch string) Item { |
| 49 | return Item{Type: TYPE_GROUP, Channel: ch} |
| 50 | } |
| 51 | |
| 52 | // ItemRef is a reference to a message of any type. One of FileID, |
| 53 | // CommentId, or the combination of ChannelId and Timestamp must be |
| 54 | // specified. |
| 55 | type ItemRef struct { |
| 56 | Channel string `json:"channel"` |
| 57 | Timestamp string `json:"timestamp"` |
| 58 | File string `json:"file"` |
| 59 | Comment string `json:"file_comment"` |
| 60 | } |
| 61 | |
| 62 | // NewRefToMessage initializes a reference to to a message. |
| 63 | func NewRefToMessage(channel, timestamp string) ItemRef { |
| 64 | return ItemRef{Channel: channel, Timestamp: timestamp} |
| 65 | } |
| 66 | |
| 67 | // NewRefToFile initializes a reference to a file. |
| 68 | func NewRefToFile(file string) ItemRef { |
| 69 | return ItemRef{File: file} |
| 70 | } |
| 71 | |
| 72 | // NewRefToComment initializes a reference to a file comment. |
| 73 | func NewRefToComment(comment string) ItemRef { |
| 74 | return ItemRef{Comment: comment} |
| 75 | } |