Send data into Slack using this GitHub Action! This package has three different techniques to send data to Slack:
- Send data to Slack's Workflow Builder (requires a paid Slack instance).
- Send data via a Slack app to post to a specific channel (use an existing custom app or create a new one).
- Send data via a Slack Incoming Webhook URL (use an existing custom app or create a new one).
The recommended way to use this action is with Slack's Workflow Builder (if you're on a paid Slack plan).
❗️ This approach requires a paid Slack plan
Sending data to Slack's Workflow builder is the recommended way to use this action. This action will send data into Slack via a webhook URL. Follow these steps to create a Slack workflow using webhooks. The Slack workflow webhook URL will be in the form https://hooks.slack.com/workflows/....
. The payload sent by this GitHub action will be flattened (all nested keys moved to the top level) and stringified since Slack's workflow builder only supports top level string values in payloads.
As part of the workflow setup, you will need to define expected variables in the payload the webhook will receive (described in the "Create custom variables" section of the docs). If these variables are missing in the payload, an error is returned.
- Create a Slack workflow webhook.
- Copy the webhook URL (
https://hooks.slack.com/workflows/....
) and add it as a secret in your repo settings namedSLACK_WEBHOOK_URL
. - Add a step to your GitHub action to send data to your Webhook.
- Configure your Slack workflow to use variables from the incoming payload from the GitHub Action. You can select where you want to post the data and how you want to format it in Slack's workflow builder interface.
Add this Action as a step to your project's GitHub Action Workflow file:
- name: Send GitHub Action trigger data to Slack workflow
id: slack
uses: slackapi/slack-github-action@v1.19.0
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
or
- name: Send custom JSON data to Slack workflow
id: slack
uses: slackapi/slack-github-action@v1.19.0
with:
# This data can be any valid JSON from a previous step in the GitHub Action
payload: |
{
"key": "value",
"foo": "bar"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
or
If the
payload
is provided it will take preference overpayload-file-path
- name: Send custom JSON data to Slack workflow
id: slack
uses: slackapi/slack-github-action@v1.19.0
with:
payload-file-path: "./payload-slack-content.json"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
By creating a new Slack app or using an existing one, this approach allows your GitHub Actions job to post a message in a Slack channel or direct message by utilizing the chat.postMessage API method. Using this approach you can instantly post a message without setting up Slack workflows.
- Create a Slack App for your workspace (alternatively use an existing app you have already created and installed).
- Add the
chat.write
bot scope under OAuth & Permissions. - Install the app to your workspace.
- Copy the app's Bot Token from the OAuth & Permissions page and add it as a secret in your repo settings named
SLACK_BOT_TOKEN
. - Invite the bot user into the channel you wish to post messages to (
/invite @bot_user_name
).
Add this Action as a step to your project's GitHub Action Workflow file:
- name: Post to a Slack channel
id: slack
uses: slackapi/slack-github-action@v1.19.0
with:
# Slack channel id, channel name, or user id to post message.
# See also: https://api.slack.com/methods/chat.postMessage#channels
channel-id: 'CHANNEL_ID'
# For posting a simple plain text message
slack-message: "GitHub build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
Using JSON payload for constructing a message is also available:
- name: Post to a Slack channel
id: slack
uses: slackapi/slack-github-action@v1.19.0
with:
# Slack channel id, channel name, or user id to post message.
# See also: https://api.slack.com/methods/chat.postMessage#channels
channel-id: 'CHANNEL_ID'
# For posting a rich message using Block Kit
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 }}"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
This approach allows your GitHub Actions job to post a message to a Slack channel or direct message by utilizing Incoming Webhooks.
Incoming Webhooks conform to the same rules and functionality as any of Slack's other messaging APIs. You can make your posted messages as simple as a single line of text, or make them really useful with interactive components. To make the message more expressive and useful use Block Kit to build and test visual components.
- Create a Slack App for your workspace (alternatively use an existing app you have already created and installed).
- Add the
incoming-webhook
bot scope under OAuth & Permissions. - Install the app to your workspace (you will select a channel to notify).
- Activate and create a new webhook under Incoming Webhooks.
- Copy the Webhook URL from the Webhook you just generated add it as a secret in your repo settings named
SLACK_WEBHOOK_URL
.
- name: Send custom JSON data to Slack workflow
id: slack
uses: slackapi/slack-github-action@v1.18.0
with:
# For posting a rich message using Block Kit
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 }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
See CONTRIBUTING.
See LICENSE.