8000 GitHub - ziv/nestjs-slack: nestjs-slack-integration
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ziv/nestjs-slack

Repository files navigation

NestJS/Slack Integrations

slack logo nestjs logo

See example application at packages/nestjs-slack-example-app directory.

@xpr/nestjs-slack

A NestJS microservice transport for Slack Bolt Apps.

@xpr/nestjs-slack-assistant

A NestJS microservice transport for Slack Bolt Assistant.

Usage

Initialize Slack/Bolt application with the Slack transport:

const app = await NestFactory.createMicroservice(MyModule, {
  strategy: new Slack({
    slack: {
      token: env.SLACK_BOT_TOKEN,
      appToken: env.SLACK_APP_TOKEN,
    },
  }),
});
await app.listen();

📃 https://tools.slack.dev/bolt-js/getting-started

Initialize Slack/Bolt Assistant application with the SlackAssistant transport:

This transport is built on top of Slack transport. It provides all Slack transports features and provide decorators for the assistant application.

const app = await NestFactory.createMicroservice(MyModule, {
  strategy: new SlackAssistant({
    slack: {
      token: env.SLACK_BOT_TOKEN,
      appToken: env.SLACK_APP_TOKEN,
    },
  }),
});
await app.listen();

📃 https://tools.slack.dev/bolt-js/concepts/ai-apps

Slack Application Controller

Example of a Slack controller with listener for action and a command.

import { SlackAction, SlackCommand, SlackController } from "@xpr/nestjs-slack";

@SlackController()
export class MyController {
  @SlackAction("button-action")
  async onAction({ ack, respond, payload }: SlackActionMiddlewareArgs) {
    await ack();
    await respond(`Button clicked! with payload ${JSON.stringify(payload)}`);
  }

  @SlackCommand("/ping")
  async onPing({ ack, respond }: SlackCommandMiddlewareArgs) {
    await ack();
    await respond({
      text: "pong!",
      response_type: "in_channel",
    });
  }
}

📃 https://tools.slack.dev/bolt-js/concepts/event-listening

📃 https://tools.slack.dev/bolt-js/concepts/commands

Slack Assistant Controller

import {
  SlackController,
  ThreadStarted,
  UserMessage,
  // `@xpr/nestjs-slack-assistant` re-export everything from `@xpr/nestjs-slack`
} from "@xpr/nestjs-slack-assistant";

@SlackController()
export class MyController {
  // any `@xpr/nestjs-slack` decorator can be used here as well

  @ThreadStarted()
  async startThread(
    { say, setSuggestedPrompts }: AssistantThreadStartedMiddlewareArgs,
  ) {
    await setSuggestedPrompts({ prompts: [/*...*/] });
    await say("Hi, how can I help you?");
  }

  @UserMessage()
  async message({ say, message }: AssistantUserMessageMiddlewareArgs) {
    await say("You said: " + message.text);
  }
}

📃 https://tools.slack.dev/bolt-js/concepts/ai-apps


0