Example of responding to Slack commands and @mentions
One script reply has been approved by the moderators Verified

This script responds to both /windmill <text> slash commands and @Windmill mentions in Slack.

Created by admin 1116 days ago Picked 1 time
Submitted by henri186 Deno
Verified 29 days ago
1
  import { WebClient } from 'https://deno.land/x/[email protected]/mod.ts';
2
  import * as wmill from 'https://deno.land/x/[email protected]/mod.ts';
3

4
  type Slack = {
5
      token: string;
6
  };
7

8
  export async function main(
9
      response_url: string,
10
      text: string,
11
      channel_id?: string,
12
      command?: string
13
  ) {
14
      if (command === "@mention") {
15
          // @mention - use Slack API
16
          const slack = await wmill.getResource<Slack>('f/slack_bot/bot_token');
17
          const web = new WebClient(slack.token);
18
          await web.chat.postMessage({
19
              channel: channel_id,
20
              text: `Echo: ${text}`
21
          });
22
      } else {
23
          // Slash command - use response_url
24
          await fetch(response_url, {
25
              method: 'POST',
26
              body: JSON.stringify({ text: `Echo: ${text}` })
27
          });
28
      }
29
  }
Other submissions