In this tutorial we will set up a webhook that will cause a message to be posted to a Slack channel whenever a deployment occurs in an Environment of a particular Application.
You will require:
An App set up in Humanitec
A "paid for" Slack organization
The fastest way of getting a message into a channel in Slack is with Slack Workflows. We will build a workflow that is triggered by a webhook and then posts a message to a channel.
You can access the workflow builder in Slack by clicking your Slack organization's name in the top left of the desktop version of Slack. Select Tools → Workflow Builder.
In the Workflow Builder, click the Create button in the top right.
When prompted, choose a name for your workflow.
Click the Select button next to "Webhook (advanced)" from the options to start the workflow.
The webhook request generated by Humanitec will contain a number of variables that we need to configure in Slack.
You should add the following variables:
You can add these variables by clicking the Add Variable button.
Once the variables are added, your dialog should look like this:
Click Save to move to the next step.
Next, you will be prompted to add a step to the workflow. Click Add Step.
Then choose Send a message step by clicking the Add button next to "Send a message".
Choose the channel you want to send to and craft your message. You can insert the variables you added earlier into the message by clicking the Insert a variable button. You can also add formatting as you would in Slack. A preview of how your message will look is shown at the bottom of the window.
Once you are happy with your message, click Save.
Click the Publish button in the top right of the Workflow Builder to publish your workflow.
Next you will be prompted with the URL to use for the webhook. Make sure you copy this somewhere safe. You will need to paste it into Humanitec later.
Enter an ID you will use to identify this webhook in future. It must be a valid Humanitec ID.
Paste in the URL you copied in the last step of creating your Slack workflow.
Select the Deployment → Finished trigger to make the webhook be fired once every deployment has completed.
Click the Create button finish setting up the webhook.
When you next deploy to an Environment in the App, you should get a slack message in the channel you setup in your workflow!