Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@seratch_/bolt-fastify
Advanced tools
This module provides a Receiver
implementation for Fastify users.
You can create a simple Node app project using the following package.json
and tsconfig.json
. Of course, if you would like to use some build tool such as webpack, you can go with your own way and add the necessary dependencies.
{
"name": "bolt-fastify-app",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "rm -rf dist/ && tsc && npx ts-node src/index.ts"
},
"author": "Kazuhiro Sera",
"license": "MIT",
"dependencies": {
"@slack/bolt": "^3.12.2",
"fastify": "^3.27.4",
"@seratch_/bolt-fastify": "^1.0.0"
},
"devDependencies": {
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
}
}
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowJs": true,
"esModuleInterop": true,
"outDir": "dist",
},
"include": ["src/**/*"]
}
The next step is to create a new Slack app configuration. You can use the following App Manifest configuration data for it.
display_information:
name: fastify-oauth-test-app
features:
bot_user:
display_name: fastify-oauth-test-app
oauth_config:
redirect_urls:
- https://xxx.ngrok.io/slack/oauth_redirect
scopes:
bot:
- commands
- chat:write
- app_mentions:read
settings:
event_subscriptions:
bot_events:
- app_mention
interactivity:
is_enabled: true
socket_mode_enabled: true
The last step is to add your code in the project and spin up your app. You can use the following code as-is.
import Fastify from 'fastify';
import { App, FileInstallationStore, LogLevel } from '@slack/bolt';
import { FileStateStore } from '@slack/oauth';
import { FastifyReceiver } from '@seratch_/bolt-fastify';
const fastify = Fastify({ logger: true });
fastify.get('/', async (_, res) => {
res.redirect('/slack/install');
});
const receiver = new FastifyReceiver({
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(),
installerOptions: {
directInstall: true,
stateStore: new FileStateStore({}),
},
fastify,
});
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:`,
},
},
],
});
});
app.command('/my-command', async ({ ack }) => {
await ack('Hi there!');
});
app.shortcut('my-global-shortcut', async ({ ack, body, client }) => {
await ack();
await client.views.open({
trigger_id: body.trigger_id,
view: {
type: 'modal',
callback_id: 'my-modal',
title: {
type: 'plain_text',
text: 'My App',
},
submit: {
type: 'plain_text',
text: 'Submit',
},
blocks: [
{
type: 'input',
block_id: 'b',
element: {
type: 'plain_text_input',
action_id: 'a',
},
label: {
type: 'plain_text',
text: 'Comment',
},
},
],
},
});
});
app.view('my-modal', async ({ view, ack, logger }) => {
logger.info(view.state.values);
await ack();
});
(async () => {
await app.start();
// eslint-disable-next-line no-console
console.log('⚡️ Bolt app is running!');
})();
Finally, your app is now available for running! Set all the required env variables, hit npm start
, and then enable your public URL endpoint (you may want to use some proxy tool such as ngrok).
export SLACK_CLIENT_ID=
export SLACK_CLIENT_SECRET=
export SLACK_SIGNING_SECRET=
export SLACK_STATE_SECRET=secret
export SLACK_APP_TOKEN=
npm start
# Visit https://{your public domain}/slack/install
Now you can install the app into your Slack workspace from https://{your public domain}/slack/install
. Enjoy!
FAQs
Bolt for JavaScript Extension - Fastify
The npm package @seratch_/bolt-fastify receives a total of 1 weekly downloads. As such, @seratch_/bolt-fastify popularity was classified as not popular.
We found that @seratch_/bolt-fastify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.