Sending data via a webhook to start a Slack workflow
This technique sends data to Slack using a webhook to start a workflow created using Slack Workflow Builder.
Setup
Start in Slack to create a Slack workflow:
- Create a Slack workflow that starts from a webhook.
- Copy the webhook URL and add it as a repository secret called
SLACK_WEBHOOK_URL. - Add this Action as a step to your GitHub workflow and provide an input payload to send to the webhook.
- Configure your Slack workflow to use the payload variables sent from the GitHub Action. You can then update the steps of the Slack workflow to use these values in creative and clever ways.
The webhook URL will resemble something like so:
https://hooks.slack.com/triggers/T0123456789/3141592653589/c6e6c0d868b3054ca0f4611a5dbadaf
Usage
Update the input payloads sent from this GitHub Action to your Slack workflow using the following options:
Sending values from the default GitHub event context
In the example below, the default GitHub event context and event payload associated with the job that started the GitHub workflow are sent to the provided webhook URL:
- name: Send GitHub Action data to a Slack workflow
uses: slackapi/slack-github-action@v3.0.1
with:
payload-delimiter: "_"
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: webhook-trigger
Accessing variables sent to Workflow Builder with a webhook require that the payload variables are flattened with stringified values. Nested variables in the provided payload can be both flattened and also stringified with the payload-delimiter option or changed with other configurations to match this format expected from Workflow Builder.
Providing parsed payload information as strings
Provided input values for payload information are sent to the webhook URL after the job is started:
- name: Send custom event details to a Slack workflow
uses: slackapi/slack-github-action@v3.0.1
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: webhook-trigger
payload: |
status: "${{ job.status }}"
option: "false"
Gathering details of the payload from a saved file
Input values for the payload to be sent can also be provided in a file, either in JSON or YAML format:
- name: Send a saved artifact to a Slack workflow
uses: slackapi/slack-github-action@v3.0.1
with:
payload-file-path: "./artifacts.json"
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: webhook-trigger
Flattening nested payloads
Variables and data provided in the payload might contain nested fields that need to be flattened before being sent with a webhook trigger to match the expected input format of Workflow Builder.
The payload-delimiter option will flatten the input payload using the provided delimiter and will also make values stringified:
- name: Flatten the default GitHub payload
uses: slackapi/slack-github-action@v3.0.1
with:
payload-delimiter: "_"
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: webhook-trigger
Reference to the flattening implementation is available for exploration from within the flat package.
Expected outputs
The technique, like all Slack Github Action techniques, outputs values that can be used as inputs in following steps of a GitHub workflow.
The following outputs are returned with each of the techniques:
| Output | Type | Description |
|---|---|---|
time | number | The Unix epoch time that the step completed. |
ok | boolean | If the request completed with success. |
response | string | The response from the request as stringified JSON. |
Example workflows
Format generated files
This workflow converts build outputs from earlier GitHub Action steps into a Slack message.
This example uses data from a payload file to send a message to a hardcoded channel.
Payload file being sent
loading...
GitHub Actions workflow
loading...
Slack app manifest
loading...
Slack webhook trigger
loading...
Post release announcements
This workflow allows you to select a channel to post news about the most recent release to.
This example uses Slack functions and inline inputs to do the following:
- Open a form to select a channel.
- Send a message to the selected channel.
- React with a
:tada:emoji.
GitHub Actions workflow
loading...
Slack app manifest
loading...
Slack webhook trigger
loading...
Update a channel topic
This workflow shows the latest commit status in the header of a channel.
This example uses the default GitHub event context and payload to update a channel topic.
GitHub Actions workflow
loading...
Slack app manifest
loading...
Slack webhook trigger
loading...