diff --git a/components/fractel/actions/call-phone/call-phone.mjs b/components/fractel/actions/call-phone/call-phone.mjs index 0716a074104a2..14ed776e0cfbc 100644 --- a/components/fractel/actions/call-phone/call-phone.mjs +++ b/components/fractel/actions/call-phone/call-phone.mjs @@ -1,11 +1,10 @@ import fractel from "../../fractel.app.mjs"; -import { axios } from "@pipedream/platform"; export default { key: "fractel-call-phone", name: "Call Phone", description: "Initiates a new phone call to the provided number.", - version: "0.0.{{ts}}", + version: "0.0.1", type: "action", props: { fractel, @@ -30,12 +29,16 @@ export default { }, async run({ $ }) { const response = await this.fractel.initiateCall({ - phoneNumber: this.phoneNumber, - to: this.to, - message: this.message, + $, + data: { + phoneNumber: this.phoneNumber, + to: this.to, + service_type: "TTS", + service_id: this.message, + }, }); - $.export("$summary", `Successfully initiated a call to ${this.to}`); + $.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 index 9c6daef75afae..5b320ceed42d4 100644 --- a/components/fractel/actions/send-sms-mms/send-sms-mms.mjs +++ b/components/fractel/actions/send-sms-mms/send-sms-mms.mjs @@ -1,5 +1,5 @@ +import { parseObject } from "../../common/utils.mjs"; import fractel from "../../fractel.app.mjs"; -import { axios } from "@pipedream/platform"; export default { key: "fractel-send-sms-mms", @@ -9,26 +9,32 @@ export default { type: "action", props: { fractel, - to: fractel.propDefinitions.to, - phoneNumber: fractel.propDefinitions.phoneNumber, - message: { - ...fractel.propDefinitions.message, - optional: true, - }, - media: { - ...fractel.propDefinitions.media, - optional: true, + phoneNumber: { + propDefinition: [ + fractel, + "phoneNumber", + ], + description: "The phone number to send the message to, including country code.", }, - confirmationUrl: { - ...fractel.propDefinitions.confirmationUrl, - optional: true, + to: { + propDefinition: [ + fractel, + "to", + ], }, - confirmationUrlUsername: { - ...fractel.propDefinitions.confirmationUrlUsername, + message: { + propDefinition: [ + fractel, + "message", + ], + description: "The message content for SMS or MMS.", optional: true, }, - confirmationUrlPassword: { - ...fractel.propDefinitions.confirmationUrlPassword, + media: { + propDefinition: [ + fractel, + "media", + ], optional: true, }, }, @@ -36,22 +42,19 @@ export default { if (!this.message && !this.media) { throw new Error("Either message or media must be provided."); } - - const data = { - to: this.to, - from: this.phoneNumber, - message: this.message, - media: this.media, - confirmation_url: this.confirmationUrl, - confirmation_url_username: this.confirmationUrlUsername, - confirmation_url_password: this.confirmationUrlPassword, - }; - - const response = await this.fractel.sendMessage(data); + const response = await this.fractel.sendMessage({ + $, + data: { + to: this.to, + phonenumber: this.phoneNumber, + message: this.message, + media: this.media && parseObject(this.media), + }, + }); $.export("$summary", `Successfully sent ${this.message ? "SMS" - : "MMS"} to ${this.to}`); + : "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 ee4d33a8a2234..c794094702dfb 100644 --- a/components/fractel/fractel.app.mjs +++ b/components/fractel/fractel.app.mjs @@ -7,7 +7,11 @@ export default { phoneNumber: { type: "string", label: "Phone Number", - description: "The phone number to call or send the message to, including country code.", + description: "The phone number to call to, including country code.", + async options() { + const { fonenumbers } = await this.listPhoneNumbers(); + return fonenumbers.map(({ phonenumber }) => phonenumber); + }, }, to: { type: "string", @@ -17,30 +21,12 @@ export default { message: { type: "string", label: "Message", - description: "The message content for SMS or MMS.", + description: "The message content for TTS.", }, media: { - type: "string", + type: "string[]", label: "Media URL", - description: "The URL of the media file for MMS.", - optional: true, - }, - confirmationUrl: { - type: "string", - label: "Confirmation URL", - description: "The URL to receive message delivery confirmations.", - optional: true, - }, - confirmationUrlUsername: { - type: "string", - label: "Confirmation URL Username", - description: "The username for HTTP Basic authentication for the confirmation URL.", - optional: true, - }, - confirmationUrlPassword: { - type: "string", - label: "Confirmation URL Password", - description: "The password for HTTP Basic authentication for the confirmation URL.", + description: "List of URL of the media file for MMS.", optional: true, }, }, @@ -48,50 +34,38 @@ export default { _baseUrl() { return "https://api.fonestorm.com/v2"; }, - async _makeRequest(opts = {}) { - const { - $ = this, method = "GET", path, headers, ...otherOpts - } = opts; + _headers() { + return { + token: `${this.$auth.oauth_access_token}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { return axios($, { - ...otherOpts, - method, url: this._baseUrl() + path, - headers: { - ...headers, - Authorization: `Bearer ${this.$auth.api_key}`, - }, + headers: this._headers(), + ...opts, }); }, - async initiateCall({ - phoneNumber, to, message, - }) { + initiateCall(opts = {}) { return this._makeRequest({ method: "POST", path: "/calls", - data: { - from: phoneNumber, - to, - message, - }, + ...opts, }); }, - async sendMessage({ - to, message, media, confirmationUrl, confirmationUrlUsername, confirmationUrlPassword, - }) { - const data = { - to, - message, - }; - if (media) data.media = media; - if (confirmationUrl) { - data.confirmation_url = confirmationUrl; - if (confirmationUrlUsername) data.confirmation_url_username = confirmationUrlUsername; - if (confirmationUrlPassword) data.confirmation_url_password = confirmationUrlPassword; - } + listPhoneNumbers(opts = {}) { + return this._makeRequest({ + path: "/phonenumbers", + ...opts, + }); + }, + sendMessage(opts = {}) { return this._makeRequest({ method: "POST", path: "/messages/send", - data, + ...opts, }); }, }, diff --git a/components/fractel/package.json b/components/fractel/package.json index e1163dfe73a60..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" } }