From 8a6d840f81e604b471b4c22357566e4e400f0628 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 16 Nov 2022 21:50:37 +0100 Subject: [PATCH] fix: support flows to be triggered by slack commands --- backend/windmill-api/src/oauth2.rs | 19 +++++++++---- frontend/src/routes/workspace_settings.svelte | 27 ++++++++++--------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/backend/windmill-api/src/oauth2.rs b/backend/windmill-api/src/oauth2.rs index 6cde5d8033..5082e037f1 100644 --- a/backend/windmill-api/src/oauth2.rs +++ b/backend/windmill-api/src/oauth2.rs @@ -716,10 +716,19 @@ async fn slack_command( .await?; if let Some(settings) = settings { - if let Some(script) = &settings.slack_command_script { - let script_hash = - windmill_common::get_latest_hash_for_path(&mut tx, &settings.workspace_id, script) - .await?; + if let Some(path) = &settings.slack_command_script { + let payload = if let Some(path) = path.strip_prefix("flow/") { + JobPayload::Flow(path.to_string()) + } else { + let path = path.strip_prefix("script/").unwrap_or_else(|| path); + let script_hash = windmill_common::get_latest_hash_for_path( + &mut tx, + &settings.workspace_id, + path, + ) + .await?; + JobPayload::ScriptHash { hash: script_hash, path: path.to_owned() } + }; let mut map = serde_json::Map::new(); map.insert("text".to_string(), serde_json::Value::String(form.text)); map.insert( @@ -730,7 +739,7 @@ async fn slack_command( let (uuid, tx) = windmill_queue::push( tx, &settings.workspace_id, - JobPayload::ScriptHash { hash: script_hash, path: script.to_owned() }, + payload, Some(map), &form.user_name, "g/slack".to_string(), diff --git a/frontend/src/routes/workspace_settings.svelte b/frontend/src/routes/workspace_settings.svelte index f6ba26ed2d..3fe410bfe1 100644 --- a/frontend/src/routes/workspace_settings.svelte +++ b/frontend/src/routes/workspace_settings.svelte @@ -25,7 +25,6 @@ import { goto } from '$app/navigation' import InviteUser from '$lib/components/InviteUser.svelte' import ScriptPicker from '$lib/components/ScriptPicker.svelte' - import AppConnect from '$lib/components/AppConnect.svelte' import { Button } from '$lib/components/common' import Tooltip from '$lib/components/Tooltip.svelte' import { faScroll, faWind } from '@fortawesome/free-solid-svg-icons' @@ -36,6 +35,7 @@ let userFilter = '' let scriptPath: string let team_name: string | undefined + let itemKind: 'flow' | 'script' = 'flow' const fuseOptions = { includeScore: false, @@ -73,7 +73,7 @@ async function editSlackCommand(): Promise { await WorkspaceService.editSlackCommand({ workspace: $workspaceStore!, - requestBody: { slack_command_script: scriptPath } + requestBody: { slack_command_script: `${itemKind}/${scriptPath}` } }) sendUserToast(`slack command script set to ${scriptPath}`) } @@ -233,16 +233,19 @@ {/if}

Script to run on /windmill command - A script run from slack /windmill command is run as group 'slack'. The script chosen is - passed the parameters
response_url: string, text: string
respectively the url to - reply directly to the trigger and the text of the command. - Define your own trigger script from a compatible template

- + >Script or flow to run on /windmill command + The script or flow to be triggered when the `/windmill` command is invoked. The script or + flow chosen is passed the parameters
response_url: string, text: string
+ respectively the url to reply directly to the trigger and the text of the command.
+ +