diff --git a/integrations/slack/integration.definition.ts b/integrations/slack/integration.definition.ts index cf2cc738d7e..df27854c88b 100644 --- a/integrations/slack/integration.definition.ts +++ b/integrations/slack/integration.definition.ts @@ -17,7 +17,7 @@ export default new IntegrationDefinition({ name: 'slack', title: 'Slack', description: 'Automate interactions with your team.', - version: '2.5.2', + version: '2.5.3', icon: 'icon.svg', readme: 'hub.md', configuration, diff --git a/integrations/slack/src/setup.ts b/integrations/slack/src/setup.ts index f2b3dea0325..9b0fb3d3960 100644 --- a/integrations/slack/src/setup.ts +++ b/integrations/slack/src/setup.ts @@ -83,7 +83,7 @@ export const register: bp.IntegrationProps['register'] = async ({ client, ctx, l const missingScopes = REQUIRED_SLACK_SCOPES.filter((scope) => !grantedScopes.includes(scope)) throw new sdk.RuntimeError( - `The Slack access token is missing required scopes. Please re-authorize the app.\n\n` + + 'The Slack access token is missing required scopes. Please re-authorize the app.\n\n' + `Missing scopes: ${missingScopes.join(', ')}.\n` + `Granted scopes: ${grantedScopes.join(', ')}.` ) diff --git a/integrations/slack/src/slack-api/slack-scopes.ts b/integrations/slack/src/slack-api/slack-scopes.ts index fbcb763a3be..d95088f6cca 100644 --- a/integrations/slack/src/slack-api/slack-scopes.ts +++ b/integrations/slack/src/slack-api/slack-scopes.ts @@ -10,8 +10,15 @@ export const requiresAllScopesDecorator = (slackClient: SlackClient, methodName: string, descriptor: PropertyDescriptor): void => { const _originalMethod: (...args: unknown[]) => Promise = descriptor.value descriptor.value = function (...args: unknown[]) { + // This function replaces the property descriptor (the class method) with + // a new function. Within the context of this function, `this` refers to + // the instance of the class (SlackClient) where the method is defined. + + // We use .apply and .call to ensure that instance methods are attached to + // the actual instance of SlackClient. + if (!slackClient.hasAllScopes.apply(this, [requiredScopes])) { - const grantedScopes = slackClient.getGrantedScopes() + const grantedScopes = slackClient.getGrantedScopes.call(this) const missingScopes = requiredScopes.filter((scope) => !grantedScopes.includes(scope)) throw new sdk.RuntimeError( @@ -19,7 +26,7 @@ export const requiresAllScopesDecorator = 'Please re-authorize the app. \n\n' + `Scopes required for this operation: ${requiredScopes.join(', ')}. \n` + `Missing scopes: ${missingScopes.join(', ')}. \n` + - `Scopes granted to the app: ${slackClient.getGrantedScopes().join(', ')}.` + `Scopes granted to the app: ${grantedScopes.join(', ')}.` ) } return _originalMethod.apply(this, args)