Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions components/syncmate_by_assitro/actions/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ConfigurationError } from "@pipedream/platform";
import fs from "fs";
import { checkTmp } from "../../common/utils.mjs";
import syncmateByAssitro from "../../syncmate_by_assitro.app.mjs";

export default {
props: {
syncmateByAssitro,
number: {
propDefinition: [
syncmateByAssitro,
"number",
],
},
message: {
propDefinition: [
syncmateByAssitro,
"message",
],
},
media: {
propDefinition: [
syncmateByAssitro,
"media",
],
},
fileName: {
propDefinition: [
syncmateByAssitro,
"fileName",
],
optional: true,
},
},
async run({ $ }) {
if (this.media && !this.fileName) {
throw new ConfigurationError("You must provide the file name.");
}
const file = fs.readFileSync(checkTmp(this.media), {
encoding: "base64",
});
const response = await this.syncmateByAssitro.sendSingleMessage({
$,
data: {
msgs: [
{
number: this.number,
message: this.message,
media: [
{
media_base64: file,
file_name: this.fileName,
},
],
},
],
},
});

$.export("$summary", `Successfully sent message to ${this.number}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import fs from "fs";
import { checkTmp } from "../../common/utils.mjs";
import syncmateByAssitro from "../../syncmate_by_assitro.app.mjs";

export default {
key: "syncmate_by_assitro-send-bulk-messages",
name: "Send Bulk Messages",
description: "Send multiple WhatsApp messages in bulk. [See the documentation](https://assistro.co/user-guide/bulk-messaging-at-a-scheduled-time-using-syncmate-2/)",
version: "0.0.1",
type: "action",
props: {
syncmateByAssitro,
messagesNumber: {
type: "string",
label: "Messages Number",
description: "The quantity of messages you want to send.",
reloadProps: true,
},
},
async additionalProps() {
const props = {};
for (let i = 1; i <= this.messagesNumber; i++) {
props[`number${i}`] = {
type: "string",
label: `Number ${i}`,
description: "WhatsApp number with country code",
};
props[`message${i}`] = {
type: "string",
label: `Message ${i}`,
description: "The text message to be sent",
};
props[`media${i}`] = {
type: "string",
label: `Media ${i}`,
description: "Base64 encoded media files",
optional: true,
};
props[`fileName${i}`] = {
type: "string",
label: `File Name ${i}`,
description: "The name of the file.",
optional: true,
};
}

return props;
},
async run({ $ }) {
const msgs = [];

for (let i = 1; i <= this.messagesNumber; i++) {
const file = fs.readFileSync(checkTmp(this[`media${i}`]), {
encoding: "base64",
});

msgs.push({
number: this[`number${i}`],
message: this[`message${i}`],
media: [
{
media_base64: file,
file_name: this[`fileName${i}`],
},
],
});
}

const response = await this.syncmateByAssitro.sendBulkMessages({
$,
data: {
msgs,
},
});

$.export("$summary", `Successfully sent ${this.messagesNumber} messages.`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ConfigurationError } from "@pipedream/platform";
import fs from "fs";
import { checkTmp } from "../../common/utils.mjs";
import syncmateByAssitro from "../../syncmate_by_assitro.app.mjs";

export default {
key: "syncmate_by_assitro-send-message",
name: "Send WhatsApp Message",
description: "Send a single WhatsApp message using SyncMate by Assistro. [See the documentation](https://assistro.co/user-guide/connect-your-custom-app-with-syncmate/)",
version: "0.0.1",
type: "action",
props: {
syncmateByAssitro,
number: {
type: "string",
label: "Number",
description: "WhatsApp number with country code",
},
message: {
type: "string",
label: "Message",
description: "The text message to be sent",
},
media: {
type: "string",
label: "Media",
description: "Base64 encoded media files",
optional: true,
},
fileName: {
type: "string",
label: "File Name",
description: "The name of the file.",
optional: true,
},
},
async run({ $ }) {
if (this.media && !this.fileName) {
throw new ConfigurationError("You must provide the file name.");
}
const file = fs.readFileSync(checkTmp(this.media), {
encoding: "base64",
});
const response = await this.syncmateByAssitro.sendSingleMessage({
$,
data: {
msgs: [
{
number: this.number,
message: this.message,
media: [
{
media_base64: file,
file_name: this.fileName,
},
],
},
],
},
});

$.export("$summary", `Successfully sent message to ${this.number}`);
return response;
},
};
6 changes: 6 additions & 0 deletions components/syncmate_by_assitro/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const checkTmp = (filename) => {
if (!filename.startsWith("/tmp")) {
return `/tmp/${filename}`;
}
return filename;
};
8 changes: 6 additions & 2 deletions components/syncmate_by_assitro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/syncmate_by_assitro",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream SyncMate by Assitro Components",
"main": "syncmate_by_assitro.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3",
"fs": "^0.0.1-security"
}
}
}
39 changes: 34 additions & 5 deletions components/syncmate_by_assitro/syncmate_by_assitro.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "syncmate_by_assitro",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://app.assistro.co/api/v1/wapushplus";
},
_headers() {
return {
"Authorization": `Bearer ${this.$auth.api_key}`,
"Content-Type": "application/json",
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
...opts,
});
},
sendSingleMessage(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/single/message",
...opts,
});
},
sendBulkMessages(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/bulk/message",
...opts,
});
},
},
};
};
8 changes: 7 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.