|
1 | | -# Github Action for sending message (and reactions/threads/update/blocks) to Slack |
| 1 | +# Github Action for sending message (and reactions/threads/update/blocks/file uploads) to Slack |
2 | 2 |
|
3 | 3 | — With support for Slack's optional arguments |
4 | 4 |
|
5 | 5 |  |
6 | 6 |  |
7 | 7 |
|
8 | | -This Action allows you to send messages (and reactions/threads/update/blocks) 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. |
| 8 | +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. |
9 | 9 |
|
10 | | -The goal is to have zero npm/yarn dependencies except `@actions/core` which is required for an action to work. |
| 10 | +The goal is to have zero npm production dependencies except `@actions/core` which is required for an action to work. |
11 | 11 |
|
12 | 12 |  |
13 | 13 |
|
@@ -37,6 +37,9 @@ This action supports: |
37 | 37 | - 3. Send reaction on sent messages<br> |
38 | 38 | <img src="./images/reaction.png" width="300"> |
39 | 39 |
|
| 40 | +- 4. Upload files<br> |
| 41 | + <img src="./images/upload.png" width="300"> |
| 42 | + |
40 | 43 | ## 1. Send messages to Slack |
41 | 44 |
|
42 | 45 | **Required: Github Repository Secret:** |
@@ -301,6 +304,68 @@ For some examples, please see: |
301 | 304 | - [.github/workflows/11-slack-message-blocks.yml](.github/workflows/11-slack-message-blocks.yml) |
302 | 305 | - [.github/workflows/12-slack-message-blocks-update.yml](.github/workflows/12-slack-message-blocks-update.yml) |
303 | 306 |
|
| 307 | +## 6. Upload files |
| 308 | + |
| 309 | +Upload files to a Slack channel using the `upload-file` function. |
| 310 | + |
| 311 | +**Required: Github Action Parameters:** |
| 312 | + |
| 313 | +- `slack-bot-user-oauth-access-token` - `SLACK_BOT_USER_OAUTH_ACCESS_TOKEN` secret |
| 314 | + |
| 315 | +- `slack-channel` - The channel where you want to upload the file |
| 316 | + |
| 317 | +- `slack-upload-file-path` - Path to the file to upload |
| 318 | + |
| 319 | +**Optional: Github Action Parameters:** |
| 320 | + |
| 321 | +- `slack-upload-filename` - Override the filename shown in Slack |
| 322 | + |
| 323 | +- `slack-upload-file-title` - Title of the file |
| 324 | + |
| 325 | +- `slack-upload-initial-comment` - Initial comment to add alongside the file |
| 326 | + |
| 327 | +**Upload security checks:** |
| 328 | + |
| 329 | +- Uploads are limited to `https` and allowlisted Slack upload hosts only. Currently the upload host must be `files.slack.com`. |
| 330 | + |
| 331 | +- Uploads are limited to 10 MB per file. |
| 332 | + |
| 333 | +- 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`. |
| 334 | + |
| 335 | +### Sample Action file |
| 336 | + |
| 337 | +[.github/workflows/15-slack-upload-file.yml](.github/workflows/15-slack-upload-file.yml) |
| 338 | + |
| 339 | +``` |
| 340 | +name: slack-upload-file |
| 341 | +
|
| 342 | +on: [push] |
| 343 | +
|
| 344 | +jobs: |
| 345 | + slack-upload-file: |
| 346 | + runs-on: ubuntu-24.04 |
| 347 | + name: Uploads a file to Slack |
| 348 | +
|
| 349 | + steps: |
| 350 | + - name: Checkout |
| 351 | + uses: actions/checkout@v4 |
| 352 | +
|
| 353 | + - name: Upload File to Slack |
| 354 | + uses: archive/github-actions-slack@v2.0.0 |
| 355 | + id: upload-file |
| 356 | + with: |
| 357 | + slack-function: upload-file |
| 358 | + slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }} |
| 359 | + slack-channel: CPPUV5KU0 |
| 360 | + slack-upload-file-path: path/to/file.png |
| 361 | + slack-upload-file-title: My File |
| 362 | + slack-upload-initial-comment: Here is the file! |
| 363 | + - name: Result from "Upload File" |
| 364 | + run: echo "${{ steps.upload-file.outputs.slack-result }}" |
| 365 | +``` |
| 366 | + |
| 367 | + |
| 368 | + |
304 | 369 | ## How to setup your first Github Action in your repository that will call this Action |
305 | 370 |
|
306 | 371 | ### 1. Create a Slack bot |
@@ -415,12 +480,12 @@ The source code moved from CommonJS (`require`) to ES Modules (`import`/`export` |
415 | 480 |
|
416 | 481 | ## Development and testing |
417 | 482 |
|
418 | | -See package.json for `yarn lint`, `yarn test`, etc. |
| 483 | +See package.json for commands. |
419 | 484 |
|
420 | 485 | Remember to create the dist with `npm run build`. |
421 | 486 |
|
422 | 487 | To run local integration test (from this repository): |
423 | 488 |
|
424 | 489 | ``` |
425 | | -env BOT_USER_OAUTH_ACCESS_TOKEN=<YOUR TOKEN> CHANNEL=<YOUR CHANNEL> node integration-test/end-to-end.js |
| 490 | +env BOT_USER_OAUTH_ACCESS_TOKEN=<YOUR TOKEN> CHANNEL=<YOUR CHANNEL ID> node integration-test/end-to-end.js |
426 | 491 | ``` |
0 commit comments