diff --git a/components/ringg_ai/ringg_ai.app.mjs b/components/ringg_ai/ringg_ai.app.mjs index 9a946f81ebaa0..664ff29783b20 100644 --- a/components/ringg_ai/ringg_ai.app.mjs +++ b/components/ringg_ai/ringg_ai.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/rumi_ai/rumi_ai.app.mjs b/components/rumi_ai/rumi_ai.app.mjs index 8a72e61202b62..0e32ac3a25801 100644 --- a/components/rumi_ai/rumi_ai.app.mjs +++ b/components/rumi_ai/rumi_ai.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/syncmate_by_assitro/actions/send-bulk-messages/send-bulk-messages.mjs b/components/syncmate_by_assitro/actions/send-bulk-messages/send-bulk-messages.mjs new file mode 100644 index 0000000000000..6a3f30cbe4f8c --- /dev/null +++ b/components/syncmate_by_assitro/actions/send-bulk-messages/send-bulk-messages.mjs @@ -0,0 +1,87 @@ +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-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: "integer", + 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: "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).", + 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++) { + if (this[`media${i}`] && !this[`fileName${i}`]) { + throw new ConfigurationError(`You must provide the File Name ${i}.`); + } + const data = { + number: this[`number${i}`], + message: this[`message${i}`], + }; + + if (this[`media${i}`]) { + const file = fs.readFileSync(checkTmp(this[`media${i}`]), { + encoding: "base64", + }); + data.media = [ + { + media_base64: file, + file_name: this[`fileName${i}`], + }, + ]; + } + + msgs.push(data); + } + + const response = await this.syncmateByAssitro.sendBulkMessages({ + $, + data: { + msgs, + }, + }); + + $.export("$summary", `Successfully sent ${this.messagesNumber} messages.`); + return response; + }, +}; diff --git a/components/syncmate_by_assitro/actions/send-message/send-message.mjs b/components/syncmate_by_assitro/actions/send-message/send-message.mjs new file mode 100644 index 0000000000000..d8fa92bd1ffc7 --- /dev/null +++ b/components/syncmate_by_assitro/actions/send-message/send-message.mjs @@ -0,0 +1,72 @@ +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: "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).", + 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 msgs = [ + { + number: this.number, + message: this.message, + }, + ]; + + if (this.media) { + const file = fs.readFileSync(checkTmp(this.media), { + encoding: "base64", + }); + + msgs[0].media = [ + { + media_base64: file, + file_name: this.fileName, + }, + ]; + } + + const response = await this.syncmateByAssitro.sendSingleMessage({ + $, + data: { + msgs, + }, + }); + + $.export("$summary", `Successfully sent message to ${this.number}`); + return response; + }, +}; diff --git a/components/syncmate_by_assitro/common/utils.mjs b/components/syncmate_by_assitro/common/utils.mjs new file mode 100644 index 0000000000000..1a5e36f32a603 --- /dev/null +++ b/components/syncmate_by_assitro/common/utils.mjs @@ -0,0 +1,6 @@ +export const checkTmp = (filename) => { + if (!filename.startsWith("/tmp")) { + return `/tmp/${filename}`; + } + return filename; +}; diff --git a/components/syncmate_by_assitro/package.json b/components/syncmate_by_assitro/package.json index d771ae625415f..259eda1b8640b 100644 --- a/components/syncmate_by_assitro/package.json +++ b/components/syncmate_by_assitro/package.json @@ -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": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/components/syncmate_by_assitro/syncmate_by_assitro.app.mjs b/components/syncmate_by_assitro/syncmate_by_assitro.app.mjs index 75248e8dce136..dfe13f875435b 100644 --- a/components/syncmate_by_assitro/syncmate_by_assitro.app.mjs +++ b/components/syncmate_by_assitro/syncmate_by_assitro.app.mjs @@ -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, + }); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 446289198ccf6..2fe569ffe3769 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11169,8 +11169,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/ringg_ai: - specifiers: {} + components/ringg_ai: {} components/ringover: dependencies: @@ -13024,7 +13023,11 @@ importers: specifier: ^1.1.0 version: 1.6.6 - components/syncmate_by_assitro: {} + components/syncmate_by_assitro: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/syncro: {} @@ -15511,14 +15514,6 @@ importers: specifier: ^6.0.0 version: 6.2.0 - modelcontextprotocol/node_modules2/@modelcontextprotocol/sdk/dist/cjs: {} - - modelcontextprotocol/node_modules2/@modelcontextprotocol/sdk/dist/esm: {} - - modelcontextprotocol/node_modules2/zod-to-json-schema/dist/cjs: {} - - modelcontextprotocol/node_modules2/zod-to-json-schema/dist/esm: {} - packages/ai: dependencies: '@pipedream/sdk':