seratch / slack-bolt-extensions

Collection of bolt-js InstallationStore/Receiver implementations + Next.js support module
MIT License
34 stars 6 forks source link
bolt nodejs slack slackapi typescript

⚡ Bolt for JavaScript Extensions

npm version lerna

This project aims to provide the following enhancement on top of bolt-js.

Receiver

At this moment, we support the following web frameworks. To learn how to use these Receiver in your bolt-js apps, check src/tests/bolt-example.ts. You can run the app by npm run bolt in each package directory.

For instance, if you go with Prisma, your Bolt app code will look like the one below:

import Router from '@koa/router';
import Koa from 'koa';
import { App, FileInstallationStore, LogLevel } from '@slack/bolt';
import { KoaReceiver } from '@seratch_/bolt-koa';

const koa = new Koa();
const router = new Router();

const receiver = new KoaReceiver({
  signingSecret: process.env.SLACK_SIGNING_SECRET!,
  clientId: process.env.SLACK_CLIENT_ID,
  clientSecret: process.env.SLACK_CLIENT_SECRET,
  scopes: ['commands', 'chat:write', 'app_mentions:read'],
  installationStore: new FileInstallationStore(),
  koa,
  router,
});

const app = new App({
  logLevel: LogLevel.DEBUG,
  receiver,
});

app.event('app_mention', async ({ event, say }) => {
  await say({
    text: `<@${event.user}> Hi there :wave:`,
    blocks: [
      {
        type: 'section',
        text: {
          type: 'mrkdwn',
          text: `<@${event.user}> Hi there :wave:`,
        },
      },
    ],
  });
});

(async () => {
  await app.start();
  console.log('⚡️ Bolt app is running!');
})();

If you go with any of other packages, just replacing the Receiver part works for you.

InstallationStore

At this moment, we support the following database libraries. To learn how to use these InstallationStore in your bolt-js apps, check src/tests/bolt-example.ts. You can run the app by npm run bolt in each package directory.

For instance, if you go with Prisma, your Bolt app code will look like the one below:

import { App } from '@slack/bolt';
import { PrismaClient } from '@prisma/client';
import { PrismaInstallationStore } from '@seratch_/bolt-prisma';

const prismaClient = new PrismaClient({
  log: [
    {
      emit: 'stdout',
      level: 'query',
    },
  ],
});
const installationStore = new PrismaInstallationStore({
  // The name `slackAppInstallation` can be different
  // if you use a different name in your Prisma schema
  prismaTable: prismaClient.slackAppInstallation,
  clientId: process.env.SLACK_CLIENT_ID,
});
const app = new App({
  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: ['commands', 'chat:write', 'app_mentions:read'],
  installationStore,
});

app.event('app_mention', async ({ event, say }) => {
  await say({
    text: `<@${event.user}> Hi there :wave:`,
    blocks: [
      {
        type: 'section',
        text: {
          type: 'mrkdwn',
          text: `<@${event.user}> Hi there :wave:`,
        },
      },
    ],
  });
});

(async () => {
  await app.start();
  console.log('⚡️ Bolt app is running!');
})();

If you go with any of other packages, just replacing the installationStore part works for you.

Features

All the packages guarantee they work with great consideration for the following points:

Open source license

All the packages in this repository are published in the npm package registry under the MIT open-source license.

Maintainers Guide

Run all the unit tests

You can run all the unit tests ysung lerna command:

git clone git@github.com:seratch/slack-bolt-extensions.git
cd slack-bolt-extensions/
npm i
npx lerna bootstrap
npx lerna run test

When you work on a specific project, head to the package directory and use npm commands here:

cd slack-bolt-extensions/
npm i
npx lerna bootstrap
cd packages/bolt-prisma/
npm test
code . # Open the project in Visual Studio Code

Publish the packages

For publishing the packages, we always use lerna publish command.

npx lerna bootstrap
npx lerna publish
# Follow the interactive steps with lerna