|
| 1 | +import { axios } from "@pipedream/platform"; |
| 2 | + |
1 | 3 | export default { |
2 | 4 | type: "app", |
3 | 5 | 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 | + }, |
5 | 63 | 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 | + }); |
9 | 147 | }, |
10 | 148 | }, |
11 | 149 | }; |
0 commit comments