Skip to content

Commit 17eb949

Browse files
authored
File upload (#90)
#90
1 parent 9caed1e commit 17eb949

13 files changed

Lines changed: 720 additions & 66 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: test-15-slack-upload-file
2+
3+
on: [push]
4+
5+
permissions: {}
6+
7+
jobs:
8+
slack-action:
9+
#if: ${{ false }}
10+
runs-on: ubuntu-latest
11+
name: Test 15 [ubuntu-latest]
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Upload File to Slack
18+
uses: archive/github-actions-slack@upload-files
19+
id: upload-file
20+
with:
21+
slack-function: upload-file
22+
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
23+
slack-channel: C0ARB84BQC9
24+
slack-upload-file-path: integration-test/one-does-not-simply.jpg
25+
slack-upload-file-title: Test 15 - Image upload
26+
slack-upload-initial-comment: Test 15 - Uploading a file 📎
27+
28+
- name: Result from "Upload File"
29+
run: echo '${{ steps.upload-file.outputs.slack-result }}'

README.md

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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
22

33
— With support for Slack's optional arguments
44

55
![](https://img.shields.io/github/release/archive/github-actions-slack/all.svg)
66
![](https://snyk.io/test/github/archive/github-actions-slack/badge.svg)
77

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.
99

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.
1111

1212
![Slack result](./images/slack-result.png "Slack result")
1313

@@ -37,6 +37,9 @@ This action supports:
3737
- 3. Send reaction on sent messages<br>
3838
<img src="./images/reaction.png" width="300">
3939

40+
- 4. Upload files<br>
41+
<img src="./images/upload.png" width="300">
42+
4043
## 1. Send messages to Slack
4144

4245
**Required: Github Repository Secret:**
@@ -301,6 +304,68 @@ For some examples, please see:
301304
- [.github/workflows/11-slack-message-blocks.yml](.github/workflows/11-slack-message-blocks.yml)
302305
- [.github/workflows/12-slack-message-blocks-update.yml](.github/workflows/12-slack-message-blocks-update.yml)
303306

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+
![Slack result](./images/upload.png "Slack result")
368+
304369
## How to setup your first Github Action in your repository that will call this Action
305370

306371
### 1. Create a Slack bot
@@ -415,12 +480,12 @@ The source code moved from CommonJS (`require`) to ES Modules (`import`/`export`
415480

416481
## Development and testing
417482

418-
See package.json for `yarn lint`, `yarn test`, etc.
483+
See package.json for commands.
419484

420485
Remember to create the dist with `npm run build`.
421486

422487
To run local integration test (from this repository):
423488

424489
```
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
426491
```

action.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,19 @@ inputs:
5656
description: "https://api.slack.com/methods/chat.postMessage#arg_username"
5757
required: false
5858
slack-function:
59-
description: send-message (https://api.slack.com/methods/chat.postMessage) or send-reaction (https://api.slack.com/methods/reactions.add) or update-message (https://api.slack.com/methods/chat.update)
59+
description: send-message (https://api.slack.com/methods/chat.postMessage) or send-reaction (https://api.slack.com/methods/reactions.add) or update-message (https://api.slack.com/methods/chat.update) or upload-file (https://api.slack.com/methods/files.upload)
60+
required: false
61+
slack-upload-file-path:
62+
description: "https://api.slack.com/methods/files.upload#arg_file"
63+
required: false
64+
slack-upload-filename:
65+
description: "https://api.slack.com/methods/files.upload#arg_filename"
66+
required: false
67+
slack-upload-file-title:
68+
description: "https://api.slack.com/methods/files.upload#arg_title"
69+
required: false
70+
slack-upload-initial-comment:
71+
description: "https://api.slack.com/methods/files.upload#arg_initial_comment"
6072
required: false
6173
slack-emoji-name:
6274
description: "https://api.slack.com/methods/reactions.add#arg_name"

0 commit comments

Comments
 (0)