Skip to content

Commit 35607f0

Browse files
authored
Yay.com new components (#17354)
* pnpm * Yay.com new actions * Adjustments * Adjustments * Adding polling source * Adjustments * Adding source deploy + package bump * pnpm * Description updates
1 parent 68a3ffe commit 35607f0

File tree

8 files changed

+371
-7
lines changed

8 files changed

+371
-7
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import yayCom from "../../yay_com.app.mjs";
3+
4+
export default {
5+
key: "yay_com-create-outbound-call",
6+
name: "Create Outbound Call",
7+
description: "Initiates an outbound call to a specified number. [See the documentation](https://www.yay.com/voip/api-docs/calls/outbound-call/)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
yayCom,
12+
userUuid: {
13+
propDefinition: [
14+
yayCom,
15+
"sipUser",
16+
],
17+
},
18+
destination: {
19+
propDefinition: [
20+
yayCom,
21+
"destination",
22+
],
23+
},
24+
displayName: {
25+
propDefinition: [
26+
yayCom,
27+
"displayName",
28+
],
29+
},
30+
sipUsers: {
31+
propDefinition: [
32+
yayCom,
33+
"sipUser",
34+
],
35+
label: "Target SIP Users",
36+
type: "string[]",
37+
description: "One or more SIP users who will receive the outbound call request",
38+
optional: true,
39+
},
40+
huntGroups: {
41+
propDefinition: [
42+
yayCom,
43+
"huntGroups",
44+
],
45+
},
46+
},
47+
async run({ $ }) {
48+
// Combine sipUsers and huntGroups into the targets array
49+
const targets = [
50+
...(this.sipUsers?.map((uuid) => ({
51+
type: "sipuser",
52+
uuid,
53+
})) || []),
54+
...(this.huntGroups?.map((uuid) => ({
55+
type: "huntgroup",
56+
uuid,
57+
})) || []),
58+
];
59+
60+
if (!targets.length) {
61+
throw new ConfigurationError("Please provide at least one target (SIP user or hunt group)");
62+
}
63+
64+
const response = await this.yayCom.createOutboundCall({
65+
$,
66+
data: {
67+
user_uuid: this.userUuid,
68+
destination: this.destination,
69+
display_name: this.displayName,
70+
targets,
71+
},
72+
});
73+
74+
$.export("$summary", `Successfully initiated outbound call to ${this.destination}`);
75+
return response;
76+
},
77+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import yayCom from "../../yay_com.app.mjs";
2+
3+
export default {
4+
key: "yay_com-get-documents",
5+
name: "Get Documents",
6+
description:
7+
"Retrieves all documents available. [See the documentation](https://www.yay.com/voip/api-docs/account/document/)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
yayCom,
12+
},
13+
async run({ $ }) {
14+
const response = await this.yayCom.listDocuments({
15+
$,
16+
});
17+
const { length } = response;
18+
$.export(
19+
"$summary",
20+
`Successfully retrieved ${length} document${length === 1
21+
? ""
22+
: "s"}`,
23+
);
24+
return response;
25+
},
26+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import yayCom from "../../yay_com.app.mjs";
2+
3+
export default {
4+
key: "yay_com-get-phone-books",
5+
name: "Get Phone Books",
6+
description: "Retrieves all phone books available. [See the documentation](https://www.yay.com/voip/api-docs/phone-books/phone-book/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
yayCom,
11+
},
12+
async run({ $ }) {
13+
const response = await this.yayCom.listPhoneBooks({
14+
$,
15+
});
16+
const { length } = response;
17+
$.export("$summary", `Successfully retrieved ${length} phone book${length === 1
18+
? ""
19+
: "s"}`);
20+
return response;
21+
},
22+
};

components/yay_com/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/yay_com",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Yay.com Components",
55
"main": "yay_com.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import yayCom from "../../yay_com.app.mjs";
3+
4+
export default {
5+
props: {
6+
yayCom,
7+
db: "$.service.db",
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
13+
},
14+
},
15+
methods: {
16+
_getSavedIds() {
17+
return this.db.get("savedIds") || [];
18+
},
19+
_setSavedIds(ids) {
20+
this.db.set("savedIds", ids);
21+
},
22+
async startEvent(maxItems) {
23+
const savedIds = this._getSavedIds();
24+
const items = await this.getItems(savedIds);
25+
26+
const newIds = [];
27+
for (const item of items) {
28+
const id = this.getItemId(item);
29+
if (!savedIds.includes(id)) {
30+
const meta = this.generateMeta(item);
31+
if (maxItems === undefined || (typeof maxItems === "number" && --maxItems >= 0)) {
32+
this.$emit(item, meta);
33+
}
34+
newIds.push(id);
35+
}
36+
}
37+
38+
if (newIds.length > 0) {
39+
// Keep only the most recent IDs to prevent the array from growing indefinitely
40+
const ids = [
41+
...savedIds,
42+
...newIds,
43+
].slice(-100);
44+
this._setSavedIds(ids);
45+
}
46+
},
47+
},
48+
async run() {
49+
await this.startEvent();
50+
},
51+
hooks: {
52+
async deploy() {
53+
await this.startEvent(5);
54+
},
55+
},
56+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import common from "../common/polling.mjs";
2+
3+
export default {
4+
...common,
5+
key: "yay_com-new-contact-added",
6+
name: "New Contact Added",
7+
description: "Emit new event when a contact is added to a phone book. [See the documentation](https://www.yay.com/voip/api-docs/phone-books/phone-book-contact/)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
...common.props,
13+
phoneBookId: {
14+
propDefinition: [
15+
common.props.yayCom,
16+
"phoneBookId",
17+
],
18+
},
19+
},
20+
methods: {
21+
...common.methods,
22+
generateMeta(contact) {
23+
const name = this.getItemId(contact);
24+
return {
25+
id: name,
26+
summary: `New Contact: ${name}`,
27+
ts: Date.now(),
28+
};
29+
},
30+
getItemId(contact) {
31+
let name = `${contact.first_name} ${contact.last_name}`;
32+
if (!name.trim()) {
33+
name = contact.company_name;
34+
}
35+
return name;
36+
},
37+
async getItems() {
38+
const { phoneBookId } = this;
39+
const contacts = await this.yayCom.listPhoneBookContacts({
40+
phoneBookId,
41+
params: {
42+
sort: "id",
43+
limit: 100,
44+
uuid: phoneBookId,
45+
},
46+
});
47+
return contacts || [];
48+
},
49+
},
50+
};

components/yay_com/yay_com.app.mjs

Lines changed: 130 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,137 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "yay_com",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
sipUser: {
8+
type: "string",
9+
label: "SIP User ID",
10+
description: "The SIP user to make the outbound call for",
11+
async options() {
12+
const users = await this.listSipUsers();
13+
return users?.map(({
14+
uuid: value, display_name, user_name,
15+
}) => ({
16+
label: display_name || user_name,
17+
value,
18+
})) || [];
19+
},
20+
},
21+
huntGroups: {
22+
type: "string[]",
23+
label: "Target Hunt Groups",
24+
description: "One or more hunt groups who will receive the outbound call request",
25+
optional: true,
26+
async options() {
27+
const groups = await this.listHuntGroups();
28+
return groups?.map(({
29+
uuid: value, name: label,
30+
}) => ({
31+
label,
32+
value,
33+
})) || [];
34+
},
35+
},
36+
phoneBookId: {
37+
type: "string",
38+
label: "Phone Book",
39+
description: "The phone book to monitor for new contacts",
40+
async options() {
41+
const books = await this.listPhoneBooks();
42+
return books?.map(({
43+
uuid: value, name: label,
44+
}) => ({
45+
label,
46+
value,
47+
})) || [];
48+
},
49+
},
50+
destination: {
51+
type: "string",
52+
label: "Destination",
53+
description: "The destination phone number to call (in E164 format for outbound calls). You may also provide extension numbers of your hunt groups, users and call routes.",
54+
},
55+
displayName: {
56+
type: "string",
57+
label: "Display Name",
58+
description: "What display name should be sent to the user, this will show as the name on their phone (where supported)",
59+
optional: true,
60+
},
61+
},
562
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
63+
_getBaseUrl() {
64+
return `https://${this.$auth.api_hostname}`;
65+
},
66+
_getHeaders() {
67+
return {
68+
"x-auth-reseller": `${this.$auth.reseller}`,
69+
"x-auth-user": `${this.$auth.user}`,
70+
"x-auth-password": `${this.$auth.password}`,
71+
};
72+
},
73+
async _makeRequest({
74+
$ = this,
75+
path,
76+
headers,
77+
...args
78+
}) {
79+
const response = await axios($, {
80+
url: `${this._getBaseUrl()}${path}`,
81+
headers: {
82+
...headers,
83+
...this._getHeaders(),
84+
},
85+
...args,
86+
});
87+
return response.result;
88+
},
89+
async listSipUsers(args) {
90+
return this._makeRequest({
91+
path: "/voip/user",
92+
...args,
93+
});
94+
},
95+
async listHuntGroups(args) {
96+
return this._makeRequest({
97+
path: "/voip/group",
98+
...args,
99+
});
100+
},
101+
async listPhoneBooks(args) {
102+
return this._makeRequest({
103+
path: "/voip/phone-book",
104+
...args,
105+
});
106+
},
107+
async listPhoneBookContacts({
108+
phoneBookId, ...args
109+
}) {
110+
return this._makeRequest({
111+
path: `/voip/phone-book/${phoneBookId}`,
112+
...args,
113+
});
114+
},
115+
async listMailboxMessages({
116+
mailboxId, ...args
117+
}) {
118+
return this._makeRequest({
119+
path: `/voip/mailbox/${mailboxId}/messages`,
120+
...args,
121+
});
122+
},
123+
async listDocuments(args) {
124+
return this._makeRequest({
125+
path: "/account/document",
126+
...args,
127+
});
128+
},
129+
async createOutboundCall(args) {
130+
return this._makeRequest({
131+
method: "POST",
132+
path: "/calls/outbound",
133+
...args,
134+
});
9135
},
10136
},
11137
};

0 commit comments

Comments
 (0)