0.2.2 • Published 4 years ago

@sikora00/nestjs-slack-bot v0.2.2

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

@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

0.2.2

4 years ago

0.2.1

4 years ago

0.2.1-alpha.5

4 years ago

0.2.1-alpha.2

4 years ago

0.2.1-alpha.3

4 years ago

0.2.1-alpha.4

4 years ago

0.2.1-alpha.0

4 years ago

0.2.1-alpha.1

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.1.0-alpha.3

4 years ago

0.1.0-alpha.2

4 years ago