@edirect/slack
v11.0.46
Published
Slack integration module for EDirectInsure applications, built for use with NestJS. Provides a configurable service for sending messages to Slack channels, supporting custom templates and message levels.
Maintainers
Keywords
Readme
@edirect/slack
Slack integration module for EDirectInsure applications, built for use with NestJS. Provides a configurable service for sending messages to Slack channels, supporting custom templates and message levels.
Features
- Send messages to Slack channels from your application
- Supports message templates and custom attributes
- Asynchronous configuration with environment variable support
- Integrates with @edirect/config and @edirect/logger
Installation
pnpm add @edirect/slack
# or
npm install @edirect/slackUsage
Register the SlackModule in your NestJS application. Example with async configuration:
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@edirect/config';
import { SlackModule, MessageLevel } from '@edirect/slack';
@Module({
imports: [
ConfigModule,
SlackModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
active: configService.get('SLACK_ACTIVE'),
service: 'Subscription Service',
cluster: configService.get('NAMESPACE'),
slack: {
token: configService.get('SLACK_TOKEN'),
channel: configService.get('SLACK_CHANNEL'),
},
}),
inject: [ConfigService],
}),
],
})
export class AppModule {}Sending a Message
import { SlackService, MessageLevel } from '@edirect/slack';
constructor(private readonly slackService: SlackService) {}
// ...
await this.slackService.sendMessage(
MessageLevel.INFO,
'Hello from the app!',
JSON.stringify({ foo: 'bar' }),
{ custom: 'attribute' }
);API
SlackService
sendMessage(level, message, payload?, attributes?, channel?, template?): Promise<string | null>- Sends a message to Slack. Returns the message timestamp or null if not sent.
Notes
- Requires a valid Slack bot token with
chat:writepermissions. - If
activeis false, messages will not be sent.
