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