Edits history of script submission #416 for ' Example of responding to Slack commands and @mentions (slack)'

  • deno
    One script reply has been approved by the moderators
    Ap­pro­ved
      import { WebClient } from 'https://deno.land/x/[email protected]/mod.ts';
      import * as wmill from 'https://deno.land/x/[email protected]/mod.ts';
    
      type Slack = {
          token: string;
      };
    
      export async function main(
          response_url: string,
          text: string,
          channel_id?: string,
          command?: string
      ) {
          if (command === "@mention") {
              // @mention - use Slack API
              const slack = await wmill.getResource<Slack>('f/slack_bot/bot_token');
              const web = new WebClient(slack.token);
              await web.chat.postMessage({
                  channel: channel_id,
                  text: `Echo: ${text}`
              });
          } else {
              // Slash command - use response_url
              await fetch(response_url, {
                  method: 'POST',
                  body: JSON.stringify({ text: `Echo: ${text}` })
              });
          }
      }

    Submitted by alex308 190 days ago

  • deno
    import { WebClient } from "https://deno.land/x/[email protected]/mod.ts";
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    
    type Slack = {
      token: string;
    };
    
    export async function main(
      response_url: string,
      text: string,
      slack: Slack,
      channel_id?: string,
      command?: string
    ) {
      const username = await Deno.env.get("WM_USERNAME");
      console.log(`user = ${username}`);
    
      const responseText = `ROGER ${text}`;
    
      // Check if triggered by @mention or /windmill command
      if (command === "@mention") {
        // For @mentions, use Slack API to respond
        const web = new WebClient(slack.token);
        await web.chat.postMessage({
          channel: channel_id,
          text: responseText,
        });
      } else {
        // For slash commands, use response_url
        await fetch(response_url, {
          method: "POST",
          body: JSON.stringify({ text: responseText }),
        });
      }
    }
    

    Submitted by hugo697 191 days ago

  • deno
    export async function main(response_url: string, text: string) {
      const x = await fetch(response_url, {
        method: "POST",
        body: JSON.stringify({ text: `ROGER ${text}` }),
      });
      const username = await Deno.env.get("WM_USERNAME");
      console.log(`user = ${username}`);
    }
    

    Submitted by hugo697 352 days ago

  • deno
    export async function main(response_url: string, text: string) {
      const x = await fetch(response_url, {
        method: "POST",
        body: JSON.stringify({ text: `ROGER ${text}` }),
      });
      const username = await Deno.env.get("WM_USERNAME");
      console.log(`user = ${username}`);
    }
    

    Submitted by hugo697 367 days ago

  • deno
    export async function main(response_url: string, text: string) {
      const x = await fetch(response_url, {
        method: "POST",
        body: JSON.stringify({ text: `ROGER ${text}` }),
      });
      const username = await Deno.env.get("WM_USERNAME");
      console.log(`user = ${username}`);
    }
    

    Submitted by hugo697 928 days ago

  • deno
    export async function main(
      response_url: string,
      text: string,
    ) {
      const x = await fetch(response_url, {
        method: 'POST',
        body: JSON.stringify({ text: `ROGER ${text}` }),
      });
      const username = await Deno.env.get('WM_USERNAME')
      console.log(`user = ${username}`)

    Submitted by admin 929 days ago

  • deno
    export async function main(response_url: string, text: string) {
      const x = await fetch(response_url, {
        method: "POST",
        body: JSON.stringify({ text: `ROGER ${text}` }),
      });
      const username = await Deno.env.get("WM_USERNAME");
      console.log(`user = ${username}`);
    }
    

    Submitted by hugo697 942 days ago

  • deno
    export async function main(
      response_url: string,
      text: string,
    ) {
      const x = await fetch(response_url, {
        method: 'POST',
        body: JSON.stringify({ text: `ROGER ${text}` }),
      });
      const username = await Deno.env.get('WM_USERNAME')
      console.log(`user = ${username}`)

    Submitted by henri186 1016 days ago