GithubHelp home page GithubHelp logo

slack-action's Introduction

Post Slack messages

This action wraps the Slack chat.postMessage API method for posting to channels, private groups, and DMs. This action sends messages using Slack bot tokens, which have two main advantages compared to user tokens and incoming webhooks: (1) Bots can't be disabled inadvertently when a Slack user is disabled or removed. Slack has written about this in a recent announcement, and (2) Bots offer a powerful range of capabilities that can be leveraged to perform more functions.

Usage:

- name: Notify slack
  env:
    SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
  uses: pullreminders/slack-action@master
  with:
    args: '{\"channel\":\"C1234567890\",\"text\":\"Hello world\"}'

Here's what the Slack message would look like:

Setup

To use this GitHub Action you'll first need to create a Slack App and install it to your Slack workspace.

Creating a Slack App

  1. Create a Slack App. Go to Slack's developer site then click "Create an app". Name the app "GitHub Action" (you can change this later) and make sure your team's Slack workspace is selected under "Development Slack Workspace" (see screenshot).
  2. Add a Bot user. Browse to the "Bot users" page listed in the sidebar. Name your bot "GitHub Action" (you can change this later) and leave the other default settings as-is (see screenshot).
  3. Set an icon for your bot. Browse to the "Basic information" page listed in the sidebar. Scroll down to the section titled "Display information" to set an icon. Feel free to use one of the icons in this repository.
  4. Install your app to your workspace. At the top of the "Basic information" page you can find a section titled "Install your app to your workspace". Click on it, then use the button to complete the installation (see screenshot).

Using the action

To use this GitHub Action, you'll need to set a SLACK_BOT_TOKEN secret on GitHub. To get your Slack bot token, browse to the "OAuth & Permissions" page listed in Slack and copy the "Bot User OAuth Access Token" beginning in xoxb-.

Posting messages

Slack's chat.postMessage method accepts a JSON payload containing options โ€” this JSON payload should be supplied as the argument in your GitHub Action. At a bare minimum, your payload must include a channel ID and the message. Here's what a basic message might look like:

- name: Notify slack
  env:
    SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
  uses: pullreminders/slack-action@master
  with:
    args: '{\"channel\":\"C1234567890\",\"text\":\"Hello world\"}'

Please note that if you are using the visual editor you should not escape quotes because GitHub will automatically escape them for you.

Channel IDs

A "channel ID" can be the ID of a channel, private group, or user you would like to post a message to. Your bot can message any user in your Slack workspace but needs to be invited into channels and private groups before it can post to them.

If you open Slack in your web browser, you can find channel IDs at the end of the URL when viewing channels and private groups. Note that this doesn't work for direct messages.

https://myworkspace.slack.com/messages/CHANNEL_ID/

You can also find channel IDs using the Slack API. Get a list of channels that your bot is a member of via Slack's users.conversations endpoint. Get user IDs for direct messages using Slack's users.lookupByEmail endpoint

If the channel is private, you'll need to install the App in that channel.

Formatting messages

Please refer to Slack's documentation on message formatting. They also have a message builder that's great for playing around and previewing messages. Your messages can contain attachments, markdown, buttons, and more.

License

The Dockerfile and associated scripts and documentation in this project are released under the MIT License.

slack-action's People

Contributors

abinoda avatar baijunyao avatar crisfole avatar legion2 avatar robpc avatar tlfbrito avatar twslade avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

slack-action's Issues

Receiving error when sending basic message - was working

Hello, I've been using this. Thanks for creating btw. As of a couple days ago I had stopped receiving the message. All green checkmarks shown, no errors shown. Checking the logs shows this message and I'm not sure why. I've created an action and pasted in the example shown on documentation for this action so is there something I can do to understand what's causing this?

{"ok":false,"error":"json_not_object","warning":"missing_charset","response_metadata":{"warnings":["missing_charset"]}}

This is the basic action getting an error.

on: push
name: Slack Notification Demo
jobs:
    slackNotification:
      name: Slack Notification Demo
      runs-on: ubuntu-latest
      steps:
      - name: Notify slack
        env:
            SLACK_BOT_TOKEN: ${{ secrets.SLACKBOT_TOKEN }}
        uses: pullreminders/slack-action@master
        with:
            args: '{\"channel\":\"GD0RL3545\",\"text\":\"Hello world\"}'

Correct OAuth Bot Token Scopes to use for Slack App

As you can see from the screenshot, there is no longer a section for "Bot Users." Instead, it is required to create OAuth Bot Token Scopes prior to adding the app to the workspace.

I've been working through various scope permissions, but it's been mostly trial and error, and I'd like more guidance on what I should be using.

Using Env variables on the message

Hey @abinoda thank you creating this action! I wanted to know if you have successfully used it with env variables on the message like the $GITHUB_ACTOR and $GITHUB_REPOSITORY that github provides to create dynamic messages?

e.g. {\"channel\":\"123243434\",\"text\":\"$GITHUB_ACTOR just pushed to $GITHUB_REPOSITORY\"}

how do I set up Github mention to show on slack?

Hello,
I would like github notification to be on slack but I am experiencing difficulty.
Currently, our github account is an organization with 5 memebers.
Github account's setting has 2 Github apps installed, which are "Pull Panda" and "Slack"
Slack has "Pull Reminder" app installed and I checked all settings and configuration to be in order.
But I am not receiving any message when I put @ mention in our github issues.

Is there any totorial that I could walk through how to set up Github-Pull Reminder-Slack to show Github mention to show on Slack ?

Thank you for your help.

Add use case examples to README

It'd be nice to add a full example workflow, e.g. posting messages about opened and merged pull requests to a Slack channel.

GITHUB_TOKEN permissions used by this action

At https://github.com/step-security/secure-workflows we are building a knowledge-base (KB) of GITHUB_TOKEN permissions needed by different GitHub Actions. When developers try to set minimum token permissions for their workflows, they can use this knowledge-base instead of trying to research permissions needed by each GitHub Action they use.

Below you can see the KB of your GITHUB Action.

name: Post Slack messages # pullreminders/slack-action
# GITHUB_TOKEN not used

If you think this information is not accurate, or if in the future your GitHub Action starts using a different set of permissions, please create an issue at https://github.com/step-security/secure-workflows/issues to let us know.

This issue is automatically created by our analysis bot, feel free to close after reading :)

References:

GitHub asks users to define workflow permissions, see https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/ and https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token for securing GitHub workflows against supply-chain attacks.

Setting minimum token permissions is also checked for by Open Source Security Foundation (OpenSSF) Scorecards. Scorecards recommend using https://github.com/step-security/secure-workflows so developers can fix this issue in an easier manner.

Just use VM, not docker

This line would spend time a lot.

https://github.com/pullreminders/slack-action/blob/da2ae3e1a32c9e629f5f6fa59a95f846366e85ff/Dockerfile#L13

I tested this action in my repository, and just building an docker image consumed 40s.

Screenshot from 2019-09-30 21-24-52

Generally speaking, pulling pre-built image from docker hub is a better option compared to buliding it every time the action is called.

However, I suggest not to use docker just for using curl. According to https://help.github.com/en/articles/software-in-virtual-environments-for-github-actions#ubuntu-1804-lts, VMs already have curl preinstalled. So directly executing entrypoint.sh would be the best.

Shell problem in entrypoint file (?)

Followed the README, and it doesn't work for me, here's the problem:

image

Link to failing job: https://github.com/chapati23/hello-github-actions/pull/4/checks#step:3:7

My job code is as follows:

jobs:
  slack-notifier:
    runs-on: ubuntu-latest
    steps:
      - name: Notify slack
        env:
          SLACK_BOT_TOKEN: ${{secrets.SLACK_BOT_TOKEN}}
        uses: pullreminders/slack-action@master
        with:
          args: '{\"channel\":\"D790ZUYJH\",\"text\":\"Hello world\"}'

Not 100% sure but this looks like some shell/bash syntax issue.

Any idea what's going wrong here?

Step won't run if previous step failed

This is not related to how this action works, it's more related to how GH Actions work, in general.

I was testing sending a message after running unit tests and was surprised that I never got a slack notification for it, when looking at the debug output I saw this

##[debug]Evaluating: secrets.SLACK_BOT_TOKEN
##[debug]Evaluating Index:
##[debug]..Evaluating secrets:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'SLACK_BOT_TOKEN'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Evaluating condition for step: 'Notify slack'
##[debug]Parsing expression: <success()>
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> false
##[debug]Result: false

Meaning the step didn't run, because the previous one had failed. I worked around this issue by adding if: always() at the top of the step and it worked just fine.

This got me wondering, should this be stated in the README?

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.