Skip to content

Commit 04c6c45

Browse files
committed
Adjustments
1 parent 25fe015 commit 04c6c45

File tree

3 files changed

+155
-153
lines changed

3 files changed

+155
-153
lines changed
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
import yay_com from "../../app/yay_com.app.mjs";
1+
import yay_com from "../../yay_com.app.mjs";
22

33
export default {
44
key: "yay_com-get-documents",
55
name: "Get Documents",
6-
description: "Retrieves a list of documents. [See documentation](https://www.yay.com/voip/api-docs/account/document/)",
6+
description:
7+
"Retrieves a list of documents. [See documentation](https://www.yay.com/voip/api-docs/account/document/)",
78
version: "0.0.1",
89
type: "action",
910
props: {
1011
yay_com,
1112
},
1213
async run({ $ }) {
13-
const response = await this.yay_com.listDocuments($);
14-
const documents = response.data || [];
15-
$.export("$summary", `Successfully retrieved ${documents.length} document(s)`);
14+
const response = await this.yay_com.listDocuments({
15+
$,
16+
});
17+
const { length } = response;
18+
$.export(
19+
"$summary",
20+
`Successfully retrieved ${length} document${length === 1
21+
? ""
22+
: "s"}`,
23+
);
1624
return response;
1725
},
1826
};

components/yay_com/app/yay_com.app.mjs

Lines changed: 0 additions & 144 deletions
This file was deleted.

components/yay_com/yay_com.app.mjs

Lines changed: 142 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,149 @@
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",
10+
description: "The SIP user to make the outbound call for",
11+
async options() {
12+
const { result } = await this.listSipUsers();
13+
return result?.map(({
14+
uuid: value, display_name, user_name,
15+
}) => ({
16+
label: display_name || user_name,
17+
value,
18+
})) || [];
19+
},
20+
},
21+
sipUsers: {
22+
type: "string[]",
23+
label: "SIP Users",
24+
description: "List of SIP users who will receive the outbound call request",
25+
optional: true,
26+
async options() {
27+
const { result } = await this.listSipUsers();
28+
return result?.map(({
29+
uuid: value, display_name, user_name,
30+
}) => ({
31+
label: display_name || user_name,
32+
value,
33+
})) || [];
34+
},
35+
},
36+
huntGroups: {
37+
type: "string[]",
38+
label: "Hunt Groups",
39+
description: "List of hunt groups who will receive the outbound call request",
40+
optional: true,
41+
async options() {
42+
const { result } = await this.listHuntGroups();
43+
return result?.map(({
44+
uuid: value, name: label,
45+
}) => ({
46+
label,
47+
value,
48+
})) || [];
49+
},
50+
},
51+
destination: {
52+
type: "string",
53+
label: "Destination",
54+
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.",
55+
},
56+
displayName: {
57+
type: "string",
58+
label: "Display Name",
59+
description: "What display name should be sent to the user, this will show as the name on their phone (where supported)",
60+
optional: true,
61+
},
62+
},
563
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
64+
_getBaseUrl() {
65+
return `https://${this.$auth.api_hostname}`;
66+
},
67+
_getHeaders() {
68+
return {
69+
"x-auth-reseller": `${this.$auth.reseller}`,
70+
"x-auth-user": `${this.$auth.user}`,
71+
"x-auth-password": `${this.$auth.password}`,
72+
};
73+
},
74+
async _makeRequest({
75+
$ = this,
76+
path,
77+
headers,
78+
...args
79+
}) {
80+
const response = await axios($, {
81+
url: `${this._getBaseUrl()}${path}`,
82+
headers: {
83+
...headers,
84+
...this._getHeaders(),
85+
},
86+
...args,
87+
});
88+
return response.result;
89+
},
90+
async listSipUsers(args) {
91+
return this._makeRequest({
92+
path: "/voip/user",
93+
...args,
94+
});
95+
},
96+
async listHuntGroups(args) {
97+
return this._makeRequest({
98+
path: "/voip/group",
99+
...args,
100+
});
101+
},
102+
async listPhoneBooks(args) {
103+
return this._makeRequest({
104+
path: "/phone-book",
105+
...args,
106+
});
107+
},
108+
async listDocuments(args) {
109+
return this._makeRequest({
110+
path: "/account/document",
111+
...args,
112+
});
113+
},
114+
async createOutboundCall({
115+
$,
116+
userUuid,
117+
destination,
118+
displayName,
119+
sipUsers = [],
120+
huntGroups = [],
121+
}) {
122+
// Combine sipUsers and huntGroups into the targets array
123+
const targets = [
124+
...sipUsers.map((uuid) => ({
125+
type: "sipuser",
126+
uuid,
127+
})),
128+
...huntGroups.map((uuid) => ({
129+
type: "huntgroup",
130+
uuid,
131+
})),
132+
];
133+
134+
return this._makeRequest({
135+
$,
136+
method: "POST",
137+
path: "/calls/outbound",
138+
data: {
139+
user_uuid: userUuid,
140+
destination,
141+
display_name: displayName,
142+
...(targets.length > 0 && {
143+
targets,
144+
}),
145+
},
146+
});
9147
},
10148
},
11149
};

0 commit comments

Comments
 (0)