Skip to content

Commit

Permalink
web-api(feat): add support for conversations.requestShared `approve…
Browse files Browse the repository at this point in the history
…` , `deny` and `list` APIs (#1843)
  • Loading branch information
filmaj authored Sep 5, 2024
1 parent e930db3 commit a3a06ec
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 38 deletions.
22 changes: 22 additions & 0 deletions packages/web-api/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ import type {
ConversationsOpenArguments,
ConversationsRenameArguments,
ConversationsRepliesArguments,
ConversationsRequestSharedInviteApproveArguments,
ConversationsRequestSharedInviteDenyArguments,
ConversationsSetPurposeArguments,
ConversationsSetTopicArguments,
ConversationsUnarchiveArguments,
Expand Down Expand Up @@ -407,6 +409,8 @@ import type {
ConversationsOpenResponse,
ConversationsRenameResponse,
ConversationsRepliesResponse,
ConversationsRequestSharedInviteApproveResponse,
ConversationsRequestSharedInviteDenyResponse,
ConversationsSetPurposeResponse,
ConversationsSetTopicResponse,
ConversationsUnarchiveResponse,
Expand Down Expand Up @@ -1716,6 +1720,24 @@ export abstract class Methods extends EventEmitter<WebClientEvent> {
* @see {@link https://api.slack.com/methods/conversations.replies `conversations.replies` API reference}.
*/
replies: bindApiCall<ConversationsRepliesArguments, ConversationsRepliesResponse>(this, 'conversations.replies'),
requestSharedInvite: {
/**
* @description Approves a request to add an external user to a channel and sends them a Slack Connect invite.
* @see {@link https://api.slack.com/methods/conversations.requestSharedInvite.approve `conversations.requestSharedInvite.approve` API reference}.
*/
approve: bindApiCall<
ConversationsRequestSharedInviteApproveArguments,
ConversationsRequestSharedInviteApproveResponse
>(this, 'conversations.requestSharedInvite.approve'),
/**
* @description Denies a request to invite an external user to a channel.
* @see {@link https://api.slack.com/methods/conversations.requestSharedInvite.deny `conversations.requestSharedInvite.deny` API reference}.
*/
deny: bindApiCall<ConversationsRequestSharedInviteDenyArguments, ConversationsRequestSharedInviteDenyResponse>(
this,
'conversations.requestSharedInvite.deny',
),
},
/**
* @description Sets the purpose for a conversation.
* @see {@link https://api.slack.com/methods/conversations.setPurpose `conversations.setPurpose` API reference}.
Expand Down
2 changes: 1 addition & 1 deletion packages/web-api/src/retry-policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { OperationOptions } from 'retry';
/**
* Options to create retry policies. Extends from https://github.com/tim-kos/node-retry.
*/
export interface RetryOptions extends OperationOptions { }
export interface RetryOptions extends OperationOptions {}

/**
* The default retry policy. Retry up to 10 times, over the span of about 30 minutes. It's not exact because
Expand Down
7 changes: 1 addition & 6 deletions packages/web-api/src/types/request/admin/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,7 @@ export interface AdminConversationsDisconnectSharedArguments extends ChannelID,

// https://api.slack.com/methods/admin.conversations.ekm.listOriginalConnectedChannelInfo
export type AdminConversationsEKMListOriginalConnectedChannelInfoArguments = OptionalArgument<
Partial<TeamIDs> &
TokenOverridable &
CursorPaginationEnabled & {
/** @description A comma-separated list of channels to filter to. */
channel_ids?: string[];
}
Partial<TeamIDs> & TokenOverridable & CursorPaginationEnabled & Partial<ChannelIDs>
>;

// https://api.slack.com/methods/admin.conversations.getConversationPrefs
Expand Down
6 changes: 2 additions & 4 deletions packages/web-api/src/types/request/admin/functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CursorPaginationEnabled, TokenOverridable } from '../common';
import type { CursorPaginationEnabled, TokenOverridable, UserIDs } from '../common';

// https://api.slack.com/methods/admin.functions.list
export interface AdminFunctionsListArguments extends TokenOverridable, CursorPaginationEnabled {
Expand All @@ -15,11 +15,9 @@ export interface AdminFunctionsPermissionsLookupArguments extends TokenOverridab
}

// https://api.slack.com/methods/admin.functions.permissions.set
export interface AdminFunctionsPermissionsSetArguments extends TokenOverridable {
export interface AdminFunctionsPermissionsSetArguments extends TokenOverridable, Partial<UserIDs> {
/** @description The function ID to set permissions for. */
function_id: string;
/** @description The function visibility. */
visibility: 'everyone' | 'app_collaborators' | 'named_entities' | 'no_one';
/** @description List of user IDs to allow for `named_entities` visibility. */
user_ids?: string[];
}
6 changes: 1 addition & 5 deletions packages/web-api/src/types/request/admin/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ import type {
OptionalTeamAssignable,
TeamID,
TokenOverridable,
UserID,
UserIDs,
} from '../common';

interface UserID {
/** @description The ID of the user. */
user_id: string;
}

interface IsRestricted {
/** @description Set to `true` if user should be added to the workspace as a guest. */
is_restricted?: boolean;
Expand Down
14 changes: 5 additions & 9 deletions packages/web-api/src/types/request/bookmarks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { TokenOverridable } from './common';
import type { ChannelID, TokenOverridable } from './common';

interface Channel {
/** @description Channel containing bookmark. */
channel_id: string;
}
interface ID {
bookmark_id: string;
}
Expand All @@ -17,7 +13,7 @@ interface BookmarkFields {
}

// https://api.slack.com/methods/bookmarks.add
export interface BookmarksAddArguments extends Channel, BookmarkFields, TokenOverridable {
export interface BookmarksAddArguments extends ChannelID, BookmarkFields, TokenOverridable {
/** @description Type of the bookmark. Only `link` is supported at the moment. */
type: 'link';
/** @description ID of the entity being bookmarked. Only applies to message and file types. */
Expand All @@ -26,10 +22,10 @@ export interface BookmarksAddArguments extends Channel, BookmarkFields, TokenOve
parent_id?: string;
}
// https://api.slack.com/methods/bookmarks.edit
export interface BookmarksEditArguments extends Channel, ID, Partial<BookmarkFields>, TokenOverridable {}
export interface BookmarksEditArguments extends ChannelID, ID, Partial<BookmarkFields>, TokenOverridable {}

// https://api.slack.com/methods/bookmarks.list
export interface BookmarksListArguments extends Channel, TokenOverridable {}
export interface BookmarksListArguments extends ChannelID, TokenOverridable {}

// https://api.slack.com/methods/bookmarks.remove
export interface BookmarksRemoveArguments extends Channel, ID, TokenOverridable {}
export interface BookmarksRemoveArguments extends ChannelID, ID, TokenOverridable {}
6 changes: 2 additions & 4 deletions packages/web-api/src/types/request/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OptionalArgument } from '../helpers';
import type { ChannelIDs, TokenOverridable, UserIDs } from './common';
import type { ChannelID, ChannelIDs, TokenOverridable, UserIDs } from './common';

interface CanvasID {
/** @description Encoded ID of the canvas. */
Expand Down Expand Up @@ -89,9 +89,7 @@ export interface CanvasesEditArguments extends CanvasID, TokenOverridable {
}

// 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;
export interface ConversationsCanvasesCreateArguments extends ChannelID, TokenOverridable {
/** @description Structure describing the type and contents of the Canvas being created. */
document_content?: DocumentContent;
}
4 changes: 4 additions & 0 deletions packages/web-api/src/types/request/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export interface UserIDs {
/** @description List of encoded user IDs. */
user_ids: [string, ...string[]];
}
export interface UserID {
/** @description Encoded user ID. */
user_id: string;
}

export interface AppID {
/** @description The ID of the app. */
Expand Down
32 changes: 29 additions & 3 deletions packages/web-api/src/types/request/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ export interface IsPrivate {
/** @description Whether the channel should be private. */
is_private?: boolean;
}
interface Message extends Channel {
interface MessageSpecifier extends Channel {
/** @description Unique identifier of message. */
ts: string;
}
interface Message {
/** @description A message to send to the user who requested the invite. */
message?: string;
}
export interface UserIDs {
/** List of user IDs to receive this invite. Either `emails` or `user_ids` must be provided. */
user_ids: string[];
Expand Down Expand Up @@ -156,7 +160,7 @@ export type ConversationsListConnectInvitesArguments = OptionalArgument<
>;

// https://api.slack.com/methods/conversations.mark
export interface ConversationsMarkArguments extends Message, TokenOverridable {}
export interface ConversationsMarkArguments extends MessageSpecifier, TokenOverridable {}

// https://api.slack.com/methods/conversations.members
export interface ConversationsMembersArguments extends Channel, TokenOverridable, CursorPaginationEnabled {}
Expand All @@ -181,12 +185,34 @@ export interface ConversationsRenameArguments extends Channel, TokenOverridable

// https://api.slack.com/methods/conversations.replies
export interface ConversationsRepliesArguments
extends Message,
extends MessageSpecifier,
IncludeAllMetadata,
TokenOverridable,
CursorPaginationEnabled,
TimelinePaginationEnabled {}

// https://api.slack.com/methods/conversations.requestSharedInvite.approve
export interface ConversationsRequestSharedInviteApproveArguments extends InviteID, Partial<ChannelID> {
/**
* @description Whether the invited team will have post-only permissions in the channel.
* Will override the value on the requested invite.
*/
is_external_limited?: boolean;
/** @description Optional additional messaging to attach to the invite approval message. */
message?: {
/**
* @description When `true`, will override the user specified message. Otherwise, `text` will be appended to the
* user specified message on the invite request.
*/
is_override: boolean;
/** @description Text to include along with the email invite. */
text: string;
};
}

// https://api.slack.com/methods/conversations.requestSharedInvite.deny
export interface ConversationsRequestSharedInviteDenyArguments extends InviteID, Message {}

// https://api.slack.com/methods/conversations.setPurpose
export interface ConversationsSetPurposeArguments extends Channel, TokenOverridable {
/** @description A new, specialer purpose. */
Expand Down
2 changes: 2 additions & 0 deletions packages/web-api/src/types/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export type {
ConversationsOpenArguments,
ConversationsRenameArguments,
ConversationsRepliesArguments,
ConversationsRequestSharedInviteApproveArguments,
ConversationsRequestSharedInviteDenyArguments,
ConversationsSetPurposeArguments,
ConversationsSetTopicArguments,
ConversationsUnarchiveArguments,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* 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 type { WebAPICallResult } from '../../WebClient';
export type ConversationsRequestSharedInviteApproveResponse = WebAPICallResult & {
invite_id?: string;
ok?: boolean;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* 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 type { WebAPICallResult } from '../../WebClient';
export type ConversationsRequestSharedInviteDenyResponse = WebAPICallResult & {
ok?: boolean;
};
2 changes: 2 additions & 0 deletions packages/web-api/src/types/response/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ export { ConversationsMembersResponse } from './ConversationsMembersResponse';
export { ConversationsOpenResponse } from './ConversationsOpenResponse';
export { ConversationsRenameResponse } from './ConversationsRenameResponse';
export { ConversationsRepliesResponse } from './ConversationsRepliesResponse';
export { ConversationsRequestSharedInviteApproveResponse } from './ConversationsRequestSharedInviteApproveResponse';
export { ConversationsRequestSharedInviteDenyResponse } from './ConversationsRequestSharedInviteDenyResponse';
export { ConversationsSetPurposeResponse } from './ConversationsSetPurposeResponse';
export { ConversationsSetTopicResponse } from './ConversationsSetTopicResponse';
export { ConversationsUnarchiveResponse } from './ConversationsUnarchiveResponse';
Expand Down
34 changes: 34 additions & 0 deletions packages/web-api/test/types/methods/conversations.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,40 @@ expectAssignable<Parameters<typeof web.conversations.replies>>([
},
]);

// conversations.requestSharedInvite.approve
// -- sad path
expectError(web.conversations.requestSharedInvite.approve()); // lacking argument
expectError(web.conversations.requestSharedInvite.approve({})); // empty argument
// if specified, message requires `text` and `is_override`
expectError(web.conversations.requestSharedInvite.approve({ message: { is_override: true } })); // missing message.text
expectError(web.conversations.requestSharedInvite.approve({ message: { text: 'i will allow it' } })); // missing message.text
// -- happy path
expectAssignable<Parameters<typeof web.conversations.requestSharedInvite.approve>>([
{
invite_id: 'I1234',
},
]);
expectAssignable<Parameters<typeof web.conversations.requestSharedInvite.approve>>([
{
invite_id: 'I1234',
message: {
is_override: false,
text: 'You have the administrator blessing',
},
},
]);

// conversations.requestSharedInvite.deny
// -- sad path
expectError(web.conversations.requestSharedInvite.deny()); // lacking argument
expectError(web.conversations.requestSharedInvite.deny({})); // empty argument
// -- happy path
expectAssignable<Parameters<typeof web.conversations.requestSharedInvite.deny>>([
{
invite_id: 'I1234',
},
]);

// conversations.setPurpose
// -- sad path
expectError(web.conversations.setPurpose()); // lacking argument
Expand Down
8 changes: 2 additions & 6 deletions packages/web-api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
"sourceMap": true
},
"extends": "@tsconfig/recommended/tsconfig.json",
"include": [
"src/**/*"
],
"exclude": [
"src/**/*.spec.*"
],
"include": ["src/**/*"],
"exclude": ["src/**/*.spec.*"],
"jsdoc": {
"out": "support/jsdoc",
"access": "public"
Expand Down

0 comments on commit a3a06ec

Please sign in to comment.