diff --git a/canvas.go b/canvas.go new file mode 100644 index 000000000..7e57f3f39 --- /dev/null +++ b/canvas.go @@ -0,0 +1,35 @@ +package slack + +import ( + "context" + "encoding/json" +) + +type CreateChannelCanvasParams struct { + ChannelID string `json:"channel_id"` + DocumentContent *DocumentContent `json:"document_content"` +} + +type DocumentContent struct { + Type string `json:"type"` + Markdown string `json:"markdown"` +} + +func (api *Client) CreateChannelCanvasContext(ctx context.Context, params CreateChannelCanvasParams) (*string, error) { + encoded, err := json.Marshal(params) + if err != nil { + return nil, err + } + + resp := &struct { + SlackResponse + CanvasID *string `json:"canvas_id"` + }{} + + endpoint := api.endpoint + "conversations.canvases.create" + err = postJSON(ctx, api.httpclient, endpoint, api.token, encoded, resp, api) + if err != nil { + return nil, err + } + return resp.CanvasID, resp.Err() +} diff --git a/organization.go b/organization.go new file mode 100644 index 000000000..37ef5a506 --- /dev/null +++ b/organization.go @@ -0,0 +1,31 @@ +package slack + +type Organization struct { + TeamID string `json:"team_id"` + TeamName string `json:"team_name"` + TeamDomain string `json:"team_domain"` + PublicChannelCount int `json:"public_channel_count"` + PrivateChannelCount int `json:"private_channel_count"` + IMChannelCount int `json:"im_channel_count"` + MPIMChannelCount int `json:"mpim_channel_count"` + ConnectedWorkspaces struct { + WorkspaceID string `json:"workspace_id"` + WorkspaceName string `json:"workspace_name"` + } `json:"connected_workspaces"` + // SlackConnectPrefs struct{} `json:"slack_connect_prefs"` + ConnectionStatus string `json:"connection_status"` + LastActiveTimestamp int `json:"last_active_timestamp"` + IsSponsored bool `json:"is_sponsored"` + Canvas struct { + TotalCount int `json:"total_count"` + OwnershipDetails []struct { + TeamID string `json:"team_id"` + } `json:"ownership_details"` + } `json:"canvas"` + Lists struct { + TotalCount int `json:"total_count"` + OwnershipDetails []struct { + TeamID string `json:"team_id"` + } `json:"ownership_details"` + } `json:"lists"` +} diff --git a/team.go b/team.go index d21a1b642..02023defa 100644 --- a/team.go +++ b/team.go @@ -124,6 +124,64 @@ func (api *Client) teamProfileRequest(ctx context.Context, client httpClient, pa return response, response.Err() } +func (api *Client) GetExternalTeams(params *GetExternalTeamsParameters) (organizations []*Organization, nextCursor string, err error) { + return api.GetExternalTeamsContext(context.Background(), params) +} + +type GetExternalTeamsParameters struct { + ConnectionStatusFilter string + Cursor string + Limit int + SlackConnectPrefFilter []string + SortDirection string + SortField string + WorkspaceFilter []string +} + +func (api *Client) GetExternalTeamsContext(ctx context.Context, params *GetExternalTeamsParameters) (organizations []*Organization, nextCursor string, err error) { + values := url.Values{ + "token": {api.token}, + } + + if params != nil { + if params.ConnectionStatusFilter != "" { + values.Add("connection_status_filter", params.ConnectionStatusFilter) + } + if params.Cursor != "" { + values.Add("cursor", params.Cursor) + } + if params.Limit != 0 { + values.Add("limit", strconv.Itoa(params.Limit)) + } + if len(params.SlackConnectPrefFilter) > 0 { + values.Add("slack_connect_pref_filter", params.SlackConnectPrefFilter[0]) + } + if params.SortDirection != "" { + values.Add("sort_direction", params.SortDirection) + } + if params.SortField != "" { + values.Add("sort_field", params.SortField) + } + if len(params.WorkspaceFilter) > 0 { + values.Add("workspace_filter", params.WorkspaceFilter[0]) + } + } + + response := struct { + Organizations []*Organization `json:"organizations"` + ResponseMetaData responseMetaData `json:"response_metadata"` + SlackResponse + }{} + + err = api.postMethod(ctx, "team.externalTeams.list", values, response) + if err != nil { + return nil, "", err + } + + return response.Organizations, response.ResponseMetadata.Cursor, response.Err() + +} + // GetTeamInfo gets the Team Information of the user func (api *Client) GetTeamInfo() (*TeamInfo, error) { return api.GetTeamInfoContext(context.Background())