| 1 | package slack |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "fmt" |
| 6 | ) |
| 7 | |
| 8 | // AckMessage is used for messages received in reply to other messages |
| 9 | type AckMessage struct { |
| 10 | ReplyTo int `json:"reply_to"` |
| 11 | Timestamp string `json:"ts"` |
| 12 | Text string `json:"text"` |
| 13 | RTMResponse |
| 14 | } |
| 15 | |
| 16 | // RTMResponse encapsulates response details as returned by the Slack API |
| 17 | type RTMResponse struct { |
| 18 | Ok bool `json:"ok"` |
| 19 | Error *RTMError `json:"error"` |
| 20 | } |
| 21 | |
| 22 | // RTMError encapsulates error information as returned by the Slack API |
| 23 | type RTMError struct { |
| 24 | Code int |
| 25 | Msg string |
| 26 | } |
| 27 | |
| 28 | func (s RTMError) Error() string { |
| 29 | return fmt.Sprintf("Code %d - %s", s.Code, s.Msg) |
| 30 | } |
| 31 | |
| 32 | // MessageEvent represents a Slack Message (used as the event type for an incoming message) |
| 33 | type MessageEvent Message |
| 34 | |
| 35 | // RTMEvent is the main wrapper. You will find all the other messages attached |
| 36 | type RTMEvent struct { |
| 37 | Type string |
| 38 | Data interface{} |
| 39 | } |
| 40 | |
| 41 | // HelloEvent represents the hello event |
| 42 | type HelloEvent struct{} |
| 43 | |
| 44 | // PresenceChangeEvent represents the presence change event |
| 45 | type PresenceChangeEvent struct { |
| 46 | Type string `json:"type"` |
| 47 | Presence string `json:"presence"` |
| 48 | User string `json:"user"` |
| 49 | Users []string `json:"users"` |
| 50 | } |
| 51 | |
| 52 | // UserTypingEvent represents the user typing event |
| 53 | type UserTypingEvent struct { |
| 54 | Type string `json:"type"` |
| 55 | User string `json:"user"` |
| 56 | Channel string `json:"channel"` |
| 57 | } |
| 58 | |
| 59 | // PrefChangeEvent represents a user preferences change event |
| 60 | type PrefChangeEvent struct { |
| 61 | Type string `json:"type"` |
| 62 | Name string `json:"name"` |
| 63 | Value json.RawMessage `json:"value"` |
| 64 | } |
| 65 | |
| 66 | // ManualPresenceChangeEvent represents the manual presence change event |
| 67 | type ManualPresenceChangeEvent struct { |
| 68 | Type string `json:"type"` |
| 69 | Presence string `json:"presence"` |
| 70 | } |
| 71 | |
| 72 | // UserChangeEvent represents the user change event |
| 73 | type UserChangeEvent struct { |
| 74 | Type string `json:"type"` |
| 75 | User User `json:"user"` |
| 76 | } |
| 77 | |
| 78 | // EmojiChangedEvent represents the emoji changed event |
| 79 | type EmojiChangedEvent struct { |
| 80 | Type string `json:"type"` |
| 81 | SubType string `json:"subtype"` |
| 82 | Name string `json:"name"` |
| 83 | Names []string `json:"names"` |
| 84 | Value string `json:"value"` |
| 85 | EventTimestamp string `json:"event_ts"` |
| 86 | } |
| 87 | |
| 88 | // CommandsChangedEvent represents the commands changed event |
| 89 | type CommandsChangedEvent struct { |
| 90 | Type string `json:"type"` |
| 91 | EventTimestamp string `json:"event_ts"` |
| 92 | } |
| 93 | |
| 94 | // EmailDomainChangedEvent represents the email domain changed event |
| 95 | type EmailDomainChangedEvent struct { |
| 96 | Type string `json:"type"` |
| 97 | EventTimestamp string `json:"event_ts"` |
| 98 | EmailDomain string `json:"email_domain"` |
| 99 | } |
| 100 | |
| 101 | // BotAddedEvent represents the bot added event |
| 102 | type BotAddedEvent struct { |
| 103 | Type string `json:"type"` |
| 104 | Bot Bot `json:"bot"` |
| 105 | } |
| 106 | |
| 107 | // BotChangedEvent represents the bot changed event |
| 108 | type BotChangedEvent struct { |
| 109 | Type string `json:"type"` |
| 110 | Bot Bot `json:"bot"` |
| 111 | } |
| 112 | |
| 113 | // AccountsChangedEvent represents the accounts changed event |
| 114 | type AccountsChangedEvent struct { |
| 115 | Type string `json:"type"` |
| 116 | } |
| 117 | |
| 118 | // ReconnectUrlEvent represents the receiving reconnect url event |
| 119 | type ReconnectUrlEvent struct { |
| 120 | Type string `json:"type"` |
| 121 | URL string `json:"url"` |
| 122 | } |
| 123 | |
| 124 | // MemberJoinedChannelEvent, a user joined a public or private channel |
| 125 | type MemberJoinedChannelEvent struct { |
| 126 | Type string `json:"type"` |
| 127 | User string `json:"user"` |
| 128 | Channel string `json:"channel"` |
| 129 | ChannelType string `json:"channel_type"` |
| 130 | Team string `json:"team"` |
| 131 | Inviter string `json:"inviter"` |
| 132 | } |
| 133 | |
| 134 | // MemberLeftChannelEvent a user left a public or private channel |
| 135 | type MemberLeftChannelEvent struct { |
| 136 | Type string `json:"type"` |
| 137 | User string `json:"user"` |
| 138 | Channel string `json:"channel"` |
| 139 | ChannelType string `json:"channel_type"` |
| 140 | Team string `json:"team"` |
| 141 | } |