{"flow":{"id":28,"summary":"Example handler for slack bot commands and @mentions","versions":[130,131,132,133,134,183,285],"created_by":"mrl5","created_at":"2022-11-14T18:58:14.059Z","votes":0,"approved":true,"apps":["slack"],"value":{"modules":[{"id":"c","value":{"lock":"","path":null,"type":"rawscript","content":"export async function main(text_input: string): Output {\n  const tokenized: string[] = text_input?.split(' ') || [];\n  const command = tokenized[0] || 'help';\n  const input = tokenized.slice(1,).join(' ');\n\n  return { command, input };\n}\n\ninterface Output {\n  command: string;\n  input: string;\n}","language":"deno","input_transforms":{"text_input":{"expr":"flow_input.text","type":"javascript"}}},"summary":"parse input","stop_after_if":null,"input_transforms":{}},{"id":"d","value":{"type":"branchone","default":[{"id":"e","value":{"lock":null,"path":null,"type":"rawscript","content":"import { WebClient } from \"https://deno.land/x/slack_web_api@1.0.3/mod.ts\";\nimport * as wmill from \"https://deno.land/x/windmill@v1.85.0/mod.ts\";\n\ntype Slack = {\n  token: string;\n};\n\nexport async function main(\n  response_url: string,\n  command: string,\n  channel_id?: string\n) {\n  const help = `Supported commands\n  help - prints this command\n  echo - prints input\n  `;\n  \n  // Check if triggered by @mention or slash command\n  if (command === '@mention') {\n    // For @mentions, use Slack API to respond\n    const slack = await wmill.getResource<Slack>(\"f/slack_bot/bot_token\");\n    const web = new WebClient(slack.token);\n    await web.chat.postMessage({\n      channel: channel_id,\n      text: help,\n    });\n  } else {\n    // For slash commands, use response_url\n    await fetch(response_url, {\n      method: 'POST',\n      body: JSON.stringify({ text: help }),\n    });\n  }\n}\n","language":"deno","input_transforms":{"command":{"expr":"flow_input.command","type":"javascript"},"channel_id":{"expr":"flow_input.channel_id","type":"javascript"},"response_url":{"expr":"flow_input.response_url","type":"javascript"}}},"summary":"print help","stop_after_if":null,"input_transforms":{}}],"branches":[{"expr":"results.c.command === 'echo'","modules":[{"id":"h","value":{"path":"hub/28071/slack/example_of_responding_to_a_slack_command","type":"script","input_transforms":{"text":{"expr":"results.c.input","type":"javascript"},"command":{"expr":"flow_input.command","type":"javascript"},"channel_id":{"expr":"flow_input.channel_id","type":"javascript"},"response_url":{"expr":"flow_input.response_url","type":"javascript"}}},"summary":"handle echo command","stop_after_if":null,"input_transforms":{}}],"summary":"run command"}]},"summary":"","stop_after_if":null,"input_transforms":{}}],"failure_module":null},"schema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["response_url","text"],"properties":{"text":{"type":"string","format":"","default":"","description":"The text following the command or @mention"},"command":{"type":"string","format":"","default":null,"description":"Trigger type: '/windmill' for slash commands, '@mention' for @mentions"},"channel_id":{"type":"string","format":"","default":null,"description":"Slack channel ID where message was sent"},"response_url":{"type":"string","format":"","default":"","description":"Slack webhook URL (empty for @mentions)"}}},"description":"Slack bot will handle both slash commands and @mentions:\n```console\n/windmill help\n/windmill echo foo bar\n@Windmill help\n@Windmill echo foo bar\n```","recording":null,"vcreated_at":"2025-10-30T13:46:12.684Z","vcreated_by":"alex308","comments":[]}}