diff --git a/components/esendex/.gitignore b/components/esendex/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/esendex/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/esendex/actions/send-sms-message/send-sms-message.mjs b/components/esendex/actions/send-sms-message/send-sms-message.mjs new file mode 100644 index 0000000000000..2997ff4f81eda --- /dev/null +++ b/components/esendex/actions/send-sms-message/send-sms-message.mjs @@ -0,0 +1,75 @@ +import esendex from "../../esendex.app.mjs"; +import constants from "../../common/constants.mjs"; + +export default { + key: "esendex-send-sms-message", + name: "Send SMS Message", + description: "Send an SMS message to a recipient. [See the documentation](https://developers.esendex.com/api-reference/#messagedispatcher)", + version: "0.0.1", + type: "action", + props: { + esendex, + accountReference: { + propDefinition: [ + esendex, + "accountReference", + ], + }, + to: { + type: "string", + label: "To", + description: "The phone number to send the message to. E.g. `447700900123`", + }, + message: { + type: "string", + label: "Message", + description: "The message to send", + }, + from: { + type: "string", + label: "From", + description: "The default alphanumeric originator that the message appears to originate from. This must be either a valid phone number or an alphanumeric value with a maximum length of 11 characters, that may contain letters, numbers and the following special characters: * $ ? ! ” # % & _ - , @ ' +. Special characters may not work for all networks in France.", + optional: true, + }, + sendAt: { + type: "string", + label: "Send At", + description: "The scheduled time to send the messages in this request. The format is `yyyy-MM-ddThh:mm:ssZ` where y=year, M=month, d=day, T=separator, h=hour, m=min and s=seconds. The value is treated as per ISO 8601 semantics, e.g. without time zone information the value is assumed to be the local time of the server, otherwise as an offset from UTC with Z representing a UTC time.", + optional: true, + }, + characterSet: { + type: "string", + label: "Character Set", + description: "The character set of the message to be used. Valid values are: GSM, Unicode and Auto. When using Auto the most appropriate character set is automatically detected. The default value is GSM. When using auto, if unicode characters are detected, the number of characters available in a message will change from 160 to 70.", + options: constants.CHARACTER_SETS, + optional: true, + }, + validity: { + type: "integer", + label: "Validity", + description: "The validity period for this message in hours (default to 0 which indicates the MAX allowed). The maximum allowed validity period is 72 hours.", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.esendex.sendMessage({ + $, + data: { + accountreference: this.accountReference, + sendat: this.sendAt, + messages: [ + { + to: this.to, + body: this.message, + from: this.from, + type: "SMS", + characterset: this.characterSet, + validity: this.validity, + }, + ], + }, + }); + $.export("$summary", `Successfully sent SMS message to ${this.to}`); + return response; + }, +}; diff --git a/components/esendex/actions/send-voice-message/send-voice-message.mjs b/components/esendex/actions/send-voice-message/send-voice-message.mjs new file mode 100644 index 0000000000000..5e308c9a366d7 --- /dev/null +++ b/components/esendex/actions/send-voice-message/send-voice-message.mjs @@ -0,0 +1,82 @@ +import esendex from "../../esendex.app.mjs"; +import constants from "../../common/constants.mjs"; + +export default { + key: "esendex-send-voice-message", + name: "Send Voice Message", + description: "Send a voice message to a recipient. [See the documentation](https://developers.esendex.com/api-reference/#messagedispatcher)", + version: "0.0.1", + type: "action", + props: { + esendex, + accountReference: { + propDefinition: [ + esendex, + "accountReference", + ], + }, + to: { + type: "string", + label: "To", + description: "The phone number to send the message to. E.g. `447700900123`", + }, + message: { + type: "string", + label: "Message", + description: "The message to send", + }, + from: { + type: "string", + label: "From", + description: "The default alphanumeric originator that the message appears to originate from. This must be either a valid phone number or an alphanumeric value with a maximum length of 11 characters, that may contain letters, numbers and the following special characters: * $ ? ! ” # % & _ - , @ ' +. Special characters may not work for all networks in France.", + optional: true, + }, + sendAt: { + type: "string", + label: "Send At", + description: "The scheduled time to send the messages in this request. The format is `yyyy-MM-ddThh:mm:ssZ` where y=year, M=month, d=day, T=separator, h=hour, m=min and s=seconds. The value is treated as per ISO 8601 semantics, e.g. without time zone information the value is assumed to be the local time of the server, otherwise as an offset from UTC with Z representing a UTC time.", + optional: true, + }, + characterSet: { + type: "string", + label: "Character Set", + description: "The character set of the message to be used. Valid values are: GSM, Unicode and Auto. When using Auto the most appropriate character set is automatically detected. The default value is GSM. When using auto, if unicode characters are detected, the number of characters available in a message will change from 160 to 70.", + options: constants.CHARACTER_SETS, + optional: true, + }, + lang: { + type: "string", + label: "Language", + description: "The language to use for this Voice message", + options: constants.LANGUAGES, + }, + retries: { + type: "integer", + label: "Retries", + description: "The number of times to attempt to call and deliver a Voice message", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.esendex.sendMessage({ + $, + data: { + accountreference: this.accountReference, + sendat: this.sendAt, + messages: [ + { + to: this.to, + body: this.message, + from: this.from, + type: "Voice", + characterset: this.characterSet, + lang: this.lang, + retries: this.retries, + }, + ], + }, + }); + $.export("$summary", `Successfully sent voicemessage to ${this.to}`); + return response; + }, +}; diff --git a/components/esendex/app/esendex.app.ts b/components/esendex/app/esendex.app.ts deleted file mode 100644 index f6ab052af809c..0000000000000 --- a/components/esendex/app/esendex.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "esendex", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); \ No newline at end of file diff --git a/components/esendex/common/constants.mjs b/components/esendex/common/constants.mjs new file mode 100644 index 0000000000000..c1836b16d026b --- /dev/null +++ b/components/esendex/common/constants.mjs @@ -0,0 +1,58 @@ +const CHARACTER_SETS = [ + "GSM", + "Unicode", + "Auto", +]; + +const LANGUAGES = [ + { + label: "English UK", + value: "en-GB", + }, + { + label: "English Australian", + value: "en-AU", + }, + { + label: "French", + value: "fr-FR", + }, + { + label: "Spanish", + value: "es-ES", + }, + { + label: "German", + value: "de-DE", + }, +]; + +const MESSAGE_STATUSES = [ + "Acknowledged", + "Authorised", + "Connecting", + "Delivered", + "Dispatched", + "Expired", + "Failed", + "FailedAuthorisation", + "PartiallyDelivered", + "Processing", + "Queued", + "Rejected", + "Scheduled", + "Sent", + "Submitted", +]; + +const MESSAGE_TYPES = [ + "SMS", + "Voice", +]; + +export default { + CHARACTER_SETS, + LANGUAGES, + MESSAGE_STATUSES, + MESSAGE_TYPES, +}; diff --git a/components/esendex/esendex.app.mjs b/components/esendex/esendex.app.mjs new file mode 100644 index 0000000000000..d02cf2a273c6d --- /dev/null +++ b/components/esendex/esendex.app.mjs @@ -0,0 +1,56 @@ +import { axios } from "@pipedream/platform"; + +export default { + type: "app", + app: "esendex", + propDefinitions: { + accountReference: { + type: "string", + label: "Account Reference", + description: "The account reference to use for the request", + async options() { + const { accounts } = await this.listAccounts(); + return accounts.map((account) => ({ + label: account.label, + value: account.reference, + })); + }, + }, + }, + methods: { + _baseUrl() { + return "https://api.esendex.com/v1.0"; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + auth: { + username: `${this.$auth.username}`, + password: `${this.$auth.api_password}`, + }, + ...opts, + }); + }, + listAccounts(opts = {}) { + return this._makeRequest({ + path: "/accounts", + ...opts, + }); + }, + listMessages(opts = {}) { + return this._makeRequest({ + path: "/messageheaders", + ...opts, + }); + }, + sendMessage(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/messagedispatcher", + ...opts, + }); + }, + }, +}; diff --git a/components/esendex/package.json b/components/esendex/package.json index 52a7a141fc449..c5280b44ff3f3 100644 --- a/components/esendex/package.json +++ b/components/esendex/package.json @@ -1,16 +1,19 @@ { "name": "@pipedream/esendex", - "version": "0.0.2", + "version": "0.1.0", "description": "Pipedream Esendex Components", - "main": "dist/app/esendex.app.mjs", + "main": "esendex.app.mjs", "keywords": [ "pipedream", "esendex" ], - "files": ["dist"], "homepage": "https://pipedream.com/apps/esendex", "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3", + "simple-xml2json": "^1.2.3" } } diff --git a/components/esendex/sources/new-message-received/new-message-received.mjs b/components/esendex/sources/new-message-received/new-message-received.mjs new file mode 100644 index 0000000000000..89157c9ccac7a --- /dev/null +++ b/components/esendex/sources/new-message-received/new-message-received.mjs @@ -0,0 +1,104 @@ +import esendex from "../../esendex.app.mjs"; +import constants from "../../common/constants.mjs"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import xml2json from "simple-xml2json"; +import sampleEmit from "./test-event.mjs"; + +export default { + key: "esendex-new-message-received", + name: "New Message Received", + description: "Emit new event when a new message is received. [See the documentation](https://developers.esendex.com/api-reference/#messageheader)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + esendex, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + type: { + type: "string", + label: "Type", + description: "The type of the messages to watch for: either SMS or Voice. If no type is specified, all types are returned.", + options: constants.MESSAGE_TYPES, + optional: true, + }, + status: { + type: "string", + label: "Status", + description: "Filter messages by status. If no status is specified, all statuses are returned.", + options: constants.MESSAGE_STATUSES, + optional: true, + }, + }, + methods: { + _getLastTs() { + return this.db.get("lastTs"); + }, + _setLastTs(ts) { + this.db.set("lastTs", ts); + }, + generateMeta(message) { + return { + id: message.id, + summary: `New Message Received: ${message.id}`, + ts: Date.parse(message.laststatusat), + }; + }, + async processEvent(max) { + const lastTs = this._getLastTs(); + let maxTs = lastTs; + + const xmlResponse = await this.esendex.listMessages({ + params: { + start: lastTs, + finish: new Date().toISOString() + .split(".")[0] + "Z", // current time + status: this.status, + }, + }); + + const { messageheaders } = xml2json.parser(xmlResponse); + let messages = messageheaders?.messageheader || []; + if (!Array.isArray(messages)) { + messages = [ + messages, + ]; + } + + if (!messages.length) { + return; + } + + let count = 0; + for (const message of messages) { + if ((!lastTs || Date.parse(message.laststatusat) > Date.parse(lastTs)) + && (!this.type || message.type === this.type)) { + const meta = this.generateMeta(message); + this.$emit(message, meta); + if (!maxTs || Date.parse(message.laststatusat) > Date.parse(maxTs)) { + maxTs = message.laststatusat; + } + if (max && ++count >= max) { + break; + } + } + } + + this._setLastTs(maxTs); + }, + }, + hooks: { + async deploy() { + await this.processEvent(25); + }, + }, + async run() { + await this.processEvent(); + }, + sampleEmit, +}; diff --git a/components/esendex/sources/new-message-received/test-event.mjs b/components/esendex/sources/new-message-received/test-event.mjs new file mode 100644 index 0000000000000..1485717aac2b6 --- /dev/null +++ b/components/esendex/sources/new-message-received/test-event.mjs @@ -0,0 +1,29 @@ +export default { + "id": "7645199a-01e6-4a9f-8ce1-ae3a4ea30227", + "uri": "https://api.esendex.com/v1.0/messageheaders/7645199a-01e6-4a9f-8ce1-ae3a4ea30227", + "reference": "EX0349711", + "status": "Delivered", + "deliveredat": "2025-06-04T15:21:39.783Z", + "sentat": "2025-06-04T15:21:34.19Z", + "laststatusat": "2025-06-04T15:21:39.783Z", + "submittedat": "2025-06-04T15:21:33.843Z", + "type": "SMS", + "to": { + "phonenumber": 5555555555, + }, + "from": { + "phonenumber": 5555555555, + }, + "summary": "hello world", + "body": { + "id": "7645199a-01e6-4a9f-8ce1-ae3a4ea30227", + "uri": "https://api.esendex.com/v1.0/messageheaders/7645199a-01e6-4a9f-8ce1-ae3a4ea30227/body" + }, + "direction": "Outbound", + "parts": 1, + "username": "", + "batch": { + "id": "3428f958-c19d-49c6-9c59-3c2f9e884713", + "uri": "https://api.esendex.com/v1.0/messagebatches/3428f958-c19d-49c6-9c59-3c2f9e884713" + } + } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 49aeb7fb7390d..8e80d913e09db 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -367,8 +367,7 @@ importers: specifier: ^1.2.1 version: 1.6.6 - components/adtraction: - specifiers: {} + components/adtraction: {} components/adversus: dependencies: @@ -3739,8 +3738,7 @@ importers: components/dokan: {} - components/dolibarr: - specifiers: {} + components/dolibarr: {} components/domain_group: dependencies: @@ -4225,7 +4223,14 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/esendex: {} + components/esendex: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 + simple-xml2json: + specifier: ^1.2.3 + version: 1.2.3 components/esignatures_io: dependencies: @@ -7373,8 +7378,7 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/limoexpress: - specifiers: {} + components/limoexpress: {} components/line: dependencies: @@ -9888,8 +9892,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/pinghome: - specifiers: {} + components/pinghome: {} components/pingone: {} @@ -10384,8 +10387,7 @@ importers: components/procore_sandbox: {} - components/prodatakey: - specifiers: {} + components/prodatakey: {} components/prodpad: dependencies: @@ -15058,8 +15060,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/zenedu: - specifiers: {} + components/zenedu: {} components/zenkit: dependencies: @@ -28648,6 +28649,9 @@ packages: resolution: {integrity: sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==} engines: {node: '>=10'} + simple-xml2json@1.2.3: + resolution: {integrity: sha512-R2qDtYMXCaaXq300+TKTtzJvryJ2BFmbP2VANnS6H7XzUgVbi9an7VnCVLvXMdEqyzAW6G4whZix7fOuUo54oQ==} + sisteransi@1.0.5: resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} @@ -48657,6 +48661,8 @@ snapshots: dependencies: semver: 7.7.1 + simple-xml2json@1.2.3: {} + sisteransi@1.0.5: {} slackify-html@1.0.1: