5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-22 21:50:28 +00:00
matterbridge/vendor/github.com/slack-go/slack/apps.go

65 lines
1.9 KiB
Go
Raw Normal View History

2020-10-19 21:40:00 +00:00
package slack
import (
"context"
"encoding/json"
2021-02-01 20:29:04 +00:00
"net/url"
2020-10-19 21:40:00 +00:00
)
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"`
}
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. You must provide an app-level token to the client using OptionAppLevelToken. More info: 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
}
2021-02-01 20:29:04 +00:00
func (api *Client) UninstallApp(clientID, clientSecret string) error {
2022-04-25 21:50:10 +00:00
return api.UninstallAppContext(context.Background(), clientID, clientSecret)
}
func (api *Client) UninstallAppContext(ctx context.Context, clientID, clientSecret string) error {
2021-02-01 20:29:04 +00:00
values := url.Values{
"client_id": {clientID},
"client_secret": {clientSecret},
}
response := SlackResponse{}
2022-04-25 21:50:10 +00:00
err := api.getMethod(ctx, "apps.uninstall", api.token, values, &response)
2021-02-01 20:29:04 +00:00
if err != nil {
return err
}
return response.Err()
}