Skip to content

Commit 86d3c48

Browse files
New Components - syncmate_by_assitro (#16836)
* syncmate_by_assitro init * [Components] syncmate_by_assitro #16832 Actions - Send Message - Send Bulk Messages * pnpm update * Update components/syncmate_by_assitro/package.json Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * some adjusts * pnpm update * pnpm update * Update components/syncmate_by_assitro/syncmate_by_assitro.app.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 42d5532 commit 86d3c48

File tree

8 files changed

+211
-18
lines changed

8 files changed

+211
-18
lines changed

components/ringg_ai/ringg_ai.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/rumi_ai/rumi_ai.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import fs from "fs";
3+
import { checkTmp } from "../../common/utils.mjs";
4+
import syncmateByAssitro from "../../syncmate_by_assitro.app.mjs";
5+
6+
export default {
7+
key: "syncmate_by_assitro-send-bulk-messages",
8+
name: "Send Bulk Messages",
9+
description: "Send multiple WhatsApp messages in bulk. [See the documentation](https://assistro.co/user-guide/bulk-messaging-at-a-scheduled-time-using-syncmate-2/)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
syncmateByAssitro,
14+
messagesNumber: {
15+
type: "integer",
16+
label: "Messages Number",
17+
description: "The quantity of messages you want to send.",
18+
reloadProps: true,
19+
},
20+
},
21+
async additionalProps() {
22+
const props = {};
23+
for (let i = 1; i <= this.messagesNumber; i++) {
24+
props[`number${i}`] = {
25+
type: "string",
26+
label: `Number ${i}`,
27+
description: "WhatsApp number with country code",
28+
};
29+
props[`message${i}`] = {
30+
type: "string",
31+
label: `Message ${i}`,
32+
description: "The text message to be sent",
33+
};
34+
props[`media${i}`] = {
35+
type: "string",
36+
label: `Media ${i}`,
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).",
38+
optional: true,
39+
};
40+
props[`fileName${i}`] = {
41+
type: "string",
42+
label: `File Name ${i}`,
43+
description: "The name of the file.",
44+
optional: true,
45+
};
46+
}
47+
48+
return props;
49+
},
50+
async run({ $ }) {
51+
const msgs = [];
52+
53+
for (let i = 1; i <= this.messagesNumber; i++) {
54+
if (this[`media${i}`] && !this[`fileName${i}`]) {
55+
throw new ConfigurationError(`You must provide the File Name ${i}.`);
56+
}
57+
const data = {
58+
number: this[`number${i}`],
59+
message: this[`message${i}`],
60+
};
61+
62+
if (this[`media${i}`]) {
63+
const file = fs.readFileSync(checkTmp(this[`media${i}`]), {
64+
encoding: "base64",
65+
});
66+
data.media = [
67+
{
68+
media_base64: file,
69+
file_name: this[`fileName${i}`],
70+
},
71+
];
72+
}
73+
74+
msgs.push(data);
75+
}
76+
77+
const response = await this.syncmateByAssitro.sendBulkMessages({
78+
$,
79+
data: {
80+
msgs,
81+
},
82+
});
83+
84+
$.export("$summary", `Successfully sent ${this.messagesNumber} messages.`);
85+
return response;
86+
},
87+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import fs from "fs";
3+
import { checkTmp } from "../../common/utils.mjs";
4+
import syncmateByAssitro from "../../syncmate_by_assitro.app.mjs";
5+
6+
export default {
7+
key: "syncmate_by_assitro-send-message",
8+
name: "Send WhatsApp Message",
9+
description: "Send a single WhatsApp message using SyncMate by Assistro. [See the documentation](https://assistro.co/user-guide/connect-your-custom-app-with-syncmate/)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
syncmateByAssitro,
14+
number: {
15+
type: "string",
16+
label: "Number",
17+
description: "WhatsApp number with country code",
18+
},
19+
message: {
20+
type: "string",
21+
label: "Message",
22+
description: "The text message to be sent",
23+
},
24+
media: {
25+
type: "string",
26+
label: "Media",
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).",
28+
optional: true,
29+
},
30+
fileName: {
31+
type: "string",
32+
label: "File Name",
33+
description: "The name of the file.",
34+
optional: true,
35+
},
36+
},
37+
async run({ $ }) {
38+
if (this.media && !this.fileName) {
39+
throw new ConfigurationError("You must provide the file name.");
40+
}
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+
62+
const response = await this.syncmateByAssitro.sendSingleMessage({
63+
$,
64+
data: {
65+
msgs,
66+
},
67+
});
68+
69+
$.export("$summary", `Successfully sent message to ${this.number}`);
70+
return response;
71+
},
72+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const checkTmp = (filename) => {
2+
if (!filename.startsWith("/tmp")) {
3+
return `/tmp/${filename}`;
4+
}
5+
return filename;
6+
};

components/syncmate_by_assitro/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/syncmate_by_assitro",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream SyncMate by Assitro Components",
55
"main": "syncmate_by_assitro.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}
Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "syncmate_by_assitro",
4-
propDefinitions: {},
56
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
7+
_baseUrl() {
8+
return "https://app.assistro.co/api/v1/wapushplus";
9+
},
10+
_headers() {
11+
return {
12+
"Authorization": `Bearer ${this.$auth.api_key}`,
13+
"Content-Type": "application/json",
14+
};
15+
},
16+
_makeRequest({
17+
$ = this, path, ...opts
18+
}) {
19+
return axios($, {
20+
url: this._baseUrl() + path,
21+
headers: this._headers(),
22+
...opts,
23+
});
24+
},
25+
sendSingleMessage(opts = {}) {
26+
return this._makeRequest({
27+
method: "POST",
28+
path: "/single/message",
29+
...opts,
30+
});
31+
},
32+
sendBulkMessages(opts = {}) {
33+
return this._makeRequest({
34+
method: "POST",
35+
path: "/bulk/message",
36+
...opts,
37+
});
938
},
1039
},
11-
};
40+
};

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)