Skip to main content

Sending data via a webhook to start a Slack workflow

This technique requires a Slack paid plan to use Workflow Builder.

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:

  1. Create a Slack workflow that starts from a webhook.
  2. Copy the webhook URL and add it as a repository secret called SLACK_WEBHOOK_URL.
  3. Add this Action as a step to your GitHub workflow and provide an input payload to send to the webhook.
  4. 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:

OutputTypeDescription
timenumberThe Unix epoch time that the step completed.
okbooleanIf the request completed with success.
responsestringThe 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

example-workflows/Technique_1_Slack_Workflow_Builder/builds.data.json
loading...

GitHub Actions workflow

example-workflows/Technique_1_Slack_Workflow_Builder/builds.gha.yml
loading...

Slack app manifest

example-workflows/Technique_1_Slack_Workflow_Builder/builds.manifest.json
loading...

Slack webhook trigger

example-workflows/Technique_1_Slack_Workflow_Builder/builds.trigger.json
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:

  1. Open a form to select a channel.
  2. Send a message to the selected channel.
  3. React with a :tada: emoji.

GitHub Actions workflow

example-workflows/Technique_1_Slack_Workflow_Builder/announcements.gha.yml
loading...

Slack app manifest

example-workflows/Technique_1_Slack_Workflow_Builder/announcements.manifest.json
loading...

Slack webhook trigger

example-workflows/Technique_1_Slack_Workflow_Builder/announcements.trigger.json
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

example-workflows/Technique_1_Slack_Workflow_Builder/topic.gha.yml
loading...

Slack app manifest

example-workflows/Technique_1_Slack_Workflow_Builder/topic.manifest.json
loading...

Slack webhook trigger

example-workflows/Technique_1_Slack_Workflow_Builder/topic.trigger.json
loading...