diff --git a/components/gupshup/actions/send-template-message/send-template-message.mjs b/components/gupshup/actions/send-template-message/send-template-message.mjs new file mode 100644 index 0000000000000..23c7d07d1046c --- /dev/null +++ b/components/gupshup/actions/send-template-message/send-template-message.mjs @@ -0,0 +1,60 @@ +import gupshup from "../../gupshup.app.mjs"; + +export default { + key: "gupshup-send-template-message", + name: "Send Template Message", + description: "Send a template message. Requires a paid Gupshup account. [See the documentation](https://docs.gupshup.io/reference/sending-text-template)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + gupshup, + info: { + type: "alert", + alertType: "info", + content: "Note: This action requires a paid Gupshup account.", + }, + source: { + type: "string", + label: "Source", + description: "Sender Whatsapp Number", + }, + destination: { + type: "string", + label: "Destination", + description: "Receiver Whatsapp Number", + }, + templateId: { + propDefinition: [ + gupshup, + "templateId", + ], + }, + params: { + type: "string[]", + label: "Parameters", + description: "List of template parameters", + }, + }, + async run({ $ }) { + const response = await this.gupshup.sendTemplateMessage({ + $, + data: { + source: this.source, + destination: this.destination, + template: { + id: this.templateId, + params: this.params, + }, + }, + }); + if (response.status === "success") { + $.export("$summary", `Successfully sent template message to ${this.destination}`); + } + return response; + }, +}; diff --git a/components/gupshup/actions/update-subscription/update-subscription.mjs b/components/gupshup/actions/update-subscription/update-subscription.mjs new file mode 100644 index 0000000000000..6b96ba5e6747b --- /dev/null +++ b/components/gupshup/actions/update-subscription/update-subscription.mjs @@ -0,0 +1,63 @@ +import gupshup from "../../gupshup.app.mjs"; + +export default { + key: "gupshup-update-subscription", + name: "Update Subscription", + description: "Update a subscription. Requires a paid Gupshup account. [See the documentation](https://docs.gupshup.io/reference/updateanexisitngsubscription)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: true, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + gupshup, + info: { + type: "alert", + alertType: "info", + content: "Note: This action requires a paid Gupshup account.", + }, + subscriptionId: { + type: "string", + label: "Subscription ID", + description: "The ID of the subscription to update", + }, + modes: { + type: "string", + label: "Modes", + description: "The modes of the subscription", + }, + url: { + type: "string", + label: "URL", + description: "The subscription URL", + }, + version: { + type: "integer", + label: "Version", + description: "The version of the subscription", + }, + active: { + type: "boolean", + label: "Active", + description: "Whether the subscription is active", + }, + }, + async run({ $ }) { + const response = await this.gupshup.updateSubscription({ + $, + subscriptionId: this.subscriptionId, + data: { + modes: this.modes, + url: this.url, + version: this.version, + active: this.active, + }, + }); + if (response.status === "success") { + $.export("$summary", `Successfully updated subscription ${this.subscriptionId}`); + } + return response; + }, +}; diff --git a/components/gupshup/gupshup.app.mjs b/components/gupshup/gupshup.app.mjs index 1bc8b6c25ffd0..c4da6b0c7a817 100644 --- a/components/gupshup/gupshup.app.mjs +++ b/components/gupshup/gupshup.app.mjs @@ -1,11 +1,69 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "gupshup", - propDefinitions: {}, + propDefinitions: { + templateId: { + type: "string", + label: "Template ID", + description: "The ID of the template to use", + async options({ page }) { + const { templates } = await this.listTemplates({ + params: { + pageNo: page, + }, + }); + return templates?.map(({ id }) => id) || []; + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.gupshup.io"; + }, + _appName() { + return this.$auth.appname; + }, + _makeRequest({ + $ = this, path, headers, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + ...headers, + "apikey": `${this.$auth.apikey}`, + }, + ...opts, + }); + }, + listTemplates(opts = {}) { + return this._makeRequest({ + path: `/wa/app/${this._appName()}/template`, + ...opts, + }); + }, + sendTemplateMessage(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/wa/api/v1/template/msg", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + ...opts, + }); + }, + updateSubscription({ + subscriptionId, ...opts + }) { + return this._makeRequest({ + method: "PUT", + path: `/wa/app/${this._appName()}/subscription/${subscriptionId}`, + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + ...opts, + }); }, }, }; diff --git a/components/gupshup/package.json b/components/gupshup/package.json index 055f42240f31b..196354e904036 100644 --- a/components/gupshup/package.json +++ b/components/gupshup/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/gupshup", - "version": "0.0.3", + "version": "0.1.0", "description": "Pipedream Gupshup Components", "main": "gupshup.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2bd737ed6c93c..75652f5ef8e95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2589,8 +2589,7 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/chartly: - specifiers: {} + components/chartly: {} components/chartmogul: dependencies: @@ -3541,8 +3540,7 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/cryptlex: - specifiers: {} + components/cryptlex: {} components/crypto_apis_by_alternative: {} @@ -4289,8 +4287,7 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/docuwriter_ai: - specifiers: {} + components/docuwriter_ai: {} components/dokan: {} @@ -5776,8 +5773,7 @@ importers: specifier: 4.0.4 version: 4.0.4 - components/genpage: - specifiers: {} + components/genpage: {} components/geoapify: dependencies: @@ -6615,7 +6611,11 @@ importers: specifier: ^1.6.8 version: 1.6.8 - components/gupshup: {} + components/gupshup: + dependencies: + '@pipedream/platform': + specifier: ^3.1.1 + version: 3.1.1 components/guru: dependencies: @@ -7118,8 +7118,7 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/hybrid_analysis: - specifiers: {} + components/hybrid_analysis: {} components/hygraph: {} @@ -7732,8 +7731,7 @@ importers: components/junip: {} - components/just_invoice: - specifiers: {} + components/just_invoice: {} components/justcall: dependencies: @@ -11434,8 +11432,7 @@ importers: specifier: ^1.6.8 version: 1.6.8 - components/pod_ai: - specifiers: {} + components/pod_ai: {} components/podio: dependencies: @@ -11735,8 +11732,7 @@ importers: specifier: ^1.6.8 version: 1.6.8 - components/productify_ai: - specifiers: {} + components/productify_ai: {} components/productive_io: dependencies: @@ -11788,8 +11784,7 @@ importers: specifier: ^1.6.8 version: 1.6.8 - components/proovl: - specifiers: {} + components/proovl: {} components/propelauth: {} @@ -13831,8 +13826,7 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/slab: - specifiers: {} + components/slab: {} components/slack: dependencies: @@ -15333,8 +15327,7 @@ importers: specifier: ^3.1.1 version: 3.1.1 - components/transcript_downloader: - specifiers: {} + components/transcript_downloader: {} components/transform: dependencies: @@ -15937,8 +15930,7 @@ importers: specifier: 4.0.4 version: 4.0.4 - components/vatfix_plus: - specifiers: {} + components/vatfix_plus: {} components/vbout: dependencies: