Bumps the go-modules-updates group in /backend with 5 updates: | Package | From | To | | --- | --- | --- | | [github.com/PuerkitoBio/goquery](https://github.com/PuerkitoBio/goquery) | `1.10.0` | `1.10.1` | | [github.com/go-chi/chi/v5](https://github.com/go-chi/chi) | `5.1.0` | `5.2.0` | | [github.com/go-pkgz/rest](https://github.com/go-pkgz/rest) | `1.19.0` | `1.20.2` | | [golang.org/x/image](https://github.com/golang/image) | `0.22.0` | `0.23.0` | | [golang.org/x/net](https://github.com/golang/net) | `0.31.0` | `0.33.0` | Updates `github.com/PuerkitoBio/goquery` from 1.10.0 to 1.10.1 - [Release notes](https://github.com/PuerkitoBio/goquery/releases) - [Commits](https://github.com/PuerkitoBio/goquery/compare/v1.10.0...v1.10.1) Updates `github.com/go-chi/chi/v5` from 5.1.0 to 5.2.0 - [Release notes](https://github.com/go-chi/chi/releases) - [Changelog](https://github.com/go-chi/chi/blob/master/CHANGELOG.md) - [Commits](https://github.com/go-chi/chi/compare/v5.1.0...v5.2.0) Updates `github.com/go-pkgz/rest` from 1.19.0 to 1.20.2 - [Release notes](https://github.com/go-pkgz/rest/releases) - [Commits](https://github.com/go-pkgz/rest/compare/v1.19.0...v1.20.2) Updates `golang.org/x/image` from 0.22.0 to 0.23.0 - [Commits](https://github.com/golang/image/compare/v0.22.0...v0.23.0) Updates `golang.org/x/net` from 0.31.0 to 0.33.0 - [Commits](https://github.com/golang/net/compare/v0.31.0...v0.33.0) --- updated-dependencies: - dependency-name: github.com/PuerkitoBio/goquery dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules-updates - dependency-name: github.com/go-chi/chi/v5 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: github.com/go-pkgz/rest dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: golang.org/x/image dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: golang.org/x/net dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates ... Signed-off-by: dependabot[bot] <support@github.com>
265 lines
7.3 KiB
Go
265 lines
7.3 KiB
Go
package slack
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/url"
|
|
)
|
|
|
|
type CanvasDetails struct {
|
|
CanvasID string `json:"canvas_id"`
|
|
}
|
|
|
|
type DocumentContent struct {
|
|
Type string `json:"type"`
|
|
Markdown string `json:"markdown,omitempty"`
|
|
}
|
|
|
|
type CanvasChange struct {
|
|
Operation string `json:"operation"`
|
|
SectionID string `json:"section_id,omitempty"`
|
|
DocumentContent DocumentContent `json:"document_content"`
|
|
}
|
|
|
|
type EditCanvasParams struct {
|
|
CanvasID string `json:"canvas_id"`
|
|
Changes []CanvasChange `json:"changes"`
|
|
}
|
|
|
|
type SetCanvasAccessParams struct {
|
|
CanvasID string `json:"canvas_id"`
|
|
AccessLevel string `json:"access_level"`
|
|
ChannelIDs []string `json:"channel_ids,omitempty"`
|
|
UserIDs []string `json:"user_ids,omitempty"`
|
|
}
|
|
|
|
type DeleteCanvasAccessParams struct {
|
|
CanvasID string `json:"canvas_id"`
|
|
ChannelIDs []string `json:"channel_ids,omitempty"`
|
|
UserIDs []string `json:"user_ids,omitempty"`
|
|
}
|
|
|
|
type LookupCanvasSectionsCriteria struct {
|
|
SectionTypes []string `json:"section_types,omitempty"`
|
|
ContainsText string `json:"contains_text,omitempty"`
|
|
}
|
|
|
|
type LookupCanvasSectionsParams struct {
|
|
CanvasID string `json:"canvas_id"`
|
|
Criteria LookupCanvasSectionsCriteria `json:"criteria"`
|
|
}
|
|
|
|
type CanvasSection struct {
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
type LookupCanvasSectionsResponse struct {
|
|
SlackResponse
|
|
Sections []CanvasSection `json:"sections"`
|
|
}
|
|
|
|
// CreateCanvas creates a new canvas.
|
|
// For more details, see CreateCanvasContext documentation.
|
|
func (api *Client) CreateCanvas(title string, documentContent DocumentContent) (string, error) {
|
|
return api.CreateCanvasContext(context.Background(), title, documentContent)
|
|
}
|
|
|
|
// CreateCanvasContext creates a new canvas with a custom context.
|
|
// Slack API docs: https://api.slack.com/methods/canvases.create
|
|
func (api *Client) CreateCanvasContext(ctx context.Context, title string, documentContent DocumentContent) (string, error) {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
}
|
|
if title != "" {
|
|
values.Add("title", title)
|
|
}
|
|
if documentContent.Type != "" {
|
|
documentContentJSON, err := json.Marshal(documentContent)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
values.Add("document_content", string(documentContentJSON))
|
|
}
|
|
|
|
response := struct {
|
|
SlackResponse
|
|
CanvasID string `json:"canvas_id"`
|
|
}{}
|
|
|
|
err := api.postMethod(ctx, "canvases.create", values, &response)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return response.CanvasID, response.Err()
|
|
}
|
|
|
|
// DeleteCanvas deletes an existing canvas.
|
|
// For more details, see DeleteCanvasContext documentation.
|
|
func (api *Client) DeleteCanvas(canvasID string) error {
|
|
return api.DeleteCanvasContext(context.Background(), canvasID)
|
|
}
|
|
|
|
// DeleteCanvasContext deletes an existing canvas with a custom context.
|
|
// Slack API docs: https://api.slack.com/methods/canvases.delete
|
|
func (api *Client) DeleteCanvasContext(ctx context.Context, canvasID string) error {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
"canvas_id": {canvasID},
|
|
}
|
|
|
|
response := struct {
|
|
SlackResponse
|
|
}{}
|
|
|
|
err := api.postMethod(ctx, "canvases.delete", values, &response)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Err()
|
|
}
|
|
|
|
// EditCanvas edits an existing canvas.
|
|
// For more details, see EditCanvasContext documentation.
|
|
func (api *Client) EditCanvas(params EditCanvasParams) error {
|
|
return api.EditCanvasContext(context.Background(), params)
|
|
}
|
|
|
|
// EditCanvasContext edits an existing canvas with a custom context.
|
|
// Slack API docs: https://api.slack.com/methods/canvases.edit
|
|
func (api *Client) EditCanvasContext(ctx context.Context, params EditCanvasParams) error {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
"canvas_id": {params.CanvasID},
|
|
}
|
|
|
|
changesJSON, err := json.Marshal(params.Changes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
values.Add("changes", string(changesJSON))
|
|
|
|
response := struct {
|
|
SlackResponse
|
|
}{}
|
|
|
|
err = api.postMethod(ctx, "canvases.edit", values, &response)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Err()
|
|
}
|
|
|
|
// SetCanvasAccess sets the access level to a canvas for specified entities.
|
|
// For more details, see SetCanvasAccessContext documentation.
|
|
func (api *Client) SetCanvasAccess(params SetCanvasAccessParams) error {
|
|
return api.SetCanvasAccessContext(context.Background(), params)
|
|
}
|
|
|
|
// SetCanvasAccessContext sets the access level to a canvas for specified entities with a custom context.
|
|
// Slack API docs: https://api.slack.com/methods/canvases.access.set
|
|
func (api *Client) SetCanvasAccessContext(ctx context.Context, params SetCanvasAccessParams) error {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
"canvas_id": {params.CanvasID},
|
|
"access_level": {params.AccessLevel},
|
|
}
|
|
if len(params.ChannelIDs) > 0 {
|
|
channelIDsJSON, err := json.Marshal(params.ChannelIDs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
values.Add("channel_ids", string(channelIDsJSON))
|
|
}
|
|
if len(params.UserIDs) > 0 {
|
|
userIDsJSON, err := json.Marshal(params.UserIDs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
values.Add("user_ids", string(userIDsJSON))
|
|
}
|
|
|
|
response := struct {
|
|
SlackResponse
|
|
}{}
|
|
|
|
err := api.postMethod(ctx, "canvases.access.set", values, &response)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Err()
|
|
}
|
|
|
|
// DeleteCanvasAccess removes access to a canvas for specified entities.
|
|
// For more details, see DeleteCanvasAccessContext documentation.
|
|
func (api *Client) DeleteCanvasAccess(params DeleteCanvasAccessParams) error {
|
|
return api.DeleteCanvasAccessContext(context.Background(), params)
|
|
}
|
|
|
|
// DeleteCanvasAccessContext removes access to a canvas for specified entities with a custom context.
|
|
// Slack API docs: https://api.slack.com/methods/canvases.access.delete
|
|
func (api *Client) DeleteCanvasAccessContext(ctx context.Context, params DeleteCanvasAccessParams) error {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
"canvas_id": {params.CanvasID},
|
|
}
|
|
if len(params.ChannelIDs) > 0 {
|
|
channelIDsJSON, err := json.Marshal(params.ChannelIDs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
values.Add("channel_ids", string(channelIDsJSON))
|
|
}
|
|
if len(params.UserIDs) > 0 {
|
|
userIDsJSON, err := json.Marshal(params.UserIDs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
values.Add("user_ids", string(userIDsJSON))
|
|
}
|
|
|
|
response := struct {
|
|
SlackResponse
|
|
}{}
|
|
|
|
err := api.postMethod(ctx, "canvases.access.delete", values, &response)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Err()
|
|
}
|
|
|
|
// LookupCanvasSections finds sections matching the provided criteria.
|
|
// For more details, see LookupCanvasSectionsContext documentation.
|
|
func (api *Client) LookupCanvasSections(params LookupCanvasSectionsParams) ([]CanvasSection, error) {
|
|
return api.LookupCanvasSectionsContext(context.Background(), params)
|
|
}
|
|
|
|
// LookupCanvasSectionsContext finds sections matching the provided criteria with a custom context.
|
|
// Slack API docs: https://api.slack.com/methods/canvases.sections.lookup
|
|
func (api *Client) LookupCanvasSectionsContext(ctx context.Context, params LookupCanvasSectionsParams) ([]CanvasSection, error) {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
"canvas_id": {params.CanvasID},
|
|
}
|
|
|
|
criteriaJSON, err := json.Marshal(params.Criteria)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
values.Add("criteria", string(criteriaJSON))
|
|
|
|
response := LookupCanvasSectionsResponse{}
|
|
|
|
err = api.postMethod(ctx, "canvases.sections.lookup", values, &response)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return response.Sections, response.Err()
|
|
}
|