Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Components - fractel #11807

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions components/fractel/actions/call-phone/call-phone.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
60 changes: 60 additions & 0 deletions components/fractel/actions/send-sms-mms/send-sms-mms.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
22 changes: 22 additions & 0 deletions components/fractel/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -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;
};
71 changes: 66 additions & 5 deletions components/fractel/fractel.app.mjs
Original file line number Diff line number Diff line change
@@ -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,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/fractel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/fractel",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream FracTEL Components",
"main": "fractel.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.5"
}
}
}
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading