nestjs-slack-webhook
v12.0.0
Published
Nest.js + slack-webhook
Downloads
7,893
Readme
nestjs-slack-webhook
Slack incoming webhook integration for NestJS.
Install
npm install nestjs-slack-webhook @nestjs/common @slack/webhookUsage
Configure the webhook URL through an environment variable:
import { Module } from "@nestjs/common";
import { SlackModule } from "nestjs-slack-webhook";
@Module({
imports: [SlackModule.forRoot({ url: process.env.SLACK_WEBHOOK_URL! })],
})
export class AppModule {}Inject the webhook client into a service:
import { Injectable } from "@nestjs/common";
import { InjectSlack } from "nestjs-slack-webhook";
import { IncomingWebhook } from "@slack/webhook";
@Injectable()
export class NotificationsService {
constructor(@InjectSlack() private readonly slack: IncomingWebhook) {}
async notify(text: string): Promise<void> {
await this.slack.send({ text });
}
}API
SlackModule.forRoot(options)andSlackModule.forRootAsync(options)configure the webhook client.@InjectSlack()injects the configuredIncomingWebhookclient.optionsaccepts the webhookurland default arguments supported by@slack/webhook.
Contributing
Issues and pull requests are welcome at g59/nestjs-plugins.
License
MIT © g59
