@k11i/bolt-s3
v1.1.3
Published
S3-backed InstallationStore implementation for bolt-js
Downloads
47
Readme
Bolt for JavaScript: S3 InstallationStore
This package provides an S3-backed InstallationStore implementation with a few additional functionalities.
Features
- Encryption using node:crypto module.
- Compression with Brotli.
Installation
npm install @k11i/bolt-s3
You also need to install @aws-sdk/client-s3
package to create an S3 client.
Basic usage
import {App} from '@slack/bolt';
import {S3Client} from '@aws-sdk/client-s3';
import {S3InstallationStore} from '@k11i/bolt-s3';
const installationStore = S3InstallationStore.create({
clientId,
s3: new S3Client(),
// An S3 bucket needs to be created.
bucketName: 'bucket-name-where-installations-are-stored',
options: {
historicalDataEnabled: true,
// Omit the following line if you prefer not to encrypt and/or compress installations.
installationCodec: BinaryInstallationCodec.createDefault(
'your-encryption-password',
'your-encryption-salt',
),
}
});
const app = new App({
socketMode: true,
appToken: process.env.SLACK_APP_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
clientId: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
stateSecret: process.env.SLACK_STATE_SECRET,
scopes: ['chat:write'],
installerOptions: {
directInstall: true,
},
installationStore,
});
// ...
// To delete installations correctly, we should handle tokens_revoked/app_uninstalled events manually.
// See https://github.com/slackapi/bolt-js/issues/1203
app.event('tokens_revoked', async ({context, event, logger}) => {
const userIds = event.tokens.oauth;
if (!userIds) {
return;
}
const promises = userIds
.map(userId => ({
teamId: context.teamId,
enterpriseId: context.enterpriseId,
userId: userId,
isEnterpriseInstall: context.isEnterpriseInstall,
}))
.map(query => installationStore.deleteInstallation(query, logger));
await Promise.all(promises);
});
app.event('app_uninstalled', async ({context, logger}) => {
await installationStore.deleteInstallation(
{
teamId: context.teamId,
enterpriseId: context.enterpriseId,
isEnterpriseInstall: context.isEnterpriseInstall,
},
logger
);
});
(async () => {
await app.start();
console.log('⚡️ Bolt app is running!');
})();
License
MIT License.
Copyright (c) 2024 KOMIYA Atsushi.