• Stars
    star
    953
  • Rank 47,957 (Top 1.0 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 15 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Send data into Slack using this GitHub Action!

Slack Send GitHub Action

Send data into Slack using this GitHub Action!

Sending Variables

You can send GitHub-specific data related to GitHub Action workflow events using GitHub Contexts and Variables that GitHub Actions provides.

For examples on how to leverage this in your workflows, check out the example workflows we have.

How to Send Data to Slack

This package has three different techniques to send data to Slack:

  1. Send data to Slack's Workflow Builder (requires a paid Slack instance).
  2. Send data via a Slack app to post to a specific channel (use an existing custom app or create a new one).
  3. 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).

Technique 1: Slack Workflow Builder

โ—๏ธ This approach requires a paid Slack plan; it also doesn't support any text formatting

This technique sends data into Slack via a webhook URL created using Slack's Workflow builder. 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.

Setup

  • Create a Slack workflow webhook.
  • Copy the webhook URL (https://hooks.slack.com/workflows/....) and add it as a secret in your repo settings named SLACK_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.

Usage

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/[email protected]
  env:
    SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

or

- name: Send custom JSON data to Slack workflow
  id: slack
  uses: slackapi/[email protected]
  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 over payload-file-path

- name: Send custom JSON data to Slack workflow
  id: slack
  uses: slackapi/[email protected]
  with:
    payload-file-path: "./payload-slack-content.json"
  env:
    SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

Technique 2: Slack App

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.

Setup

  • 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).

Usage

Add this Action as a step to your project's GitHub Action Workflow file:

- name: Post to a Slack channel
  id: slack
  uses: slackapi/[email protected]
  with:
    # Slack channel id, channel name, or user id to post message.
    # See also: https://api.slack.com/methods/chat.postMessage#channels
    # You can pass in multiple channels to post to by providing a comma-delimited list of channel IDs.
    channel-id: 'CHANNEL_ID,ANOTHER_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/[email protected]
  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 }}

Update the message

If you would like to notify the real-time updates on a build status, you can modify the message your build job posted in the subsequent steps. In order to do this, the steps after the first message posting can have update-ts: ${{ steps.slack.outputs.ts }} in their settings. With this, the step updates the already posted channel message instead of posting a new one.

Please note that the message update step does not accept a channel name. Set a channel ID for the steps for the actions that update messages.

- id: slack
  uses: slackapi/[email protected]
  with:
    # The following message update step does not accept a channel name.
    # Setting a channel ID here for consistency is highly recommended.
    channel-id: "CHANNEL_ID"
    payload: |
      {
        "text": "Deployment started (In Progress)",
        "attachments": [
          {
            "pretext": "Deployment started",
            "color": "dbab09",
            "fields": [
              {
                "title": "Status",
                "short": true,
                "value": "In Progress"
              }
            ]
          }
        ]
      }
  env:
    SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN}}
- uses: slackapi/[email protected]
  with:
    # Unlike the step posting a new message, this step does not accept a channel name.
    # Please use a channel ID, not a name here.
    channel-id: "CHANNEL_ID"
    update-ts: ${{ steps.slack.outputs.ts }}
    payload: |
      {
        "text": "Deployment finished (Completed)",
        "attachments": [
          {
            "pretext": "Deployment finished",
            "color": "28a745",
            "fields": [
              {
                "title": "Status",
                "short": true,
                "value": "Completed"
              }
            ]
          }
        ]
      }
  env:
    SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN}}

Technique 3: Slack Incoming Webhook

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.

Setup

  • 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.

Usage

- name: Send custom JSON data to Slack workflow
  id: slack
  uses: slackapi/[email protected]
  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

HTTPS Proxy

If you need to use a proxy to connect with Slack, you can use the HTTPS_PROXY (or https_proxy) environment variable. In this example we use the Slack App technique, but configuring a proxy works the same way for all of them:

- name: Post to a Slack channel via a proxy
  id: slack
  uses: slackapi/[email protected]
  with:
    channel-id: 'CHANNEL_ID'
    slack-message: 'This message was sent through a proxy'
  env:
    SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
    # Set the HTTPS_PROXY environment variable to whatever your policy requires
    HTTPS_PROXY: 'http://proxy.example.org:8080'

Contributing

See CONTRIBUTING.

License

See LICENSE.

More Repositories

1

python-slack-sdk

Slack Developer Kit for Python
Python
3,840
star
2

node-slack-sdk

Slack Developer Kit for Node.js
TypeScript
3,270
star
3

bolt-js

A framework to build Slack apps using JavaScript
TypeScript
2,736
star
4

hubot-slack

Slack Developer Kit for Hubot
CoffeeScript
2,300
star
5

bolt-python

A framework to build Slack apps using Python
Python
1,053
star
6

python-rtmbot

A framework for receiving and interacting with events from Slack's RTM API
Python
680
star
7

java-slack-sdk

Slack Developer Kit (including Bolt for Java) for any JVM language
Java
573
star
8

python-slack-events-api

Slack Events API adapter for Python (Flask required)
Python
342
star
9

Slack-Python-Onboarding-Tutorial

a simple python onboarding bot and tutorial for Slack
Python
251
star
10

slack-api-specs

Open API specifications for platform products by Slack
220
star
11

steno

๐Ÿ“ผ Slack app testing companion - Record and Replay your HTTP requests, both incoming and outgoing
TypeScript
184
star
12

deno-slack-sdk

SDK for building Run on Slack apps using Deno
TypeScript
160
star
13

template-slash-command-and-dialogs

Sample Slack app that uses a Slash Command and interactive message to create helpdesk tickets
JavaScript
141
star
14

node-slack-interactive-messages

Slack Buttons, Menus, and Dialogs made simpler for Node
JavaScript
133
star
15

build-this-bot-workshop

Learn how to build a bot on Slack using Python
127
star
16

reacjilator

A translation bot that translates a message when a user reacted with an emoji ๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ‡ฎ๐Ÿ‡น ๐Ÿ‡น๐Ÿ‡ญ ๐Ÿ‡ซ๐Ÿ‡ท ๐Ÿ‡ฏ๐Ÿ‡ต ๐Ÿ‡ฎ๐Ÿ‡ณ ๐Ÿ‡บ๐Ÿ‡ธ ๐Ÿ‡ง๐Ÿ‡ฌ ๐Ÿ‡น๐Ÿ‡ผ ๐Ÿ‡ฆ๐Ÿ‡ช ๐Ÿ‡ฐ๐Ÿ‡ท
JavaScript
110
star
17

onboarding-example

A demonstration of how to build an onboarding app using Slack's Events API
JavaScript
99
star
18

node-tasks-app

Tasks App is a sample Task Management app built on the Slack Platform.
JavaScript
98
star
19

python-message-menu-example

A tutorial for adding Slack message menus to your Python app
Python
97
star
20

slack-platform-assets

Images, templates, and Sketch files to aid designing and presenting your Slack apps
94
star
21

node-slack-events-api

Slack Events API for Node
JavaScript
93
star
22

sample-message-menus-node

An example Slack app that demonstrates use of message menus
JavaScript
91
star
23

python-dialog-example

An example app to demonstrate Slack dialogs
Python
77
star
24

template-announcement-approvals

Sample Slack app that uses the Events API and interactive message to implement an approvals workflow
JavaScript
74
star
25

Slack-Ruby-Onboarding-Tutorial

An example Slack bot written in Ruby
Ruby
64
star
26

bolt-js-getting-started-app

Getting Started Slack app using โšก๏ธ Bolt for JavaScript
JavaScript
54
star
27

sample-app-unfurls

An example Slack app that demonstrates use of App Unfurls
JavaScript
45
star
28

app-interaction-patterns

A collection of common workflows and interaction patterns for Slack apps.
41
star
29

oauth-tutorial

Slack OAuth setup tutorial using a simple slash command bot
JavaScript
39
star
30

template-triage-bot

Triage Channel Stats w/ Bolt for JS & Shortcuts โšก๏ธ
JavaScript
39
star
31

template-actionable-notifications

Sample Slack app to illustrate how incoming webhooks and interactive messages can be used to build a helpdesk integration
JavaScript
35
star
32

deno-slack-api

Slack API Client for Deno Run on Slack projects
TypeScript
35
star
33

template-terms-of-service

Sample Slack app that uses the Events API and interactive messages to send new users a Terms of Service or welcome message
JavaScript
35
star
34

app-directory-assets

A collection of design assets to help build an app directory submission
34
star
35

template-incident-management

A sample of managing incidents via Slack
TypeScript
34
star
36

template-channel-webhooks

Sample Slack app that uses a Bot to create per-channel webhooks
JavaScript
31
star
37

TalkBot

Building a Twilio-powered Slack bot with Node.js
JavaScript
30
star
38

python-slack-discovery-sdk

This project aims to make using Slack's Discovery APIs easier.
Python
28
star
39

template-channel-naming

Sample Slack app that uses the Events API and interactive message to help enforce channel naming conventions
JavaScript
28
star
40

workflow-powerups

TypeScript
27
star
41

template-action-and-dialog

A sample Slack app "ClipIt", which allows user to clip a message using a message action
JavaScript
27
star
42

sample-message-menus-ruby

An example Slack app in Ruby that demonstrates use of message menus
Ruby
23
star
43

definition-app

A Slack app for storing and accessing company specific phrases
TypeScript
23
star
44

template-account-binding

A sample Slack app that shows you how to bind a Slack user to a user on another system
JavaScript
22
star
45

admin_app_management

Sample application to manage your applications within a Slack organization
TypeScript
20
star
46

pycon-2018

Sample app for Pycon 2018 Slack app workshop
Python
15
star
47

slack-reporting-tool

A Slack app to help administer workspaces by letting team members report offensive messages
TypeScript
15
star
48

deno-slack-runtime

Helper library for running a Run on Slack Deno function
TypeScript
13
star
49

pycon-2019

Pycon 2019 Workshop
Python
12
star
50

deno-slack-hooks

Helper library implementing the contract between the Slack CLI and Slack application SDKs
TypeScript
11
star
51

python-link-button-example

An example app using Slack link buttons and deep links
Python
10
star
52

deno-slack-hub

Connectors used to build coded workflows for Run on Slack apps using Deno
TypeScript
9
star
53

deno-slack-builder

Library for building a Run on Slack Deno project.
TypeScript
9
star
54

bolt-examples-aws-re-invent-2020

A collection of examples to get started with deploying modern โšก๏ธ Slack apps to AWS Lambda and Amazon Lightsail containers
Java
8
star
55

WeAreDevs

WeAreDevelopers Slack Workshop
Python
7
star
56

manifest-schema

Provide JSON schemas that define Slack's manifest.json file
Python
6
star
57

python-slack-hooks

Helper library implementing the contract between the Slack CLI and Bolt for Python
Python
5
star
58

template-message-linking

Sample Slack APP that uses the Events API to link to a conversation happening in one channel to another
JavaScript
5
star
59

bolt-python-getting-started-app

Getting Started Slack app using โšก๏ธ Bolt for Python
Python
4
star
60

easy-peasy-bot-custom-integration

DEPRECATED use https://github.com/slackapi/easy-peasy-bot instead
JavaScript
3
star
61

sample-incident-management

JavaScript
3
star
62

sample-code-index

An index of the most up-to-date sample code created by the Slack team
3
star
63

slack-health-score

A GitHub Action to report software project health score
JavaScript
3
star
64

deno-simple

TypeScript
2
star
65

deno-reverse-string

TypeScript
2
star
66

slack-app-time-off

Time-Off Request sample app for Slack's Next Generation Platform
TypeScript
1
star
67

deno-metadata-event

TypeScript
1
star
68

sunny-picnics

๐ŸŒค๐ŸŒณ๐ŸŒป๐Ÿงบ๐Ÿœ๐Ÿ‘’
1
star
69

deno-budget-calculator

TypeScript
1
star
70

deno-environment-variables

TypeScript
1
star
71

deno-testing-functions

TypeScript
1
star
72

template-ts-clip-message

TypeScript
1
star
73

slack-connect-sample

A sample app which shows off the functionality of the Slack Connect APIs.
JavaScript
1
star
74

deno-slack-protocols

Implements the rules for communication between Slack CLI and any Slack app development SDKs
TypeScript
1
star