MCPcopy Index your code
hub / github.com/archive/github-actions-slack

github.com/archive/github-actions-slack @v3.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v3.1.0 ↗ · + Follow
46 symbols 120 edges 22 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Github Action for sending message (and reactions/threads/update/blocks/file uploads) to Slack

— With support for Slack's optional arguments

This Action allows you to send messages (and reactions/threads/update/blocks/file uploads) to Slack from your Github Actions. Supports Slack's required arguments as well as all the optional once. It's JavaScript-based and thus fast to run.

The goal is to have zero npm production dependencies except @actions/core which is required for an action to work.

Slack result

This action is just an HTTPS call to Slack API, so you can easily build this by yourself, or use this action or any one of the hundred other Slack actions available.

Requirements

  1. Slack Workspace and Channel(s)
  2. A Slack App and Bot - the App and Bot will be used to send messages to your channel. It sounds hard, but it's not :)
  3. A Github Action - the place where you wants to send Slack messages
  4. Github Secret - the Slack Bot auth token, used when posting messages to Slack API

Important

With the latest changes to Slack API, please use channel id instead of channel name. E.g. use CPPUV5KU0 instead of test (You can find the ID in the API calls or https://stackoverflow.com/questions/40940327/what-is-the-simplest-way-to-find-a-slack-team-id-and-a-channel-id)

Setup

This action supports:

    1. Send messages

    1. Send thread response to message

    1. Send reaction on sent messages

    1. Upload files

1. Send messages to Slack

Required: Github Repository Secret:

  • SLACK_BOT_USER_OAUTH_ACCESS_TOKEN - This is the Slack App token, the credentials for allowing you to send messages from github to Slack

Required: Github Action Parameters:

  • slack-bot-user-oauth-access-token - SLACK_BOT_USER_OAUTH_ACCESS_TOKEN secret

  • slack-channel - The channel/channels where you want the message (comma separated)

  • slack-text - The text of the message (or use slack-optional-blocks)

Optional: Github Action Parameters:

All the optional parameters that Slack supports, can be sent via the slack-optional-xxx parameter.

Slack parameter name Yaml parameter name
icon_emoji slack-optional-icon_emoji
link_names slack-optional-link_names

and so forth.

Please see Slack API documentation for all available optional parameters: https://api.slack.com/methods/chat.postMessage

Result / return value

  • slack-result (.outputs.slack-result) - Contains the result of the sent message. This can be used for following steps like sending a reaction

Sample slack-result:

{
  "statusCode": 200,
  "statusMessage": "OK",
  "ok": true,
  "result": "<deprecated - same as response but as string>",
  "response": {
    "ok": true,
    "channel": "XXXX",
    "ts": "1612623790.009600",
    "message": {
      "type": "message",
      "subtype": "bot_message",
      "text": "Lipsum",
      "ts": "1612623790.009600",
      "username": "Lipsum",
      "bot_id": "XXXX"
    }
  }
}

If you want to output or debug the result, add:

      - name: Send Slack Message Result
        run: echo "${{ steps.send-message.outputs.slack-result }}"

Sample Action file with Slack Channel and Text

.github/workflows/2-slack-notification.yml

This will send a Slack message every time someone push, creates pull request or create an issue

name: slack-notification

on: [push, pull_request, issues]

jobs:
  slack-notifications:
    runs-on: ubuntu-24.04
    name: Sends a message to Slack when a push, a pull request or an issue is made
    steps:
      - name: Send message to Slack API
        uses: archive/github-actions-slack@v2.0.0
        id: notify
        with:
          slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
          slack-channel: CPPUV5KU0
          slack-text: Hello! Event "${{ github.event_name }}" in "${{ github.repository }}" 🤓
      - name: Result from "Send Message"
        run: echo "The result was ${{ steps.notify.outputs.slack-result }}"

Slack result

Sample Action file with Slack optional parameters

.github/workflows/2-slack-notification.yml

name: slack-notification-with-optional-parameters

on: [push, pull_request, issues]

jobs:
  slack-notification-with-optional-parameters:
    runs-on: ubuntu-24.04
    name: Sends a message to Slack when a push, a pull request or an issue is made
    steps:
      - name: Send message to Slack API
        uses: archive/github-actions-slack@v2.0.0
        id: notify
        with:
          slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
          slack-channel: CPPUV5KU0 #USE CHANNEL ID, NOT CHANNEL NAME, SINCE ID IS USED IN NEW SLACK API's
          slack-text: Hello! Something is burning! Or not...
          slack-optional-icon_emoji: ":fire:"
      - name: Result from "Send Message"
        run: echo "The result was ${{ steps.notify.outputs.slack-result }}"

Slack result

2. Send thread response to message to Slack

To send a thread response you have the same setup as for sending a message, but you add some extra optional parameters:

  • slack-optional-thread_ts - The timestamp of the message you want to reply/send thread to. You can find the timestamp in the response payload after sending a message

  • slack-optional-reply_broadcast - To broadcast thread reply in channel

Sample Action file

.github/workflows/4-slack-thread.yml

See Send Thread Message part below:

name: slack-thread

on: [push, issues]

jobs:
  slack-thread:
    runs-on: ubuntu-24.04
    name: Sends a message to Slack when a push, a pull request or an issue is made

    steps:
      - name: Send Slack Message
        uses: archive/github-actions-slack@master
        id: send-message

        with:
          slack-function: send-message
          slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
          slack-channel: CPPUV5KU0
          slack-text: This is a message

      - name: Send "Slack Message" Result
        run: echo "Data - ${{ steps.send-message.outputs.slack-result }}"

      - name: Some step in between
        run: echo "..."

      - name: Send Thread Message
        uses: archive/github-actions-slack@master
        with:
          slack-function: send-message
          slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
          slack-channel: ${{ fromJson(steps.send-message.outputs.slack-result).response.channel }}
          slack-text: This is a thread reply
          slack-optional-thread_ts: ${{ fromJson(steps.send-message.outputs.slack-result).response.message.ts }}
          #slack-optional-reply_broadcast: true # To broadcast thread reply in channel

      - name: Send "Send Thread Message" Result
        run: echo "Data - ${{ steps.send-message.outputs.slack-result }}"

Slack result

3. Send reaction on sent messages to Slack

Required: Github Repository Secret:

  • SLACK_BOT_USER_OAUTH_ACCESS_TOKEN - This is the Slack App token, the credentials for allowing you to send messages from github to Slack

Required: Github Action Parameters:

  • slack-bot-user-oauth-access-token - SLACK_BOT_USER_OAUTH_ACCESS_TOKEN secret

  • slack-channel - The channel where you want the message. You can find the channel id in the response payload after sending a message

  • slack-emoji-name - The name of the emoji to send (e.g. "fire"/"thumbsup")

  • slack-message-timestamp - The unique ts/timestamp of the message you want to react to. You can find the timestamp in the response payload after sending a message

Result / return value

  • slack-result (.outputs.slack-result) - Contains the result of the sent reaction

Sample Action file with Slack Channel and Text

.github/workflows/3-slack-reaction.yml

This will send a Slack message every time someone push, creates pull request or create an issue, and then, create a reaction to it

name: slack-reaction

on: [push, issues]

jobs:
  slack-reaction:
    runs-on: ubuntu-24.04
    name: Sends a message to Slack when a push, a pull request or an issue is made

    steps:
      - name: Send Slack Message
        uses: archive/github-actions-slack@v2.0.0
        id: send-message

        with:
          slack-function: send-message
          slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
          slack-channel: CPPUV5KU0
          slack-text: Time to react...

      - name: Send Slack Message Result
        run: echo "Data - ${{ steps.send-message.outputs.slack-result }}"

      - name: Some step in between
        run: echo "..."

      - name: Send Slack Reaction To Message
        uses: archive/github-actions-slack@v2.0.0
        with:
          slack-function: send-reaction
          slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
          slack-channel: ${{ fromJson(steps.send-message.outputs.slack-result).response.channel }}
          slack-emoji-name: thumbsup
          slack-message-timestamp: ${{ fromJson(steps.send-message.outputs.slack-result).response.message.ts }}

      - name: Send Slack Reaction To Message Result
        run: echo "Data - ${{ steps.send-message.outputs.slack-result }}"

Slack result

4. Update message

Similar to Add Reaction, but with text instead.

Please see .github/workflows/5-slack-update-message.yml

5. Using blocks

With blocks you can create more rich and complex messages / message layouts: https://api.slack.com/messaging/composing/layouts

image

For some examples, please see:

6. Upload files

Upload files to a Slack channel using the upload-file function.

Required: Github Action Parameters:

  • slack-bot-user-oauth-access-token - SLACK_BOT_USER_OAUTH_ACCESS_TOKEN secret

  • slack-channel - The channel where you want to upload the file

  • slack-upload-file-path - Path to the file to upload

Optional: Github Action Parameters:

  • slack-upload-filename - Override the filename shown in Slack

  • slack-upload-file-title - Title of the file

  • slack-upload-initial-comment - Initial comment to add alongside the file

Upload security checks:

  • Uploads are limited to https and allowlisted Slack upload hosts only. Currently the upload host must be files.slack.com.

  • Uploads are limited to 10 MB per file.

  • The upload path must point to a file with an allowlisted extension. Current allowlist: .txt, .log, .json, .yaml, .yml, .xml, .pdf, .jpg, .jpeg, .png, .gif, .webp, .bmp, .svg, .tif, .tiff, .doc, .docx, .xls, .xlsx, .ppt, .pptx.

Sample Action file

.github/workflows/15-slack-upload-file.yml

name: slack-upload-file

on: [push]

jobs:
  slack-upload-file:
    runs-on: ubuntu-24.04
    name: Uploads a file to Slack

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Upload File to Slack
        uses: archive/github-actions-slack@v2.0.0
        id: upload-file
        with:
          slack-function: upload-file
          slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
          slack-channel: CPPUV5KU0
          slack-upload-file-path: path/to/file.png
          slack-upload-file-title: My File
          slack-upload-initial-comment: Here is the file!
      - name: Result from "Upload File"
        run: echo "${{ steps.upload-file.outputs.slack-result }}"

Slack result

How to setup your first Github Action in your repository that will call this Action

1. Create a Slack bot

Follow this guide on how to create a Slack App and Bot for your workspace:

  • https://slack.com/intl/en-se/help/articles/115005265703-create-a-bot-for-your-workspace

You should:

  1. Create a new Slack App, https://api.slack.com/apps?new_app=1
  2. Go to "Basic Information" > "Display Information" > "App icon & Preview" and add avatar for you App. This will be shown in Slack when you receive messages
  3. Go to "Bot User" > "Add" and add a bot user to your Slack App
  4. Go to "Install App" > "Install App to Workspace" to install your Slack App into your Slack workspace
  5. Done

2. Save Bot Access Token on Github

To be able to send messages to slack, the Action needs the Auth Token for the Slack App. Since the Auth Token is sensitive information, you should NOT place it in the yaml file of the Ac

Core symbols most depended-on inside this repo

buildMessage
called by 7
src/message/build-message.js
hasErrors
called by 5
src/integration/slack-api.js
buildErrorMessage
called by 5
src/integration/slack-api.js
testSendMessage
called by 4
integration-test/end-to-end.js
post
called by 4
src/integration/slack-api-post.js
postMessage
called by 4
src/message/index.js
apiPostMessage
called by 3
src/integration/slack-api.js
jsonPretty
called by 3
src/message/index.js

Shape

Function 46

Languages

TypeScript100%

Modules by API surface

src/context.js9 symbols
src/integration/slack-api.js7 symbols
src/integration/slack-api-post.js5 symbols
integration-test/end-to-end.js4 symbols
src/message/index.test.js3 symbols
src/util/escaper.js2 symbols
src/upload-file/index.js2 symbols
src/update-message/index.js2 symbols
src/reaction/index.js2 symbols
src/message/index.js2 symbols
src/invoke.js2 symbols
src/util/optional.js1 symbols

For agents

$ claude mcp add github-actions-slack \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact