Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integrations/slack/integration.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion integrations/slack/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')}.`
)
Expand Down
11 changes: 9 additions & 2 deletions integrations/slack/src/slack-api/slack-scopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ export const requiresAllScopesDecorator =
(slackClient: SlackClient, methodName: string, descriptor: PropertyDescriptor): void => {
const _originalMethod: (...args: unknown[]) => Promise<unknown> = 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(
`The Slack access token is missing required scopes to perform operation "${operation ?? methodName ?? descriptor.value?.name}". ` +
'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)
Expand Down
Loading