Skip to content

Commit

Permalink
web-api: public canvas APIs (#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
filmaj authored Jun 12, 2024
1 parent 9f2935f commit a2c0fe5
Show file tree
Hide file tree
Showing 13 changed files with 479 additions and 1 deletion.
58 changes: 58 additions & 0 deletions packages/web-api/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ import type {
CallsUpdateResponse,
CallsParticipantsAddResponse,
CallsParticipantsRemoveResponse,
CanvasesAccessDeleteResponse,
CanvasesAccessSetResponse,
CanvasesCreateResponse,
CanvasesDeleteResponse,
CanvasesEditResponse,
CanvasesSectionsLookupResponse,
ChatDeleteResponse,
ChatDeleteScheduledMessageResponse,
ChatGetPermalinkResponse,
Expand All @@ -111,6 +117,7 @@ import type {
ChatUpdateResponse,
ConversationsAcceptSharedInviteResponse,
ConversationsApproveSharedInviteResponse,
ConversationsCanvasesCreateResponse,
ConversationsDeclineSharedInviteResponse,
ConversationsInviteSharedResponse,
ConversationsListConnectInvitesResponse,
Expand Down Expand Up @@ -325,6 +332,7 @@ import type {
ConversationsAcceptSharedInviteArguments,
ConversationsApproveSharedInviteArguments,
ConversationsArchiveArguments,
ConversationsCanvasesCreateArguments,
ConversationsCloseArguments,
ConversationsCreateArguments,
ConversationsDeclineSharedInviteArguments,
Expand Down Expand Up @@ -355,6 +363,12 @@ import type {
ChatScheduledMessagesListArguments,
ChatUnfurlArguments,
ChatUpdateArguments,
CanvasesAccessDeleteArguments,
CanvasesAccessSetArguments,
CanvasesCreateArguments,
CanvasesDeleteArguments,
CanvasesEditArguments,
CanvasesSectionsLookupArguments,
CallsAddArguments,
CallsEndArguments,
CallsInfoArguments,
Expand Down Expand Up @@ -1337,6 +1351,43 @@ export abstract class Methods extends EventEmitter<WebClientEvent> {
},
};

public readonly canvases = {
access: {
/**
* @description Remove access to a canvas for specified entities.
* @see {@link https://api.slack.com/methods/canvases.access.delete `canvases.access.delete` API reference}.
*/
delete: bindApiCall<CanvasesAccessDeleteArguments, CanvasesAccessDeleteResponse>(this, 'canvases.access.delete'),
/**
* @description Sets the access level to a canvas for specified entities.
* @see {@link https://api.slack.com/methods/canvases.access.set `canvases.access.set` API reference}.
*/
set: bindApiCall<CanvasesAccessSetArguments, CanvasesAccessSetResponse>(this, 'canvases.access.set'),
},
/**
* @description Create Canvas for a user.
* @see {@link https://api.slack.com/methods/canvases.create `canvases.create` API reference}.
*/
create: bindApiCall<CanvasesCreateArguments, CanvasesCreateResponse>(this, 'canvases.create'),
/**
* @description Deletes a canvas.
* @see {@link https://api.slack.com/methods/canvases.delete `canvases.delete` API reference}.
*/
delete: bindApiCall<CanvasesDeleteArguments, CanvasesDeleteResponse>(this, 'canvases.delete'),
/**
* @description Update an existing canvas.
* @see {@link https://api.slack.com/methods/canvases.edit `canvases.edit` API reference}.
*/
edit: bindApiCall<CanvasesEditArguments, CanvasesEditResponse>(this, 'canvases.edit'),
sections: {
/**
* @description Find sections matching the provided criteria.
* @see {@link https://api.slack.com/methods/canvases.sections.lookup `canvases.sections.lookup` API reference}.
*/
lookup: bindApiCall<CanvasesSectionsLookupArguments, CanvasesSectionsLookupResponse>(this, 'canvases.sections.lookup'),
},
};

public readonly chat = {
/**
* @description Deletes a message.
Expand Down Expand Up @@ -1423,6 +1474,13 @@ export abstract class Methods extends EventEmitter<WebClientEvent> {
* @see {@link https://api.slack.com/methods/conversations.archive `conversations.archive` API reference}.
*/
archive: bindApiCall<ConversationsArchiveArguments, ConversationsArchiveResponse>(this, 'conversations.archive'),
canvases: {
/**
* @description Create a Channel Canvas for a channel.
* @see {@link https://api.slack.com/methods/conversations.canvases.create `conversations.canvases.create` API reference}.
*/
create: bindApiCall<ConversationsCanvasesCreateArguments, ConversationsCanvasesCreateResponse>(this, 'conversations.canvases.create'),
},
/**
* @description Closes a direct message or multi-person direct message.
* @see {@link https://api.slack.com/methods/conversations.close `conversations.close` API reference}.
Expand Down
2 changes: 1 addition & 1 deletion packages/web-api/src/types/request/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CursorPaginationEnabled, TokenOverridable } from './common';
import { OptionalArgument } from '../helpers';
import type { OptionalArgument } from '../helpers';

// https://api.slack.com/methods/auth.revoke
export type AuthRevokeArguments = OptionalArgument<TokenOverridable & {
Expand Down
91 changes: 91 additions & 0 deletions packages/web-api/src/types/request/canvas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import type { ChannelIDs, TokenOverridable, UserIDs } from './common';
import type { OptionalArgument } from '../helpers';

interface CanvasID {
/** @description Encoded ID of the canvas. */
canvas_id: string;
}
interface DocumentContent {
/** @description The type of content used to describe Canvas content. Always is `markdown`. */
type: 'markdown';
/** @description The markdown defining the Canvas content. */
markdown: string;
}
type SectionType = 'any_header' | 'h1' | 'h2' | 'h3';
interface SectionTypes {
/** @description List of desired section types to filter on. Minimum of 1, maximum of 3. */
section_types: [SectionType, ...SectionType[]];
}
interface ContainsText {
/** @description Textual content that must appear in the section. */
contains_text: string;
}
// At least one of `section_types` or `contains_text` must be defined.
type Criteria = (SectionTypes & Partial<ContainsText>) | (Partial<SectionTypes> & ContainsText);
type Operation = 'insert_after' | 'insert_before' | 'insert_at_start' | 'insert_at_end' | 'replace' | 'delete';
interface BaseChange {
/** @description The operation to perform on the canvas. */
operation?: Operation;
/** @description The section of the canvas to target the operation on. */
section_id?: string;
/** @description Structure describing the type and contents. */
document_content?: DocumentContent;
}
type ChangeWithSectionAndContent = Required<BaseChange> & {
/** @description The operation to perform on the canvas. */
operation: 'insert_after' | 'insert_before'
};
type ChangeWithContent = Required<Pick<BaseChange, 'document_content'>> & {
/** @description The operation to perform on the canvas. */
operation: 'insert_at_start' | 'insert_at_end';
};
type ChangeWithContentAndOptionalSection = BaseChange & Required<Pick<BaseChange, 'document_content'>> & {
/** @description The operation to perform on the canvas. */
operation: 'replace';
};
type ChangeWithSection = Required<Pick<BaseChange, 'section_id'>> & {
/** @description The operation to perform on the canvas. */
operation: 'delete';
};
type Change = ChangeWithSection | ChangeWithContent | ChangeWithSectionAndContent | ChangeWithContentAndOptionalSection;

// https://api.slack.com/methods/canvases.access.delete
export interface CanvasesAccessDeleteArguments extends CanvasID, Partial<ChannelIDs>, TokenOverridable,
Partial<UserIDs> {}

// https://api.slack.com/methods/canvases.access.set
export interface CanvasesAccessSetArguments extends CanvasID, Partial<ChannelIDs>, TokenOverridable, Partial<UserIDs> {
/** @description Desired level of access. */
access_level: 'read' | 'write';
}

// https://api.slack.com/methods/canvases.create
export type CanvasesCreateArguments = OptionalArgument<TokenOverridable & {
/** @description Title of the newly created canvas. */
title?: string;
/** @description Structure describing the type and contents of the Canvas being created. */
document_content?: DocumentContent;
}>;

// https://api.slack.com/methods/canvases.sections.lookup
export interface CanvasesSectionsLookupArguments extends CanvasID, TokenOverridable {
/** @description Filtering criteria. */
criteria: Criteria;
}

// https://api.slack.com/methods/canvases.delete
export interface CanvasesDeleteArguments extends CanvasID, TokenOverridable {}

// https://api.slack.com/methods/canvases.edit
export interface CanvasesEditArguments extends CanvasID, TokenOverridable {
/** @description List of changes to apply to the canvas. */
changes: [Change, ...Change[]];
}

// https://api.slack.com/methods/conversations.canvases.create
export interface ConversationsCanvasesCreateArguments extends TokenOverridable {
/** @description Channel ID of the channel to create a canvas in. */
channel_id: string;
/** @description Structure describing the type and contents of the Canvas being created. */
document_content?: DocumentContent;
}
1 change: 1 addition & 0 deletions packages/web-api/src/types/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type { DndEndDndArguments, DndEndSnoozeArguments, DndInfoArguments, DndSe
export type { DialogOpenArguments } from './dialog';
export type { ConversationsAcceptSharedInviteArguments, ConversationsApproveSharedInviteArguments, ConversationsArchiveArguments, ConversationsCloseArguments, ConversationsCreateArguments, ConversationsDeclineSharedInviteArguments, ConversationsHistoryArguments, ConversationsInfoArguments, ConversationsInviteArguments, ConversationsInviteSharedArguments, ConversationsJoinArguments, ConversationsKickArguments, ConversationsLeaveArguments, ConversationsListArguments, ConversationsListConnectInvitesArguments, ConversationsMarkArguments, ConversationsMembersArguments, ConversationsOpenArguments, ConversationsRenameArguments, ConversationsRepliesArguments, ConversationsSetPurposeArguments, ConversationsSetTopicArguments, ConversationsUnarchiveArguments } from './conversations';
export type { ChatDeleteArguments, ChatDeleteScheduledMessageArguments, ChatGetPermalinkArguments, ChatMeMessageArguments, ChatPostEphemeralArguments, ChatPostMessageArguments, ChatScheduleMessageArguments, ChatScheduledMessagesListArguments, ChatUnfurlArguments, ChatUpdateArguments } from './chat';
export type { CanvasesAccessDeleteArguments, CanvasesAccessSetArguments, CanvasesCreateArguments, CanvasesDeleteArguments, CanvasesEditArguments, CanvasesSectionsLookupArguments, ConversationsCanvasesCreateArguments } from './canvas';
export type { CallsAddArguments, CallsEndArguments, CallsInfoArguments, CallsUpdateArguments, CallsParticipantsAddArguments, CallsParticipantsRemoveArguments } from './calls';
export type { BotsInfoArguments } from './bots';
export type { BookmarksAddArguments, BookmarksEditArguments, BookmarksListArguments, BookmarksRemoveArguments } from './bookmarks';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable */
/////////////////////////////////////////////////////////////////////////////////////////
// //
// !!! DO NOT EDIT THIS FILE !!! //
// //
// This file is auto-generated by scripts/generate-web-api-types.sh in the repository. //
// Please refer to the script code to learn how to update the source data. //
// //
/////////////////////////////////////////////////////////////////////////////////////////

import { WebAPICallResult } from '../../WebClient';
export type CanvasesAccessDeleteResponse = WebAPICallResult & {
error?: string;
failed_to_update_channel_ids?: string[];
failed_to_update_user_ids?: string[];
ok?: boolean;
response_metadata?: ResponseMetadata;
};

export interface ResponseMetadata {
}
21 changes: 21 additions & 0 deletions packages/web-api/src/types/response/CanvasesAccessSetResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable */
/////////////////////////////////////////////////////////////////////////////////////////
// //
// !!! DO NOT EDIT THIS FILE !!! //
// //
// This file is auto-generated by scripts/generate-web-api-types.sh in the repository. //
// Please refer to the script code to learn how to update the source data. //
// //
/////////////////////////////////////////////////////////////////////////////////////////

import { WebAPICallResult } from '../../WebClient';
export type CanvasesAccessSetResponse = WebAPICallResult & {
error?: string;
failed_to_update_channel_ids?: string[];
failed_to_update_user_ids?: string[];
ok?: boolean;
response_metadata?: ResponseMetadata;
};

export interface ResponseMetadata {
}
22 changes: 22 additions & 0 deletions packages/web-api/src/types/response/CanvasesCreateResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
/////////////////////////////////////////////////////////////////////////////////////////
// //
// !!! DO NOT EDIT THIS FILE !!! //
// //
// This file is auto-generated by scripts/generate-web-api-types.sh in the repository. //
// Please refer to the script code to learn how to update the source data. //
// //
/////////////////////////////////////////////////////////////////////////////////////////

import { WebAPICallResult } from '../../WebClient';
export type CanvasesCreateResponse = WebAPICallResult & {
canvas_id?: string;
detail?: string;
error?: string;
ok?: boolean;
response_metadata?: ResponseMetadata;
};

export interface ResponseMetadata {
messages?: string[];
}
19 changes: 19 additions & 0 deletions packages/web-api/src/types/response/CanvasesDeleteResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable */
/////////////////////////////////////////////////////////////////////////////////////////
// //
// !!! DO NOT EDIT THIS FILE !!! //
// //
// This file is auto-generated by scripts/generate-web-api-types.sh in the repository. //
// Please refer to the script code to learn how to update the source data. //
// //
/////////////////////////////////////////////////////////////////////////////////////////

import { WebAPICallResult } from '../../WebClient';
export type CanvasesDeleteResponse = WebAPICallResult & {
error?: string;
ok?: boolean;
response_metadata?: ResponseMetadata;
};

export interface ResponseMetadata {
}
20 changes: 20 additions & 0 deletions packages/web-api/src/types/response/CanvasesEditResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable */
/////////////////////////////////////////////////////////////////////////////////////////
// //
// !!! DO NOT EDIT THIS FILE !!! //
// //
// This file is auto-generated by scripts/generate-web-api-types.sh in the repository. //
// Please refer to the script code to learn how to update the source data. //
// //
/////////////////////////////////////////////////////////////////////////////////////////

import { WebAPICallResult } from '../../WebClient';
export type CanvasesEditResponse = WebAPICallResult & {
detail?: string;
error?: string;
ok?: boolean;
response_metadata?: ResponseMetadata;
};

export interface ResponseMetadata {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable */
/////////////////////////////////////////////////////////////////////////////////////////
// //
// !!! DO NOT EDIT THIS FILE !!! //
// //
// This file is auto-generated by scripts/generate-web-api-types.sh in the repository. //
// Please refer to the script code to learn how to update the source data. //
// //
/////////////////////////////////////////////////////////////////////////////////////////

import { WebAPICallResult } from '../../WebClient';
export type CanvasesSectionsLookupResponse = WebAPICallResult & {
error?: string;
ok?: boolean;
response_metadata?: ResponseMetadata;
sections?: Section[];
};

export interface ResponseMetadata {
}

export interface Section {
id?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
/////////////////////////////////////////////////////////////////////////////////////////
// //
// !!! DO NOT EDIT THIS FILE !!! //
// //
// This file is auto-generated by scripts/generate-web-api-types.sh in the repository. //
// Please refer to the script code to learn how to update the source data. //
// //
/////////////////////////////////////////////////////////////////////////////////////////

import { WebAPICallResult } from '../../WebClient';
export type ConversationsCanvasesCreateResponse = WebAPICallResult & {
canvas_id?: string;
detail?: string;
error?: string;
ok?: boolean;
response_metadata?: ResponseMetadata;
};

export interface ResponseMetadata {
messages?: string[];
}
7 changes: 7 additions & 0 deletions packages/web-api/src/types/response/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ export { CallsInfoResponse } from './CallsInfoResponse';
export { CallsParticipantsAddResponse } from './CallsParticipantsAddResponse';
export { CallsParticipantsRemoveResponse } from './CallsParticipantsRemoveResponse';
export { CallsUpdateResponse } from './CallsUpdateResponse';
export { CanvasesAccessDeleteResponse } from './CanvasesAccessDeleteResponse';
export { CanvasesAccessSetResponse } from './CanvasesAccessSetResponse';
export { CanvasesCreateResponse } from './CanvasesCreateResponse';
export { CanvasesDeleteResponse } from './CanvasesDeleteResponse';
export { CanvasesEditResponse } from './CanvasesEditResponse';
export { CanvasesSectionsLookupResponse } from './CanvasesSectionsLookupResponse';
export { ChannelsArchiveResponse } from './ChannelsArchiveResponse';
export { ChannelsCreateResponse } from './ChannelsCreateResponse';
export { ChannelsHistoryResponse } from './ChannelsHistoryResponse';
Expand Down Expand Up @@ -153,6 +159,7 @@ export { ChatUpdateResponse } from './ChatUpdateResponse';
export { ConversationsAcceptSharedInviteResponse } from './ConversationsAcceptSharedInviteResponse';
export { ConversationsApproveSharedInviteResponse } from './ConversationsApproveSharedInviteResponse';
export { ConversationsArchiveResponse } from './ConversationsArchiveResponse';
export { ConversationsCanvasesCreateResponse } from './ConversationsCanvasesCreateResponse';
export { ConversationsCloseResponse } from './ConversationsCloseResponse';
export { ConversationsCreateResponse } from './ConversationsCreateResponse';
export { ConversationsDeclineSharedInviteResponse } from './ConversationsDeclineSharedInviteResponse';
Expand Down
Loading

0 comments on commit a2c0fe5

Please sign in to comment.