Socket
Book a DemoInstallSign in
Socket

@sikora00/nestjs-slack-bot

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sikora00/nestjs-slack-bot

A module for Nest.js to handle incoming messages from slack as a commands.

0.2.2
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

@sikora00/nestjs-slack-bot

build version downloads license

Module for handling commands from Slack.

Usage

Create your slack bot

Slack Apps

Import module

import { Module } from '@nestjs/common';
import { SlackBotModule } from '@sikora00/nestjs-slack-bot';
import { HelloSlackCommand } from './hello.slack-command';

@Module({
  imports: [SlackBotModule.forRoot({ slackToken: 'yourSlackBotToken' })],
  providers: [HelloSlackCommand],
})
export class AppModule {}

Define Slack Command Handler

Create injectable Nestjs's service with @SlackCommandHandler decorator

import { Injectable } from '@nestjs/common';
import {
  SlackCommand,
  SlackCommandHandler,
  SlackMessage,
  SlackService,
} from '@sikora00/nestjs-slack-bot';

@SlackCommandHandler()
@Injectable()
export class HelloSlackCommand implements SlackCommand {
  description: string = 'say hello to the Slack Bot';
  type: string = 'hello';

  constructor(private slack: SlackService) {}

  async handler(command: string[], message: SlackMessage): Promise<void> {
    return 'Hello! I am SlackBot';
  }
}

Then send a massage with the first word hello in any channel where the bot is invited.

Docs

Help command

Nestjs Slack Bot package has build in help command handler. It displays list of all registered commands in format type: description received from SlackCommandHandler class definitions.

Interceptors

To handle or modify incoming or response messages use SlackInterceptor.

@SlackInterceptor()
@Injectable()
export class HelloInterceptor implements ISlackInterceptor {
  intercept(
    message: SlackMessage,
    next: CallHandler<any>
  ): Observable<any> | Promise<Observable<any>> {
    return next.handle().pipe(
      map((res) => {
        if (res) {
          return `Hello Maciej\n${res}`;
        }
      })
    );
  }
}

Authors

Keywords

nestjs

FAQs

Package last updated on 19 Nov 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.