Skip to content

Latest commit

 

History

History

slack-app

SlackApp

Custom resource to create a Slack App from a manifest.

Usage

Define a SlackApp:

import { Stack, StackProps } from 'aws-cdk-lib';
import * as cloudstructs from 'cloudstructs';
import { Construct } from 'constructs';

export class MyStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    new cloudstructs.SlackApp(this, 'MyApp', {
      configurationTokenSecret: secretsmanager.Secret.fromSecretNameV2(this, 'Secret', 'slack-app-config-token'),
      manifest: SlackAppManifestDefinition.fromManifest({
        name: 'My App',
        description: 'A very cool Slack App deployed with CDK',
        interactivity: {
          requestUrl: myApi.url, // reference other construct's properties
        },
      }),
    });
  }
}

The secret slack-app-config-token is expected to be of the following form:

{
  "refreshToken": "xoxe-1-..."
}

Go to App configuration tokens to create a refresh token. The construct will automatically use the refresh token to retrieve a new access token when needed.

By default, the construct creates an AWS Secrets Manager secret and stores the app credentials in it. You can use your own secret by specifying the credentialsSecret prop.

Consuming app credentials

The credentials property of the SlackApp exposes a secretsmanager.Secret with the app credentials. The secret has the following form:

{
  "appId": "...",
  "clientId": "...",
  "clientSecret": "...",
  "verificationToken": "...",
  "signingSecret": "..."
}

The credentials are also exposed as individual properties that create CloudFormation dynamic references:

const myApp = new cloudstructs.SlackApp(this, 'MyApp', { ... });

myLambda.addEnvironment('CLIENT_ID', myApp.clientId);