diff --git a/packages/web-api/src/methods.ts b/packages/web-api/src/methods.ts index ab45936c0..2c86ccd5b 100644 --- a/packages/web-api/src/methods.ts +++ b/packages/web-api/src/methods.ts @@ -273,6 +273,7 @@ import type { AdminBarriersCreateArguments, AdminBarriersDeleteArguments, AdminB import type { AdminConversationsArchiveArguments, AdminConversationsBulkArchiveArguments, AdminConversationsBulkDeleteArguments, AdminConversationsBulkMoveArguments, AdminConversationsConvertToPrivateArguments, AdminConversationsConvertToPublicArguments, AdminConversationsCreateArguments, AdminConversationsDeleteArguments, AdminConversationsDisconnectSharedArguments, AdminConversationsEKMListOriginalConnectedChannelInfoArguments, AdminConversationsGetConversationPrefsArguments, AdminConversationsGetCustomRetentionArguments, AdminConversationsGetTeamsArguments, AdminConversationsInviteArguments, AdminConversationsLookupArguments, AdminConversationsRemoveCustomRetentionArguments, AdminConversationsRenameArguments, AdminConversationsRestrictAccessAddGroupArguments, AdminConversationsRestrictAccessListGroupsArguments, AdminConversationsRestrictAccessRemoveGroupArguments, AdminConversationsSearchArguments, AdminConversationsSetConversationPrefsArguments, AdminConversationsSetCustomRetentionArguments, AdminConversationsSetTeamsArguments, AdminConversationsUnarchiveArguments } from './types/request/admin/conversations'; import type { AdminEmojiAddArguments, AdminEmojiAddAliasArguments, AdminEmojiListArguments, AdminEmojiRemoveArguments, AdminEmojiRenameArguments } from './types/request/admin/emoji'; import type { AdminFunctionsListArguments, AdminFunctionsPermissionsLookupArguments, AdminFunctionsPermissionsSetArguments } from './types/request/admin/functions'; +import type { FunctionsCompleteErrorArguments, FunctionsCompleteSuccessArguments } from './types/request/functions'; /** * Generic method definition @@ -1311,7 +1312,15 @@ export abstract class Methods extends EventEmitter { }; public readonly functions = { + /** + * @description Signal the failure to execute a Custom Function. + * @see {@link https://api.slack.com/methods/functions.completeError `functions.completeError` API reference}. + */ completeError: bindApiCall(this, 'functions.completeError'), + /** + * @description Signal the successful completion of a Custom Function. + * @see {@link https://api.slack.com/methods/functions.completeSuccess `functions.completeSuccess` API reference}. + */ completeSuccess: bindApiCall( this, 'functions.completeSuccess', @@ -1957,17 +1966,4 @@ export interface AdminWorkflowsUnpublishArguments extends TokenOverridable { workflow_ids: string[]; } -/* - * `functions.*` - */ -export interface FunctionsCompleteErrorArguments extends TokenOverridable { - function_execution_id: string; - error: string; -} - -export interface FunctionsCompleteSuccessArguments extends TokenOverridable { - function_execution_id: string; - outputs: Record; -} - export * from '@slack/types'; diff --git a/packages/web-api/src/types/request/files.ts b/packages/web-api/src/types/request/files.ts index ccaa26049..32c5b9009 100644 --- a/packages/web-api/src/types/request/files.ts +++ b/packages/web-api/src/types/request/files.ts @@ -1,5 +1,5 @@ import type { Stream } from 'node:stream'; -import { CursorPaginationEnabled, OptionalTeamAssignable, TokenOverridable, TraditionalPagingEnabled } from './common'; +import type { CursorPaginationEnabled, OptionalTeamAssignable, TokenOverridable, TraditionalPagingEnabled } from './common'; import type { FilesGetUploadURLExternalResponse } from '../response'; interface FileArgument { diff --git a/packages/web-api/src/types/request/functions.ts b/packages/web-api/src/types/request/functions.ts new file mode 100644 index 000000000..b00aaf1bd --- /dev/null +++ b/packages/web-api/src/types/request/functions.ts @@ -0,0 +1,15 @@ +import type { TokenOverridable } from './common'; + +interface ExecutionID { + function_execution_id: string; +} + +// https://api.slack.com/methods/functions.completeError +export interface FunctionsCompleteErrorArguments extends ExecutionID, TokenOverridable { + error: string; +} + +// https://api.slack.com/methods/functions.completeSuccess +export interface FunctionsCompleteSuccessArguments extends ExecutionID, TokenOverridable { + outputs: Record; +} diff --git a/packages/web-api/test/types/methods/functions.test-d.ts b/packages/web-api/test/types/methods/functions.test-d.ts new file mode 100644 index 000000000..20e8814bf --- /dev/null +++ b/packages/web-api/test/types/methods/functions.test-d.ts @@ -0,0 +1,36 @@ +import { expectAssignable, expectError } from 'tsd'; +import { WebClient } from '../../../src/WebClient'; + +const web = new WebClient('TOKEN'); + +// functions.completeError +// -- sad path +expectError(web.functions.completeError()); // lacking argument +expectError(web.functions.completeError({})); // empty argument +expectError(web.functions.completeError({ + function_execution_id: 'Fx1234', // missing error +})); +expectError(web.functions.completeError({ + error: 'boomsies', // missing function_execution_id +})); +// -- happy path +expectAssignable>([{ + function_execution_id: 'Fx1234', + error: 'oh noes', +}]); + +// functions.completeSuccess +// -- sad path +expectError(web.functions.completeSuccess()); // lacking argument +expectError(web.functions.completeSuccess({})); // empty argument +expectError(web.functions.completeSuccess({ + function_execution_id: 'Fx1234', // missing output +})); +expectError(web.functions.completeSuccess({ + outputs: {}, // missing function_execution_id +})); +// -- happy path +expectAssignable>([{ + function_execution_id: 'Fx1234', + outputs: {}, +}]);