@xpr/nestjs-slack
v2.1.1
Published
NestJS server implementation of the Slack Assistant
Downloads
327
Readme
@xpr/nestjs-slack
A NestJS microservice transport and decorators for Slack Bolt Apps.
Usage
Make sure to install peer dependencies if not already installed (@slack/bolt).
npm i @xpr/nestjs-slackInitialize Slack/Bolt application with the Slack transport:
const app = await NestFactory.createMicroservice(MyModule, {
strategy: new Slack({
slack: {
token: env.SLACK_BOT_TOKEN,
appToken: env.SLACK_APP_TOKEN,
},
}),
});
await app.listen();📃 https://tools.slack.dev/bolt-js/getting-started
Slack Application Controller
Example of a Slack controller with listener for action and a command.
import { SlackAction, SlackCommand, SlackController } from "@xpr/nestjs-slack";
@SlackController()
export class MyController {
@SlackAction("button-action")
async onAction({ ack, respond, payload }: SlackActionMiddlewareArgs) {
await ack();
await respond(`Button clicked! with payload ${JSON.stringify(payload)}`);
}
@SlackCommand("/ping")
async onPing({ ack, respond }: SlackCommandMiddlewareArgs) {
await ack();
await respond({
text: "pong!",
response_type: "in_channel",
});
}
}📃 https://tools.slack.dev/bolt-js/concepts/event-listening
📃 https://tools.slack.dev/bolt-js/concepts/commands
Decorators
See source file.
