Skip to content
 
 

Repository files navigation

N-slack

A lightweight library for integrating Slack with your NestJS applications.


N-slack enables you to send Slack messages from your NestJS projects.

⚡ Features

  • Send messages via Slack Web API
  • Webhook support

🚀 Quick Start

npm install n-slack

Basic Setup

import { Module } from "@nestjs/common";
import { SlackModule } from "n-slack";

@Module({
    imports: [
        SlackModule.forRoot({
            type: "api",
            token: "<insert-token-here>",
        }),
    ],
})
export class AppModule {}

Webhook Example

SlackModule.forRoot({
    type: "webhook",
    url: "<your-webhook-url>",
});

Multiple Webhooks

SlackModule.forRoot({
    type: "webhook",
    channels: [
        { name: "dev", url: "<webhook-url-1>" },
        { name: "customers", url: "<webhook-url-2>" },
    ],
});

TypeScript Channel Assertions

declare module "n-slack" {
    type Channels = "dev" | "customers";
}

📝 Usage Example

Inject SlackService into your services or controllers:

import { Injectable } from "@nestjs/common";
import { SlackService } from "n-slack";

@Injectable()
export class AuthService {
    constructor(private service: SlackService) {}

    helloWorldMethod() {
        this.service.sendText("Hello world was sent!");
        return "hello world";
    }
}

You can also access the underlying Slack WebClient:

import { Injectable } from "@nestjs/common";
import { SlackService } from "n-slack";

@Injectable()
export class AuthService {
    constructor(private service: SlackService) {}

    async findUserByEmail(email: string) {
        return await this.service.client.users.lookupByEmail(email);
    }
}

🟢 Acknowledgements

This project is inspired by and based on bjerkio/nestjs-slack.

📄 License

Distributed under the Apache License 2.0, following the original package's terms.

About

Lightweight library to use Slack in NestJS applications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages