Skip to content

Commit aba3eb5

Browse files
authored
OpenPhone Usability Audit (#16165)
* updates * pnpm-lock.yaml * pnpm-lock.yaml
1 parent 7733832 commit aba3eb5

File tree

15 files changed

+97
-66
lines changed

15 files changed

+97
-66
lines changed

components/bettercontact/bettercontact.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/bytebot/bytebot.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/notiff/notiff.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/openphone/actions/create-contact/create-contact.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "openphone-create-contact",
66
name: "Create Contact",
77
description: "Create a new contact in OpenPhone. [See the documentation](https://www.openphone.com/docs/api-reference/contacts/create-a-contact)",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
openphone,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import openphone from "../../openphone.app.mjs";
2+
3+
export default {
4+
key: "openphone-list-phone-numbers",
5+
name: "List Phone Numbers",
6+
description: "Retrieve the list of phone numbers and users associated with your OpenPhone workspace. [See the documentation](https://www.openphone.com/docs/mdx/api-reference/phone-numbers/list-phone-numbers)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
openphone,
11+
},
12+
async run({ $ }) {
13+
const { data } = await this.openphone.listPhoneNumbers({
14+
$,
15+
});
16+
if (data?.length) {
17+
$.export("$summary", `Successfully retrieved ${data.length} phone number${data.length === 1
18+
? ""
19+
: "s"}`);
20+
}
21+
return data;
22+
},
23+
};
Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { ConfigurationError } from "@pipedream/platform";
21
import openphone from "../../openphone.app.mjs";
32

43
export default {
54
key: "openphone-send-message",
6-
name: "Send a Text Message via OpenPhone",
5+
name: "Send a Text Message",
76
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.1",
7+
version: "0.0.2",
98
type: "action",
109
props: {
1110
openphone,
@@ -27,31 +26,18 @@ export default {
2726
},
2827
},
2928
async run({ $ }) {
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-
}
29+
const response = await this.openphone.sendTextMessage({
30+
$,
31+
data: {
32+
content: this.content,
33+
from: this.from,
34+
to: [
35+
this.to,
36+
],
37+
setInboxStatus: "done",
38+
},
39+
});
40+
$.export("$summary", `Successfully sent message to ${this.to}`);
41+
return response;
5642
},
5743
};

components/openphone/actions/update-contact/update-contact.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ export default {
55
key: "openphone-update-contact",
66
name: "Update Contact",
77
description: "Update an existing contact on OpenPhone. [See the documentation](https://www.openphone.com/docs/api-reference/contacts/update-a-contact-by-id)",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
openphone,
1212
contactId: {
1313
type: "string",
1414
label: "Contact ID",
15-
description: "The unique identifier of the contact.",
15+
description: "The unique identifier of the contact",
1616
},
1717
firstName: {
1818
propDefinition: [

components/openphone/openphone.app.mjs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { axios } from "@pipedream/platform";
1+
import {
2+
axios, ConfigurationError,
3+
} from "@pipedream/platform";
4+
import Bottleneck from "bottleneck";
5+
const limiter = new Bottleneck({
6+
minTime: 100, // 10 requests per seconds (https://www.openphone.com/docs/mdx/api-reference/rate-limits)
7+
maxConcurrent: 1,
8+
});
9+
const axiosRateLimiter = limiter.wrap(axios);
210

311
export default {
412
type: "app",
@@ -10,51 +18,53 @@ export default {
1018
description: "The sender's phone number. Can be either your OpenPhone phone number ID or the full phone number in E.164 format.",
1119
async options() {
1220
const { data } = await this.listPhoneNumbers();
13-
return data.map(({
21+
return data?.map(({
1422
id: value, name, formattedNumber,
1523
}) => ({
16-
label: `${name} - ${formattedNumber}`,
24+
label: name && formattedNumber
25+
? `${name} - ${formattedNumber}`
26+
: value,
1727
value,
18-
}));
28+
})) || [];
1929
},
2030
},
2131
firstName: {
2232
type: "string",
2333
label: "First Name",
24-
description: "The contact's first name.",
34+
description: "The contact's first name",
2535
},
2636
lastName: {
2737
type: "string",
2838
label: "Last Name",
29-
description: "The contact's last name.",
39+
description: "The contact's last name",
3040
optional: true,
3141
},
3242
company: {
3343
type: "string",
3444
label: "Company",
35-
description: "The contact's company name.",
45+
description: "The contact's company name",
3646
optional: true,
3747
},
3848
role: {
3949
type: "string",
4050
label: "Role",
41-
description: "The contact's role.",
51+
description: "The contact's role",
4252
optional: true,
4353
},
4454
emails: {
4555
type: "string[]",
4656
label: "Emails",
47-
description: "Array of objects of contact's emails. **Example:** `{\"name\": \"Company Email\", \"value\": \"[email protected]\"}`.",
57+
description: "Array of objects of contact's emails. **Example:** `{\"name\": \"Company Email\", \"value\": \"[email protected]\"}`",
4858
},
4959
phoneNumbers: {
5060
type: "string[]",
5161
label: "Phone Numbers",
52-
description: "Array of objects of contact's phone numbers. **Example:** `{\"name\": \"Company Phone\", \"value\": \"+12345678901\"}`.",
62+
description: "Array of objects of contact's phone numbers. **Example:** `{\"name\": \"Company Phone\", \"value\": \"+12345678901\"}`",
5363
},
5464
customFields: {
5565
type: "string[]",
5666
label: "Custom Fields",
57-
description: "Array of objects of custom fields for the contact. **Example:** `{\"key\": \"inbound-lead\", \"value\": \"[\"option1\", \"option2\"]\"}`.",
67+
description: "Array of objects of custom fields for the contact. **Example:** `{\"key\": \"inbound-lead\", \"value\": [\"option1\", \"option2\"]}`",
5868
},
5969
},
6070
methods: {
@@ -66,14 +76,22 @@ export default {
6676
Authorization: `${this.$auth.api_key}`,
6777
};
6878
},
69-
_makeRequest({
79+
async _makeRequest({
7080
$ = this, path, ...opts
7181
}) {
72-
return axios($, {
73-
url: this._baseUrl() + path,
74-
headers: this._headers(),
75-
...opts,
76-
});
82+
try {
83+
return await axiosRateLimiter($, {
84+
url: this._baseUrl() + path,
85+
headers: this._headers(),
86+
...opts,
87+
});
88+
} catch ({ response }) {
89+
const errorMessage = response?.data?.errors
90+
? `Prop: ${response.data.errors[0].path} - ${response.data.errors[0].message}`
91+
: response?.data?.message;
92+
93+
throw new ConfigurationError(errorMessage);
94+
}
7795
},
7896
listPhoneNumbers(opts = {}) {
7997
return this._makeRequest({

components/openphone/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/openphone",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream OpenPhone Components",
55
"main": "openphone.app.mjs",
66
"keywords": [
@@ -13,6 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^3.0.3"
16+
"@pipedream/platform": "^3.0.3",
17+
"bottleneck": "^2.19.5"
1718
}
1819
}

components/openphone/sources/common/base.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export default {
1212
],
1313
type: "string[]",
1414
label: "Resource IDs",
15-
description: "The unique identifiers of phone numbers associated with the webhook.",
15+
description: "The IDs of the incoming or outgoing phone numbers to retrieve events for. Use the List Phone Numbers action to retrieve information about phone numbers.",
1616
optional: true,
1717
},
1818
label: {
1919
type: "string",
2020
label: "Label",
21-
description: "Webhook's label",
21+
description: "A label to identify the webhook",
2222
optional: true,
2323
},
2424
},

0 commit comments

Comments
 (0)