Skip to content

Commit 9ac982c

Browse files
committed
some adjusts
1 parent e6dc232 commit 9ac982c

File tree

5 files changed

+47
-91
lines changed

5 files changed

+47
-91
lines changed

components/syncmate_by_assitro/actions/common/base.mjs

Lines changed: 0 additions & 63 deletions
This file was deleted.

components/syncmate_by_assitro/actions/send-bulk-messages/send-bulk-messages.mjs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ConfigurationError } from "@pipedream/platform";
12
import fs from "fs";
23
import { checkTmp } from "../../common/utils.mjs";
34
import syncmateByAssitro from "../../syncmate_by_assitro.app.mjs";
@@ -11,7 +12,7 @@ export default {
1112
props: {
1213
syncmateByAssitro,
1314
messagesNumber: {
14-
type: "string",
15+
type: "integer",
1516
label: "Messages Number",
1617
description: "The quantity of messages you want to send.",
1718
reloadProps: true,
@@ -33,7 +34,7 @@ export default {
3334
props[`media${i}`] = {
3435
type: "string",
3536
label: `Media ${i}`,
36-
description: "Base64 encoded media files",
37+
description: "The the path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp).",
3738
optional: true,
3839
};
3940
props[`fileName${i}`] = {
@@ -50,20 +51,27 @@ export default {
5051
const msgs = [];
5152

5253
for (let i = 1; i <= this.messagesNumber; i++) {
53-
const file = fs.readFileSync(checkTmp(this[`media${i}`]), {
54-
encoding: "base64",
55-
});
56-
57-
msgs.push({
54+
if (this[`media${i}`] && !this[`fileName${i}`]) {
55+
throw new ConfigurationError(`You must provide the File Name ${i}.`);
56+
}
57+
const data = {
5858
number: this[`number${i}`],
5959
message: this[`message${i}`],
60-
media: [
60+
};
61+
62+
if (this[`media${i}`]) {
63+
const file = fs.readFileSync(checkTmp(this[`media${i}`]), {
64+
encoding: "base64",
65+
});
66+
data.media = [
6167
{
6268
media_base64: file,
6369
file_name: this[`fileName${i}`],
6470
},
65-
],
66-
});
71+
];
72+
}
73+
74+
msgs.push(data);
6775
}
6876

6977
const response = await this.syncmateByAssitro.sendBulkMessages({

components/syncmate_by_assitro/actions/send-message/send-message.mjs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default {
2424
media: {
2525
type: "string",
2626
label: "Media",
27-
description: "Base64 encoded media files",
27+
description: "The the path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp).",
2828
optional: true,
2929
},
3030
fileName: {
@@ -38,24 +38,31 @@ export default {
3838
if (this.media && !this.fileName) {
3939
throw new ConfigurationError("You must provide the file name.");
4040
}
41-
const file = fs.readFileSync(checkTmp(this.media), {
42-
encoding: "base64",
43-
});
41+
42+
const msgs = [
43+
{
44+
number: this.number,
45+
message: this.message,
46+
},
47+
];
48+
49+
if (this.media) {
50+
const file = fs.readFileSync(checkTmp(this.media), {
51+
encoding: "base64",
52+
});
53+
54+
msgs[0].media = [
55+
{
56+
media_base64: file,
57+
file_name: this.fileName,
58+
},
59+
];
60+
}
61+
4462
const response = await this.syncmateByAssitro.sendSingleMessage({
4563
$,
4664
data: {
47-
msgs: [
48-
{
49-
number: this.number,
50-
message: this.message,
51-
media: [
52-
{
53-
media_base64: file,
54-
file_name: this.fileName,
55-
},
56-
],
57-
},
58-
],
65+
msgs,
5966
},
6067
});
6168

components/syncmate_by_assitro/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^3.0.3",
17-
"fs": "^0.0.1-security"
16+
"@pipedream/platform": "^3.0.3"
1817
}
1918
}

components/syncmate_by_assitro/syncmate_by_assitro.app.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export default {
1616
_makeRequest({
1717
$ = this, path, ...opts
1818
}) {
19+
console.log("config", {
20+
url: this._baseUrl() + path,
21+
headers: this._headers(),
22+
...opts,
23+
});
1924
return axios($, {
2025
url: this._baseUrl() + path,
2126
headers: this._headers(),

0 commit comments

Comments
 (0)