Skip to content

Commit 5624c24

Browse files
committed
add: slack
1 parent c104045 commit 5624c24

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

components/slack/actions/upload-file/upload-file.mjs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import {
2-
ConfigurationError, axios,
2+
ConfigurationError, axios, getFileStreamAndMetadata,
33
} from "@pipedream/platform";
4-
import fs from "fs";
54
import FormData from "form-data";
65
import slack from "../../slack.app.mjs";
76

87
export default {
98
key: "slack-upload-file",
109
name: "Upload File",
1110
description: "Upload a file. [See the documentation](https://api.slack.com/messaging/files#uploading_files)",
12-
version: "0.0.27",
11+
version: "0.1.0",
1312
type: "action",
1413
props: {
1514
slack,
@@ -35,16 +34,16 @@ export default {
3534
},
3635
},
3736
async run({ $ }) {
38-
if (!fs.existsSync(this.content)) {
39-
throw new ConfigurationError(`\`${this.content}\` not found, a valid \`/tmp\` path is needed`);
40-
}
37+
const {
38+
stream, metadata,
39+
} = await getFileStreamAndMetadata(this.content);
4140

4241
const filename = this.content.split("/").pop();
4342

4443
// Get an upload URL from Slack
4544
const getUploadUrlResponse = await this.slack.getUploadUrl({
4645
filename,
47-
length: fs.statSync(this.content).size,
46+
length: metadata.size,
4847
});
4948

5049
if (!getUploadUrlResponse.ok) {
@@ -57,7 +56,7 @@ export default {
5756

5857
// Upload the file to the provided URL
5958
const formData = new FormData();
60-
formData.append("file", fs.createReadStream(this.content));
59+
formData.append("file", stream);
6160
formData.append("filename", filename);
6261

6362
await axios($, {

components/slack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/slack",
3-
"version": "0.9.5",
3+
"version": "0.10.0",
44
"description": "Pipedream Slack Components",
55
"main": "slack.app.mjs",
66
"keywords": [
@@ -14,7 +14,7 @@
1414
"access": "public"
1515
},
1616
"dependencies": {
17-
"@pipedream/platform": "^3.0.0",
17+
"@pipedream/platform": "^3.1.0",
1818
"@slack/web-api": "^7.9.0",
1919
"async-retry": "^1.3.3",
2020
"lodash": "^4.17.21"

components/slack/slack.app.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ export default {
356356
},
357357
},
358358
content: {
359-
label: "File Path",
360-
description: "Full path to the file in `/tmp/` directory. E.g. `/tmp/cute_cat.jpg`",
359+
label: "File Path or URL",
360+
description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
361361
type: "string",
362362
},
363363
link_names: {

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)