Skip to content

Commit 7404d4a

Browse files
committed
update docs with slack access token setup and secrets file changes
1 parent 4f34457 commit 7404d4a

File tree

3 files changed

+51
-34
lines changed

3 files changed

+51
-34
lines changed

README.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,23 @@ Run the `_build/default/src/monorobot.exe` binary. The following commands are su
2222

2323
- `run`: Launch the HTTP server
2424
- `check_gh <GH_PAYLOAD>`: read a Github notification from a file and display the actions that will be taken (used for testing)
25-
- `check_slack <SLACK_PAYLOAD> <SLACK_WEBHOOK>`: read a Slack notification from a file and send it to a webhook (used for testing)
25+
- `check_slack <SLACK_PAYLOAD>`: read a Slack notification from a file and send it to a channel (used for testing)
26+
27+
## Getting Started
28+
29+
1. Commit a **repository configuration** file to the root of your target repository.
30+
2. Place a **secrets** file locally on the server.
31+
3. Configure GitHub
32+
1. If targeting a private repository, set up a [personal access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) with `repo` scope and store it in the `gh_token` field of the secrets file.
33+
2. [Create a webhook](https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/creating-webhooks#setting-up-a-webhook) for the repository you are targeting. Set the *Payload URL* to be `<server_domain>/github`.
34+
3. You can optionally [secure the webhook](https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/securing-your-webhooks) with a token, and store it in the `gh_hook_token` field of the secrets file.
35+
4. Configure Slack
36+
1. [Create a Slack app](https://api.slack.com/apps?new_app=1).
37+
2. Click "Install to Workspace", and when prompted to grant permissions to your workspace, click "Allow".
38+
3. Set up notifications with one of the following methods:
39+
- **Web API (recommended):** To use Slack's [Web API](https://api.slack.com/web), click on "OAuth & Permissions" in your app dashboard's sidebar. Give your bot a *Bot Token Scope* of `chat:write`. Copy the generated OAuth access token (`xoxb-XXXX`) to the `slack_access_token` field of your secrets file. This token is used by the bot to authenticate to the workspace, and remains valid until the token is revoked or the app is uninstalled.
40+
- **Incoming Webhooks:** To use [incoming webhooks](https://api.slack.com/messaging/webhooks), enable them in your app dashboard and create one for each channel you want to notify. Store them in the `slack_hooks` field of your secrets file. If you decide to notify additional channels later, you will need to update the secrets file with the new webhooks and restart the server.
41+
2642

2743
### Documentation
2844

documentation/config_docs.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ A **label rule** specifies whether or not a Slack channel should be notified, ba
8686
|-|-|-|-|
8787
| `match` | if notifications have any label in this list, they should be routed to the channel | Yes | all labels matched if no list provided |
8888
| `ignore` | if notifications have any label in this list, they shouldn't be routed to the channel (even if they have any `match` labels) | Yes | - |
89-
| `channel` | channel to use as webhook if the rule is matched | No | - |
89+
| `channel` | channel to notify if the rule is matched | No | - |
9090

9191
## Prefix Options
9292

@@ -125,7 +125,7 @@ A **prefix rule** specifies whether or not a Slack channel should be notified, b
125125
|-|-|-|-|
126126
| `match` | if commit files have any prefix in this list, they should be routed to the channel | Yes | all prefixes matched if no list provided |
127127
| `ignore` | if commit files have any prefix in this list, they shouldn't be routed to the channel (even if they have any `match` prefixes) | Yes | - |
128-
| `channel` | channel to use as webhook if the rule is matched | No | - |
128+
| `channel` | channel to notify if the rule is matched | No | - |
129129

130130
## Status Options
131131

documentation/secret_docs.md

+32-31
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,19 @@ A secrets file stores sensitive information. Unlike the repository configuration
88

99
```json
1010
{
11-
"slack_hooks": [
12-
{
13-
"url": "https://slack_webhook_url",
14-
"channel": "default"
15-
},
16-
{
17-
"url": "https://slack_webhook_url",
18-
"channel": "aa"
19-
},
20-
{
21-
"url": "https://slack_webhook_url",
22-
"channel": "backend"
23-
},
24-
{
25-
"url": "https://slack_webhook_url",
26-
"channel": "all-push-events"
27-
},
28-
{
29-
"url": "https://slack_webhook_url",
30-
"channel": "frontend-bot"
31-
},
32-
{
33-
"url": "https://slack_webhook_url",
34-
"channel": "aa-git"
35-
},
36-
{
37-
"url": "https://slack_webhook_url",
38-
"channel": "siren"
39-
}
40-
]
11+
"gh_token": "",
12+
"slack_access_token": ""
4113
}
4214
```
4315

4416
| value | description | optional | default |
4517
|-|-|-|-|
46-
| `slack_hooks` | list of channel names (`channel`) and their corresponding webhook endpoint (`url`) | No | - |
4718
| `gh_token` | specify to grant the bot access to private repositories; omit for public repositories | Yes | - |
4819
| `gh_hook_token` | specify to ensure the bot only receives GitHub notifications from pre-approved repositories | Yes | - |
20+
| `slack_access_token` | slack bot access token to enable message posting to the workspace | Yes | try to use webhooks defined in `slack_hooks` instead |
21+
| `slack_hooks` | list of channel names and their corresponding webhook endpoint | Yes | try to use token defined in `slack_access_token` instead |
22+
23+
Note that either `slack_access_token` or `slack_hooks` must be defined.
4924

5025
## `gh_token`
5126

@@ -54,3 +29,29 @@ Some operations, such as fetching a config file from a private repository, or th
5429
## `gh_hook_token`
5530

5631
Refer [here](https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/securing-your-webhooks) for more information on securing webhooks with a token.
32+
33+
## `slack_access_token`
34+
35+
Refer [here](https://api.slack.com/authentication/oauth-v2) for obtaining an access token via OAuth.
36+
37+
## `slack_hooks`
38+
39+
*Note: If `slack_access_token` is also defined, the bot will authenticate over Slack's Web API and this option will not be used.*
40+
41+
Expected format:
42+
43+
```json
44+
[
45+
{
46+
"channel": "channel name",
47+
"url": "webhook url"
48+
},
49+
{
50+
"channel": "channel name",
51+
"url": "webhook url"
52+
},
53+
...
54+
]
55+
```
56+
57+
Refer [here](https://api.slack.com/messaging/webhooks) for obtaining a webhook for a channel.

0 commit comments

Comments
 (0)