Slack Integration
Slack is an instant messaging and collaboration platform.
There are two ways to build interactions between Slack and Windmill: run code on Windmill by a Slack command or use the Slack API directly from Windmill. In this guide, we'll cover both approaches.
Action on Windmill from Slack
The goal here is to be able to invoke a Windmill Script from Slack, by using
/windmill
command.
First, you need to be a workspace admin. Then you should go to
Workspace Settings Page
and select the "Slack Command" tab. On there, click "Connect to Slack".
The Slack integration is done through OAuth. On self-hosted instances, integrating an OAuth API will require Setup OAuth and SSO.
Slack will ask you to allow Windmill to access your workspace. Click "Allow".
At the time of writing, Slack cautions that Windmill is not an approved app. We are working on getting the app approved but you can safely ignore it for now.
You can connect multiple Windmill workspaces to the same Slack workspace. Only one Windmill workspace can accept the /windmill
commands from a given Slack workspace. This feature is mostly useful for the error handler.
Using commands on Slack
Once you allow access, you will be redirected to the Slack settings in Windmill. We'll create a command handler Script first, so let's click "Create a script to handle slack command".
You will be navigated to the Script editor. Give your script a name
(e.g. slack_command_handler
), a short summary (e.g. "Slack command handler"). You'll get to this template:
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}`);
}
After the Script is deployed, navigate back to the
Slack settings
Choose the "Script" option for adding a command handler and select your newly created Script.
Congratulations! You've just created a Slack command handler. Now you can use
the /windmill
command in your Slack workspace to trigger the Script. Try it
out with /windmill foo
and you should get back ROGER foo
. Go ahead and
customize the Script to your needs.
In addition to response_url, the script/flow can use the following parameters, simply by having them as inputs with the proper name:
channel_id
user_name
user_id
command
trigger_id
api_app_id
You won't be able to have Slack interact with your resources and variables before adding them to the slack
group that was automatically created by Windmill after you set up your Slack workspace on Windmill. Tutorial below.