GithubHelp home page GithubHelp logo

00mjk / slack-messaging-action Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wearerequired/slack-messaging-action

0.0 0.0 0.0 363 KB

๐Ÿ’Œ A GitHub Action for sending (and updating) messages of any layout and formatting from GitHub Actions to Slack.

License: MIT License

JavaScript 100.00%

slack-messaging-action's Introduction

Slack Messaging Action

A GitHub Action for sending (and updating) messages of any layout and formatting from GitHub Actions to Slack. Inspired by Slack Notify Build.

A Slack bot token is required to use this action, and the associated app must be granted permission to post in the channel, private group or DM you specify.

Usage

uses: wearerequired/slack-messaging-action@v1
with:
  bot_token: ${{ secrets.SLACK_BOT_TOKEN }}
  channel: deployments
  payload: >-
    {
        "icon_emoji": ":rocket:",
        "username": "Deployer",
        "attachments": [
            {
                "author_name": "${{ github.event.sender.login }}",
                "author_link": "${{ github.event.sender.html_url }}",
                "author_icon": "${{ github.event.sender.avatar_url }}",
                "color": "good",
                "fallback": "Deployment finished.",
                "pretext": "Deployment finished.",
                "fields": [
                    {
                      "title": "Revision",
                      "value": "<https://github.com/${{ github.repository }}/commit/${{ github.sha }}|${{ github.sha }}@${{ github.ref }}>",
                      "short": true
                    }
                ],
                "footer": "<https://github.com/${{ github.repository }}|${{ github.repository }}>",
            }
        ]
    }

In payload you have to provide your own rich message layout which will be sent as is to Slack.

Updating an existing message

If you prefer to update a single message instead of posting multiple messages, you can pass a message_id to future steps.

Note: You must assign a step id to the first Slack notification step in order to reference it for future steps:

- name: Notify Slack about deployment start
  if: success()
  id: slack # IMPORTANT: Reference this step ID value in future Slack steps.
  uses: wearerequired/slack-messaging-action@v1
  with:
    bot_token: ${{ secrets.SLACK_BOT_TOKEN }}
    channel: deployments
    payload: >-
      {
          "icon_emoji": ":rocket:",
          "username": "Deployer",
          "text": "Deployment started."
      }

- name: Deployment

- name: Notify Slack about deployment success
  if: success() # You can use the conditional checks to determine which notification to send.
  uses: wearerequired/slack-messaging-action@v1
  with:
    bot_token: ${{ secrets.SLACK_BOT_TOKEN }}
    message_id: ${{ steps.slack.outputs.message_id }} # Updates existing message from the first step.
    channel: deployments
    payload: >-
      {
          "icon_emoji": ":rocket:",
          "username": "Deployer",
          "text": "Deployment finished."
      }

- name: Notify Slack about deployment fail
  if: failure() # You can use the conditional checks to determine which notification to send.
  uses: wearerequired/slack-messaging-action@v1
  with:
    bot_token: ${{ secrets.SLACK_BOT_TOKEN }}
    message_id: ${{ steps.slack.outputs.message_id }} # Updates existing message from the first step.
    channel: deployments
    payload: >-
      {
          "icon_emoji": ":boom:",
          "username": "Deployer",
          "text": "Deployment failed."
      }

Inputs

bot_token

A bot token associated with a Slack app. Required

Note: The following bot token scopes are required: chat:write, chat:write.customize, chat:write.public, channels:read, and groups:read.

channel

The name of the channel to post the message to. Required if no channel_id is provided.

Note: If your workspace has many channels, supplying only a channel may cause rate limiting issues with this GitHub Action. Consider supplying a channel_id instead.

channel_id

The ID of the channel to post the message to. Required if no channel is provided, or if you need to send to a DM.

payload

The JSON payload of a message to send. Required

Note: channel and ts are set to the values of the respective inputs.

message_id

The ID of a previous Slack message to update instead of posting a new message. Typically passed using the steps context:

message_id: ${{ steps.<your_first_slack_step_id>.outputs.message_id }}

Outputs

message_id

Returns the unique message ID, which is a timestamp which can be passed to future Slack API calls as ts.

License

The scripts and documentation in this project are released under the MIT license.


a required open source product - let's get in touch

slack-messaging-action's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar ocean90 avatar szepeviktor avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.