Skip to main content

Sending data as a message with a Slack incoming webhook URL

This technique uses this Action to post a message to a channel or direct message with incoming webhooks and a Slack app.

Incoming webhooks follow the same formatting patterns as other Slack messaging APIs. Posted messages can be as short as a single line of text, include additional interactivity with interactive components, or be formatted with Block Kit to build visual components.

Setup

Gather a Slack incoming webhook URL:

  1. Create a Slack app for your workspace or use an existing app.
  2. Add the incoming-webhook bot scope under OAuth & Permissions page on app settings.
  3. Install the app to your workspace and select a channel to notify from the Install App page.
  4. Create additional webhooks from the Incoming Webhooks page.
  5. Add the generated incoming webhook URL as a repository secret called SLACK_WEBHOOK_URL.
  6. Add this Action as a step to your GitHub workflow and provide an input payload to send as a message.

The webhook URL will resemble something like so:

https://hooks.slack.com/services/T0123456789/B1001010101/7IsoQTrixdUtE971O1xQTm4T

Usage

Add the collected webhook from above to a GitHub workflow and configure the step using mrkdwn formatting values for a message or Block Kit blocks:

- name: Post a message in a channel
uses: slackapi/slack-github-action@v3.0.1
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
text: "*GitHub Action build result*: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
blocks:
- type: "section"
text:
type: "mrkdwn"
text: "GitHub Action build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"

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

Post an inline text message

This workflow uses incoming webhooks to post a plain text message.

example-workflows/Technique_3_Slack_Incoming_Webhook/text.yml
loading...
Post an inline block message

This workflow uses incoming webhooks to post a message with Block Kit.

example-workflows/Technique_3_Slack_Incoming_Webhook/blocks.yml
loading...
Post blocks found in a file

This workflow uses file data when posting to an incoming webhook. It links to the GitHub Actions job in progress.

Payload file being sent

example-workflows/Technique_3_Slack_Incoming_Webhook/saved.data.json
loading...

Workflow

example-workflows/Technique_3_Slack_Incoming_Webhook/saved.gha.yml
loading...