diff --git a/components/fractel/actions/call-phone/call-phone.mjs b/components/fractel/actions/call-phone/call-phone.mjs new file mode 100644 index 0000000000000..6e963cd74ec30 --- /dev/null +++ b/components/fractel/actions/call-phone/call-phone.mjs @@ -0,0 +1,44 @@ +import fractel from "../../fractel.app.mjs"; + +export default { + key: "fractel-call-phone", + name: "Call Phone", + description: "Initiates a new phone call to the provided number.", + version: "0.0.1", + type: "action", + props: { + fractel, + phoneNumber: { + propDefinition: [ + fractel, + "phoneNumber", + ], + }, + to: { + propDefinition: [ + fractel, + "to", + ], + }, + message: { + propDefinition: [ + fractel, + "message", + ], + }, + }, + async run({ $ }) { + const response = await this.fractel.initiateCall({ + $, + data: { + fonenumber: this.phoneNumber, + to: this.to, + service_type: "TTS", + service_id: this.message, + }, + }); + + $.export("$summary", `Successfully initiated a call with Id: ${response.call.id}`); + return response; + }, +}; diff --git a/components/fractel/actions/send-sms-mms/send-sms-mms.mjs b/components/fractel/actions/send-sms-mms/send-sms-mms.mjs new file mode 100644 index 0000000000000..a3d88a8299f29 --- /dev/null +++ b/components/fractel/actions/send-sms-mms/send-sms-mms.mjs @@ -0,0 +1,60 @@ +import { parseObject } from "../../common/utils.mjs"; +import fractel from "../../fractel.app.mjs"; + +export default { + key: "fractel-send-sms-mms", + name: "Send SMS or MMS", + description: "Allows to send an SMS or MMS to a particular phone number. [See the documentation](https://developer.fonestorm.com/reference/sendmessage)", + version: "0.0.1", + type: "action", + props: { + fractel, + phoneNumber: { + propDefinition: [ + fractel, + "phoneNumber", + ], + description: "The phone number to send the message to, including country code.", + }, + to: { + propDefinition: [ + fractel, + "to", + ], + }, + message: { + propDefinition: [ + fractel, + "message", + ], + description: "The message content for SMS or MMS.", + optional: true, + }, + media: { + propDefinition: [ + fractel, + "media", + ], + optional: true, + }, + }, + async run({ $ }) { + if (!this.message && !this.media) { + throw new Error("Either message or media must be provided."); + } + const response = await this.fractel.sendMessage({ + $, + data: { + to: this.to, + fonenumber: this.phoneNumber, + message: this.message, + media: this.media && parseObject(this.media), + }, + }); + + $.export("$summary", `Successfully sent ${this.message + ? "SMS" + : "MMS"} with Id: ${response.message.id}`); + return response; + }, +}; diff --git a/components/fractel/common/utils.mjs b/components/fractel/common/utils.mjs new file mode 100644 index 0000000000000..4b5f3f9d301f8 --- /dev/null +++ b/components/fractel/common/utils.mjs @@ -0,0 +1,22 @@ +export const parseObject = (obj) => { + if (Array.isArray(obj)) { + return obj.map((item) => { + if (typeof item === "string") { + try { + return JSON.parse(item); + } catch (e) { + return item; + } + } + return item; + }); + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + return obj; +}; diff --git a/components/fractel/fractel.app.mjs b/components/fractel/fractel.app.mjs index 65866d7e2e844..b111abfb23be6 100644 --- a/components/fractel/fractel.app.mjs +++ b/components/fractel/fractel.app.mjs @@ -1,11 +1,72 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "fractel", - propDefinitions: {}, + propDefinitions: { + phoneNumber: { + type: "string", + label: "Phone Number", + description: "The phone number to call to, including country code.", + async options() { + const { fonenumbers } = await this.listFoneNumbers(); + return fonenumbers; + }, + }, + to: { + type: "string", + label: "To", + description: "The recipient phone number, including country code.", + }, + message: { + type: "string", + label: "Message", + description: "The message content for TTS.", + }, + media: { + type: "string", + label: "Media URL", + description: "Media URL of the media file for MMS.", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.fonestorm.com/v2"; + }, + _headers() { + return { + token: `${this.$auth.oauth_access_token}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: this._baseUrl() + path, + headers: this._headers(), + ...opts, + }); + }, + initiateCall(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/calls", + ...opts, + }); + }, + listFoneNumbers(opts = {}) { + return this._makeRequest({ + path: "/fonenumbers", + ...opts, + }); + }, + sendMessage(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/messages/send", + ...opts, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/fractel/package.json b/components/fractel/package.json index 548b3402eeaf2..509e5d1ceacba 100644 --- a/components/fractel/package.json +++ b/components/fractel/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/fractel", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream FracTEL Components", "main": "fractel.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^1.6.5" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 49ff92b0cd5e8..862691c28a9bc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3020,7 +3020,10 @@ importers: specifiers: {} components/fractel: - specifiers: {} + specifiers: + '@pipedream/platform': ^1.6.5 + dependencies: + '@pipedream/platform': 1.6.5 components/frame: specifiers: