├── .dockerignore ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── docs ├── app-icons │ ├── github-action-icon.png │ └── github-icon.png └── images │ ├── bot-user.png │ ├── install-slack-app.png │ ├── slack-app.png │ └── slack-message-example.png └── entrypoint.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | # ignore all files by default 2 | * 3 | # include required files with an exception 4 | !entrypoint.sh 5 | !LICENSE 6 | !README.md -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM curlimages/curl:7.68.0 2 | 3 | LABEL "com.github.actions.name"="Post Slack messages" 4 | LABEL "com.github.actions.description"="Post Slack messages from your own bot" 5 | LABEL "com.github.actions.icon"="hash" 6 | LABEL "com.github.actions.color"="gray-dark" 7 | 8 | LABEL version="1.0.5" 9 | LABEL repository="http://github.com/pullreminders/slack-action" 10 | LABEL homepage="http://github.com/pullreminders/slack-action" 11 | LABEL maintainer="Abi Noda " 12 | 13 | ADD entrypoint.sh /entrypoint.sh 14 | ENTRYPOINT ["/entrypoint.sh"] 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Abi Noda 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Post Slack messages 2 | 3 | This action wraps the Slack [chat.postMessage](https://api.slack.com/methods/chat.postMessage) API method for posting to channels, private groups, and DMs. This action sends messages using [Slack bot tokens](https://api.slack.com/docs/token-types), 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](https://medium.com/slack-developer-blog/the-latest-with-app-tokens-fe878d44130c), and (2) Bots offer a [powerful range of capabilities](https://api.slack.com/bot-users) that can be leveraged to perform more functions. 4 | 5 | ## Usage: 6 | 7 | ```yaml 8 | - name: Notify slack 9 | env: 10 | SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} 11 | uses: pullreminders/slack-action@master 12 | with: 13 | args: '{\"channel\":\"C1234567890\",\"text\":\"Hello world\"}' 14 | ``` 15 | 16 | Here's what the Slack message would look like: 17 | 18 | 19 | 20 | ## Setup 21 | 22 | To use this GitHub Action you'll first need to create a Slack App and install it to your Slack workspace. 23 | 24 | ### Creating a Slack App 25 | 26 | 1. **Create a Slack App**. Go to [Slack's developer site](https://api.slack.com/apps) 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](docs/images/slack-app.png)). 27 | 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](docs/images/bot-user.png)). 28 | 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](docs/app-icons). 29 | 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](docs/images/install-slack-app.png)). 30 | 31 | ## Using the action 32 | 33 | 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-`. 34 | 35 | ### Posting messages 36 | 37 | Slack's [chat.postMessage](https://api.slack.com/methods/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: 38 | 39 | ```yaml 40 | - name: Notify slack 41 | env: 42 | SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} 43 | uses: pullreminders/slack-action@master 44 | with: 45 | args: '{\"channel\":\"C1234567890\",\"text\":\"Hello world\"}' 46 | ``` 47 | 48 | Please note that if you are using the visual editor you should not escape quotes because GitHub will automatically escape them for you. 49 | 50 | #### Channel IDs 51 | 52 | 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. 53 | 54 | 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. 55 | 56 | ``` 57 | https://myworkspace.slack.com/messages/CHANNEL_ID/ 58 | ``` 59 | 60 | 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](https://api.slack.com/methods/users.conversations) endpoint. Get user IDs for direct messages using Slack's [users.lookupByEmail](https://api.slack.com/methods/users.lookupByEmail) endpoint 61 | 62 | If the channel is private, you'll need to install the App in that channel. 63 | 64 | #### Formatting messages 65 | 66 | Please refer to [Slack's documentation](https://api.slack.com/docs/messages) on message formatting. They also have a [message builder](https://api.slack.com/docs/messages/builder) that's great for playing around and previewing messages. Your messages can contain attachments, markdown, buttons, and more. 67 | 68 | ## License 69 | 70 | The Dockerfile and associated scripts and documentation in this project are released under the [MIT License](LICENSE). 71 | -------------------------------------------------------------------------------- /docs/app-icons/github-action-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abinoda/slack-action/a5a262c896a1cc80dcbae59ba95513e2dfb21439/docs/app-icons/github-action-icon.png -------------------------------------------------------------------------------- /docs/app-icons/github-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abinoda/slack-action/a5a262c896a1cc80dcbae59ba95513e2dfb21439/docs/app-icons/github-icon.png -------------------------------------------------------------------------------- /docs/images/bot-user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abinoda/slack-action/a5a262c896a1cc80dcbae59ba95513e2dfb21439/docs/images/bot-user.png -------------------------------------------------------------------------------- /docs/images/install-slack-app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abinoda/slack-action/a5a262c896a1cc80dcbae59ba95513e2dfb21439/docs/images/install-slack-app.png -------------------------------------------------------------------------------- /docs/images/slack-app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abinoda/slack-action/a5a262c896a1cc80dcbae59ba95513e2dfb21439/docs/images/slack-app.png -------------------------------------------------------------------------------- /docs/images/slack-message-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abinoda/slack-action/a5a262c896a1cc80dcbae59ba95513e2dfb21439/docs/images/slack-message-example.png -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -eu 3 | 4 | if test -z "$SLACK_BOT_TOKEN"; then 5 | echo "Set the SLACK_BOT_TOKEN secret." 6 | exit 1 7 | fi 8 | 9 | curl -X POST \ 10 | -H "Content-type: application/json" \ 11 | -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ 12 | -d "$*" \ 13 | https://slack.com/api/chat.postMessage --------------------------------------------------------------------------------