| 1 | package slack |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "net/url" |
| 7 | ) |
| 8 | |
| 9 | type listEventAuthorizationsResponse struct { |
| 10 | SlackResponse |
| 11 | Authorizations []EventAuthorization `json:"authorizations"` |
| 12 | } |
| 13 | |
| 14 | type EventAuthorization struct { |
| 15 | EnterpriseID string `json:"enterprise_id"` |
| 16 | TeamID string `json:"team_id"` |
| 17 | UserID string `json:"user_id"` |
| 18 | IsBot bool `json:"is_bot"` |
| 19 | IsEnterpriseInstall bool `json:"is_enterprise_install"` |
| 20 | } |
| 21 | |
| 22 | func (api *Client) ListEventAuthorizations(eventContext string) ([]EventAuthorization, error) { |
| 23 | return api.ListEventAuthorizationsContext(context.Background(), eventContext) |
| 24 | } |
| 25 | |
| 26 | // ListEventAuthorizationsContext lists authed users and teams for the given event_context. You must provide an app-level token to the client using OptionAppLevelToken. More info: https://api.slack.com/methods/apps.event.authorizations.list |
| 27 | func (api *Client) ListEventAuthorizationsContext(ctx context.Context, eventContext string) ([]EventAuthorization, error) { |
| 28 | resp := &listEventAuthorizationsResponse{} |
| 29 | |
| 30 | request, _ := json.Marshal(map[string]string{ |
| 31 | "event_context": eventContext, |
| 32 | }) |
| 33 | |
| 34 | err := postJSON(ctx, api.httpclient, api.endpoint+"apps.event.authorizations.list", api.appLevelToken, request, &resp, api) |
| 35 | |
| 36 | if err != nil { |
| 37 | return nil, err |
| 38 | } |
| 39 | if !resp.Ok { |
| 40 | return nil, resp.Err() |
| 41 | } |
| 42 | |
| 43 | return resp.Authorizations, nil |
| 44 | } |
| 45 | |
| 46 | func (api *Client) UninstallApp(clientID, clientSecret string) error { |
| 47 | return api.UninstallAppContext(context.Background(), clientID, clientSecret) |
| 48 | } |
| 49 | |
| 50 | func (api *Client) UninstallAppContext(ctx context.Context, clientID, clientSecret string) error { |
| 51 | values := url.Values{ |
| 52 | "client_id": {clientID}, |
| 53 | "client_secret": {clientSecret}, |
| 54 | } |
| 55 | |
| 56 | response := SlackResponse{} |
| 57 | |
| 58 | err := api.getMethod(ctx, "apps.uninstall", api.token, values, &response) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | |
| 63 | return response.Err() |
| 64 | } |