Skip to content

Commit 164df46

Browse files
committed
[Components] openphone #14493
Sources - New Call Recording Completed (Instant) - New Outgoing Call Completed (Instant) - New Incoming Call Completed (Instant) Actions - Send Message - Create Contact - Update Contact
1 parent ac29641 commit 164df46

File tree

15 files changed

+384
-475
lines changed

15 files changed

+384
-475
lines changed
Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { parseObject } from "../../common/utils.mjs";
12
import openphone from "../../openphone.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "openphone-create-contact",
@@ -10,61 +10,71 @@ export default {
1010
props: {
1111
openphone,
1212
firstName: {
13-
type: "string",
14-
label: "First Name",
15-
description: "The contact's first name.",
13+
propDefinition: [
14+
openphone,
15+
"firstName",
16+
],
1617
},
1718
lastName: {
18-
type: "string",
19-
label: "Last Name",
20-
description: "The contact's last name.",
19+
propDefinition: [
20+
openphone,
21+
"lastName",
22+
],
2123
optional: true,
2224
},
2325
company: {
24-
type: "string",
25-
label: "Company",
26-
description: "The contact's company name.",
26+
propDefinition: [
27+
openphone,
28+
"company",
29+
],
2730
optional: true,
2831
},
2932
role: {
30-
type: "string",
31-
label: "Role",
32-
description: "The contact's role.",
33+
propDefinition: [
34+
openphone,
35+
"role",
36+
],
3337
optional: true,
3438
},
3539
emails: {
36-
type: "string[]",
37-
label: "Emails",
38-
description: "Array of contact's emails.",
40+
propDefinition: [
41+
openphone,
42+
"emails",
43+
],
3944
optional: true,
4045
},
4146
phoneNumbers: {
42-
type: "string[]",
43-
label: "Phone Numbers",
44-
description: "Array of contact's phone numbers.",
47+
propDefinition: [
48+
openphone,
49+
"phoneNumbers",
50+
],
4551
optional: true,
4652
},
4753
customFields: {
48-
type: "string[]",
49-
label: "Custom Fields",
50-
description: "Array of custom fields for the contact.",
54+
propDefinition: [
55+
openphone,
56+
"customFields",
57+
],
5158
optional: true,
5259
},
5360
},
5461
async run({ $ }) {
55-
const data = {
56-
firstName: this.firstName,
57-
lastName: this.lastName,
58-
company: this.company,
59-
role: this.role,
60-
emails: this.emails,
61-
phoneNumbers: this.phoneNumbers,
62-
customFields: this.customFields,
63-
};
62+
const response = await this.openphone.createContact({
63+
$,
64+
data: {
65+
defaultFields: {
66+
firstName: this.firstName,
67+
lastName: this.lastName,
68+
company: this.company,
69+
role: this.role,
70+
emails: parseObject(this.emails),
71+
phoneNumbers: parseObject(this.phoneNumbers),
72+
},
73+
customFields: parseObject(this.customFields),
74+
},
75+
});
6476

65-
const response = await this.openphone.createContact(data);
66-
67-
$.export("$summary", `Successfully created contact with ID: ${response.id}`);
77+
$.export("$summary", `Successfully created contact with ID: ${response.data.id}`);
6878
return response;
6979
},
7080
};
Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { ConfigurationError } from "@pipedream/platform";
12
import openphone from "../../openphone.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "openphone-send-message",
66
name: "Send a Text Message via OpenPhone",
77
description: "Send a text message from your OpenPhone number to a recipient. [See the documentation](https://www.openphone.com/docs/api-reference/messages/send-a-text-message)",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
openphone,
@@ -16,41 +16,42 @@ export default {
1616
],
1717
},
1818
to: {
19-
propDefinition: [
20-
openphone,
21-
"to",
22-
],
19+
type: "string",
20+
label: "To",
21+
description: "Recipient phone number in E.164 format.",
2322
},
2423
content: {
25-
propDefinition: [
26-
openphone,
27-
"content",
28-
],
29-
},
30-
userId: {
31-
propDefinition: [
32-
openphone,
33-
"userId",
34-
],
35-
optional: true,
36-
},
37-
setInboxStatus: {
38-
propDefinition: [
39-
openphone,
40-
"setInboxStatus",
41-
],
42-
optional: true,
24+
type: "string",
25+
label: "Content",
26+
description: "The text content of the message to be sent.",
4327
},
4428
},
4529
async run({ $ }) {
46-
const response = await this.openphone.sendTextMessage({
47-
from: this.from,
48-
to: this.to,
49-
content: this.content,
50-
userId: this.userId,
51-
setInboxStatus: this.setInboxStatus,
52-
});
53-
$.export("$summary", `Successfully sent message to ${this.to}`);
54-
return response;
30+
try {
31+
const response = await this.openphone.sendTextMessage({
32+
$,
33+
data: {
34+
content: this.content,
35+
from: this.from,
36+
to: [
37+
this.to,
38+
],
39+
setInboxStatus: "done",
40+
},
41+
});
42+
$.export("$summary", `Successfully sent message to ${this.to}`);
43+
return response;
44+
45+
} catch ({ response }) {
46+
let errorMessage = "";
47+
48+
if (response.data.errors) {
49+
errorMessage = `Prop: ${response.data.errors[0].path} - ${response.data.errors[0].message}`;
50+
} else {
51+
errorMessage = response.data.message;
52+
}
53+
54+
throw new ConfigurationError(errorMessage);
55+
}
5556
},
5657
};
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1+
import { parseObject } from "../../common/utils.mjs";
12
import openphone from "../../openphone.app.mjs";
23

34
export default {
45
key: "openphone-update-contact",
56
name: "Update Contact",
67
description: "Update an existing contact on OpenPhone. [See the documentation](https://www.openphone.com/docs/api-reference/contacts/update-a-contact-by-id)",
7-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
89
type: "action",
910
props: {
1011
openphone,
1112
contactId: {
12-
propDefinition: [
13-
openphone,
14-
"contactId",
15-
],
13+
type: "string",
14+
label: "Contact ID",
15+
description: "The unique identifier of the contact.",
1616
},
1717
firstName: {
1818
propDefinition: [
@@ -65,17 +65,21 @@ export default {
6565
},
6666
},
6767
async run({ $ }) {
68-
const data = {
69-
firstName: this.firstName,
70-
lastName: this.lastName,
71-
company: this.company,
72-
role: this.role,
73-
emails: this.emails,
74-
phoneNumbers: this.phoneNumbers,
75-
customFields: this.customFields,
76-
};
77-
78-
const response = await this.openphone.updateContact(this.contactId, data);
68+
const response = await this.openphone.updateContact({
69+
$,
70+
contactId: this.contactId,
71+
data: {
72+
defaultFields: {
73+
firstName: this.firstName,
74+
lastName: this.lastName,
75+
company: this.company,
76+
role: this.role,
77+
emails: parseObject(this.emails),
78+
phoneNumbers: parseObject(this.phoneNumbers),
79+
},
80+
customFields: parseObject(this.customFields),
81+
},
82+
});
7983

8084
$.export("$summary", `Successfully updated contact with ID ${this.contactId}`);
8185
return response;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
let parsedObj = obj;
5+
if (typeof obj === "string") {
6+
try {
7+
parsedObj = JSON.parse(obj);
8+
} catch (e) {
9+
return obj;
10+
}
11+
}
12+
13+
if (Array.isArray(parsedObj)) {
14+
return parsedObj.map((item) => parseObject(item));
15+
}
16+
if (typeof parsedObj === "object") {
17+
for (const [
18+
key,
19+
value,
20+
] of Object.entries(parsedObj)) {
21+
parsedObj[key] = parseObject(value);
22+
}
23+
}
24+
25+
return parsedObj;
26+
};

0 commit comments

Comments
 (0)