| 1 | // outer_events.go provides EventsAPI particular outer events |
| 2 | |
| 3 | package slackevents |
| 4 | |
| 5 | import ( |
| 6 | "encoding/json" |
| 7 | ) |
| 8 | |
| 9 | // EventsAPIEvent is the base EventsAPIEvent |
| 10 | type EventsAPIEvent struct { |
| 11 | Token string `json:"token"` |
| 12 | TeamID string `json:"team_id"` |
| 13 | Type string `json:"type"` |
| 14 | APIAppID string `json:"api_app_id"` |
| 15 | EnterpriseID string `json:"enterprise_id"` |
| 16 | Data interface{} |
| 17 | InnerEvent EventsAPIInnerEvent |
| 18 | } |
| 19 | |
| 20 | // EventsAPIURLVerificationEvent received when configuring a EventsAPI driven app |
| 21 | type EventsAPIURLVerificationEvent struct { |
| 22 | Token string `json:"token"` |
| 23 | Challenge string `json:"challenge"` |
| 24 | Type string `json:"type"` |
| 25 | } |
| 26 | |
| 27 | // ChallengeResponse is a response to a EventsAPIEvent URLVerification challenge |
| 28 | type ChallengeResponse struct { |
| 29 | Challenge string |
| 30 | } |
| 31 | |
| 32 | // EventsAPICallbackEvent is the main (outer) EventsAPI event. |
| 33 | type EventsAPICallbackEvent struct { |
| 34 | Type string `json:"type"` |
| 35 | Token string `json:"token"` |
| 36 | TeamID string `json:"team_id"` |
| 37 | APIAppID string `json:"api_app_id"` |
| 38 | InnerEvent *json.RawMessage `json:"event"` |
| 39 | AuthedUsers []string `json:"authed_users"` |
| 40 | AuthedTeams []string `json:"authed_teams"` |
| 41 | EventID string `json:"event_id"` |
| 42 | EventTime int `json:"event_time"` |
| 43 | EventContext string `json:"event_context"` |
| 44 | } |
| 45 | |
| 46 | // EventsAPIAppRateLimited indicates your app's event subscriptions are being rate limited |
| 47 | type EventsAPIAppRateLimited struct { |
| 48 | Type string `json:"type"` |
| 49 | Token string `json:"token"` |
| 50 | TeamID string `json:"team_id"` |
| 51 | MinuteRateLimited int `json:"minute_rate_limited"` |
| 52 | APIAppID string `json:"api_app_id"` |
| 53 | } |
| 54 | |
| 55 | const ( |
| 56 | // CallbackEvent is the "outer" event of an EventsAPI event. |
| 57 | CallbackEvent = "event_callback" |
| 58 | // URLVerification is an event used when configuring your EventsAPI app |
| 59 | URLVerification = "url_verification" |
| 60 | // AppRateLimited indicates your app's event subscriptions are being rate limited |
| 61 | AppRateLimited = "app_rate_limited" |
| 62 | ) |
| 63 | |
| 64 | // EventsAPIEventMap maps OUTER Event API events to their corresponding struct |
| 65 | // implementations. The structs should be instances of the unmarshalling |
| 66 | // target for the matching event type. |
| 67 | var EventsAPIEventMap = map[string]interface{}{ |
| 68 | CallbackEvent: EventsAPICallbackEvent{}, |
| 69 | URLVerification: EventsAPIURLVerificationEvent{}, |
| 70 | AppRateLimited: EventsAPIAppRateLimited{}, |
| 71 | } |