mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-07 16:03:21 +00:00
fix: support flows to be triggered by slack commands
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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<void> {
|
||||
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 @@
|
||||
</Button>
|
||||
{/if}
|
||||
<h3 class="mt-5 text-gray-700"
|
||||
>Script to run on /windmill command <Tooltip>
|
||||
A script run from slack /windmill command is run as group 'slack'. The script chosen is
|
||||
passed the parameters <pre>response_url: string, text: string</pre> respectively the url to
|
||||
reply directly to the trigger and the text of the command.
|
||||
<a href="/scripts/add?template=u/admin/triggered_from_slack_command"
|
||||
>Define your own trigger script from a compatible template</a
|
||||
></Tooltip
|
||||
></h3
|
||||
>
|
||||
<ScriptPicker kind={Script.kind.SCRIPT} bind:scriptPath on:select={editSlackCommand} />
|
||||
>Script or flow to run on /windmill command <Tooltip>
|
||||
The script or flow to be triggered when the `/windmill` command is invoked. The script or
|
||||
flow chosen is passed the parameters <pre>response_url: string, text: string</pre>
|
||||
respectively the url to reply directly to the trigger and the text of the command.</Tooltip
|
||||
>
|
||||
</h3>
|
||||
<ScriptPicker
|
||||
kind={Script.kind.SCRIPT}
|
||||
allowFlow
|
||||
bind:itemKind
|
||||
bind:scriptPath
|
||||
on:select={editSlackCommand}
|
||||
/>
|
||||
|
||||
<div class="mt-10" />
|
||||
<PageHeader title="Export workspace" primary={false} />
|
||||
|
||||
Reference in New Issue
Block a user