@xapp/stentor-service-housecall-pro 1.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ ## @xapp/stentor-service-housecall-pro
2
+
3
+ Implementation of CrmService for Housecall Pro
4
+
5
+ ### Required Variables
6
+ HOUSECALL_PRO_API_KEY
7
+
8
+ ### Documentation
9
+ - [Housecall Pro v1 API](https://docs.housecallpro.com/docs/housecall-public-api/a4ca20a18010c-housecall-v1-api)
@@ -0,0 +1,25 @@
1
+ /*! Copyright (c) 2024, XAPP AI */
2
+ import { FetchService } from "stentor-service-fetch";
3
+ import { BaseService, CrmResponse, CrmService, ExternalLead } from "stentor-models";
4
+ import { HouseCallProResponse, CustomerQuery, HouseCallProCustomer, HouseCallProExternalLeadExtras } from "./models";
5
+ export interface HouseCallProServiceProps extends BaseService {
6
+ appId: string;
7
+ channel?: string;
8
+ apiToken?: string;
9
+ }
10
+ export declare class HouseCallProService extends FetchService implements CrmService {
11
+ private props;
12
+ constructor(props: HouseCallProServiceProps);
13
+ send(externalLead: ExternalLead, extras?: HouseCallProExternalLeadExtras): Promise<CrmResponse>;
14
+ getCustomers(query: CustomerQuery, page?: number): Promise<HouseCallProResponse>;
15
+ addCustomer(customer: HouseCallProCustomer): Promise<HouseCallProResponse>;
16
+ addLead(customer: HouseCallProCustomer): Promise<HouseCallProResponse>;
17
+ addLeadSource(leadSourceName: string): Promise<HouseCallProResponse>;
18
+ getLeadSources(page?: number): Promise<HouseCallProResponse>;
19
+ getJobTypes(page?: number): Promise<HouseCallProResponse>;
20
+ getJobs(page?: number): Promise<HouseCallProResponse>;
21
+ getLeads(page?: number): Promise<HouseCallProResponse>;
22
+ getCompany(): Promise<HouseCallProResponse>;
23
+ getScheduleWindows(): Promise<HouseCallProResponse>;
24
+ getBookingWindows(): Promise<HouseCallProResponse>;
25
+ }
@@ -0,0 +1,373 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.HouseCallProService = void 0;
16
+ /*! Copyright (c) 2024, XAPP AI */
17
+ const stentor_service_fetch_1 = require("stentor-service-fetch");
18
+ const stentor_logger_1 = require("stentor-logger");
19
+ const axios_1 = __importDefault(require("axios"));
20
+ const base_url = "https://api.housecallpro.com/";
21
+ const lead_source = process.env.HOUSECALL_PRO_LEADSOURCE ? process.env.HOUSECALL_PRO_LEADSOURCE : "XAPP AI";
22
+ const util_1 = require("./util");
23
+ class HouseCallProService extends stentor_service_fetch_1.FetchService {
24
+ constructor(props) {
25
+ super(props);
26
+ this.props = Object.assign({ apiToken: process.env.HOUSECALL_PRO_API_KEY }, props);
27
+ if (!this.props.channel) {
28
+ this.props.channel = "Chat";
29
+ }
30
+ }
31
+ // Send the lead or scheduling request
32
+ send(externalLead, extras) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ var _a, _b, _c, _d, _e, _f, _g;
35
+ const customerQuery = {};
36
+ const crmResponse = {
37
+ status: "Failure",
38
+ message: ""
39
+ };
40
+ try {
41
+ let transcript = "";
42
+ (_a = externalLead.transcript) === null || _a === void 0 ? void 0 : _a.forEach((x) => (transcript += `${x.from.id != this.props.appId && x.from.id != "bot" ? "user: " : this.props.appId + ": "} ${x.message} \n`));
43
+ const firstName = (_b = externalLead.fields.find((x) => x.name == "FIRST_NAME")) === null || _b === void 0 ? void 0 : _b.value;
44
+ const lastName = (_c = externalLead.fields.find((x) => x.name == "LAST_NAME")) === null || _c === void 0 ? void 0 : _c.value;
45
+ const address = (_d = externalLead.fields.find((x) => x.name == "ADDRESS")) === null || _d === void 0 ? void 0 : _d.value;
46
+ const phone = (_e = externalLead.fields.find((x) => x.name == "PHONE")) === null || _e === void 0 ? void 0 : _e.value;
47
+ const email = (_f = externalLead.fields.find((x) => x.name == "EMAIL")) === null || _f === void 0 ? void 0 : _f.value;
48
+ const message = (_g = externalLead.fields.find((x) => x.name == "MESSAGE")) === null || _g === void 0 ? void 0 : _g.value;
49
+ let parsedAddress;
50
+ try {
51
+ parsedAddress = yield (0, util_1.parseAddress)(address);
52
+ }
53
+ catch (err) {
54
+ (0, stentor_logger_1.log)().error(`Housecall Pro: Invalid address "${address}"`);
55
+ }
56
+ const crmRequest = {
57
+ first_name: firstName,
58
+ last_name: lastName,
59
+ mobile_number: phone,
60
+ email,
61
+ notes: message,
62
+ note: transcript,
63
+ lead_source
64
+ };
65
+ if (util_1.parseAddress) {
66
+ crmRequest.addresses = [];
67
+ crmRequest.addresses.push({
68
+ street: parsedAddress.addressLine1,
69
+ city: parsedAddress.placeName,
70
+ state: parsedAddress.stateAbbreviation,
71
+ zip: parsedAddress.zipCode,
72
+ country: "USA"
73
+ });
74
+ }
75
+ // Check if customer exists
76
+ if (phone) {
77
+ customerQuery.phone = phone;
78
+ }
79
+ if (email) {
80
+ customerQuery.email = email;
81
+ }
82
+ const customerMatches = yield this.getCustomers(customerQuery);
83
+ // Customer exists, use this account
84
+ if (customerMatches.data.total_items) {
85
+ crmRequest.customer_id = customerMatches.data.customers[0].id;
86
+ yield this.addLead(crmRequest);
87
+ }
88
+ else {
89
+ yield this.addCustomer(crmRequest);
90
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () {
91
+ const newCustomer = yield this.getCustomers(customerQuery);
92
+ crmRequest.customer_id = newCustomer.data.customers[0].id;
93
+ yield this.addLead(crmRequest);
94
+ }), 2000);
95
+ }
96
+ crmResponse.status = "Success";
97
+ }
98
+ catch (err) {
99
+ (0, stentor_logger_1.log)().error(`Housecall Pro: call was a failure: ${err}`);
100
+ crmResponse.message = err;
101
+ }
102
+ return crmResponse;
103
+ });
104
+ }
105
+ getCustomers(query_1) {
106
+ return __awaiter(this, arguments, void 0, function* (query, page = 1) {
107
+ const housecallProResponse = { status: "Failure" };
108
+ let q = "";
109
+ if (query.name)
110
+ q = query.name;
111
+ else if (query.phone)
112
+ q = query.phone;
113
+ else if (query.email)
114
+ q = query.email;
115
+ try {
116
+ const config = {
117
+ method: "get",
118
+ url: `${base_url}customers?q=${q}&page=${page}`,
119
+ headers: {
120
+ Accept: "application/json",
121
+ Authorization: `Token ${this.props.apiToken}`
122
+ }
123
+ };
124
+ const response = yield (0, axios_1.default)(config);
125
+ housecallProResponse.status = "Success";
126
+ housecallProResponse.data = response.data;
127
+ }
128
+ catch (err) {
129
+ (0, stentor_logger_1.log)().error(`HousecallPro: Error searching customers ${err}`);
130
+ housecallProResponse.error = err;
131
+ }
132
+ return housecallProResponse;
133
+ });
134
+ }
135
+ addCustomer(customer) {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ const housecallProResponse = { status: "Failure" };
138
+ try {
139
+ const config = {
140
+ method: "post",
141
+ url: `${base_url}customers`,
142
+ headers: {
143
+ Accept: "application/json",
144
+ Authorization: `Token ${this.props.apiToken}`,
145
+ "Content-Type": "application/json"
146
+ },
147
+ data: JSON.stringify(customer)
148
+ };
149
+ const response = yield (0, axios_1.default)(config);
150
+ housecallProResponse.status = "Success";
151
+ housecallProResponse.data = response.data;
152
+ }
153
+ catch (err) {
154
+ (0, stentor_logger_1.log)().error(`HousecallPro: Error adding customer ${err}`);
155
+ housecallProResponse.error = err;
156
+ }
157
+ return housecallProResponse;
158
+ });
159
+ }
160
+ addLead(customer) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ const housecallProResponse = { status: "Failure" };
163
+ try {
164
+ const config = {
165
+ method: "post",
166
+ url: `${base_url}leads`,
167
+ headers: {
168
+ Accept: "application/json",
169
+ Authorization: `Token ${this.props.apiToken}`,
170
+ "Content-Type": "application/json"
171
+ },
172
+ data: JSON.stringify(customer)
173
+ };
174
+ const response = yield (0, axios_1.default)(config);
175
+ housecallProResponse.status = "Success";
176
+ housecallProResponse.data = response.data;
177
+ }
178
+ catch (err) {
179
+ (0, stentor_logger_1.log)().error(`HousecallPro: Error adding lead ${err}`);
180
+ housecallProResponse.error = err;
181
+ }
182
+ return housecallProResponse;
183
+ });
184
+ }
185
+ addLeadSource(leadSourceName) {
186
+ return __awaiter(this, void 0, void 0, function* () {
187
+ const housecallProResponse = { status: "Failure" };
188
+ try {
189
+ const config = {
190
+ method: "post",
191
+ url: `${base_url}lead_sources`,
192
+ headers: {
193
+ Accept: "application/json",
194
+ Authorization: `Token ${this.props.apiToken}`,
195
+ "Content-Type": "application/json"
196
+ },
197
+ data: JSON.stringify({ name: leadSourceName })
198
+ };
199
+ const response = yield (0, axios_1.default)(config);
200
+ housecallProResponse.status = "Success";
201
+ housecallProResponse.data = response.data;
202
+ }
203
+ catch (err) {
204
+ (0, stentor_logger_1.log)().error(`HousecallPro: Error adding lead source ${err}`);
205
+ housecallProResponse.error = err;
206
+ }
207
+ return housecallProResponse;
208
+ });
209
+ }
210
+ getLeadSources() {
211
+ return __awaiter(this, arguments, void 0, function* (page = 1) {
212
+ const housecallProResponse = { status: "Failure" };
213
+ try {
214
+ const config = {
215
+ method: "get",
216
+ url: `${base_url}lead_sources?page=${page}`,
217
+ headers: {
218
+ Accept: "application/json",
219
+ Authorization: `Token ${this.props.apiToken}`
220
+ }
221
+ };
222
+ const response = yield (0, axios_1.default)(config);
223
+ housecallProResponse.status = "Success";
224
+ housecallProResponse.data = response.data;
225
+ }
226
+ catch (err) {
227
+ (0, stentor_logger_1.log)().error(`HousecallPro: Error getting lead sources ${err}`);
228
+ housecallProResponse.error = err;
229
+ }
230
+ return housecallProResponse;
231
+ });
232
+ }
233
+ getJobTypes() {
234
+ return __awaiter(this, arguments, void 0, function* (page = 1) {
235
+ const housecallProResponse = { status: "Failure" };
236
+ try {
237
+ const config = {
238
+ method: "get",
239
+ url: `${base_url}job_fields/job_types?page=${page}`,
240
+ headers: {
241
+ Accept: "application/json",
242
+ Authorization: `Token ${this.props.apiToken}`
243
+ }
244
+ };
245
+ const response = yield (0, axios_1.default)(config);
246
+ housecallProResponse.status = "Success";
247
+ housecallProResponse.data = response.data;
248
+ }
249
+ catch (err) {
250
+ (0, stentor_logger_1.log)().error(`HousecallPro: Error getting job types ${err}`);
251
+ housecallProResponse.error = err;
252
+ }
253
+ return housecallProResponse;
254
+ });
255
+ }
256
+ getJobs() {
257
+ return __awaiter(this, arguments, void 0, function* (page = 1) {
258
+ const housecallProResponse = { status: "Failure" };
259
+ try {
260
+ const config = {
261
+ method: "get",
262
+ url: `${base_url}jobs?page=${page}`,
263
+ headers: {
264
+ Accept: "application/json",
265
+ Authorization: `Token ${this.props.apiToken}`
266
+ }
267
+ };
268
+ const response = yield (0, axios_1.default)(config);
269
+ housecallProResponse.status = "Success";
270
+ housecallProResponse.data = response.data;
271
+ }
272
+ catch (err) {
273
+ (0, stentor_logger_1.log)().error(`HousecallPro: Error getting jobs ${err}`);
274
+ housecallProResponse.error = err;
275
+ }
276
+ return housecallProResponse;
277
+ });
278
+ }
279
+ getLeads() {
280
+ return __awaiter(this, arguments, void 0, function* (page = 1) {
281
+ const housecallProResponse = { status: "Failure" };
282
+ try {
283
+ const config = {
284
+ method: "get",
285
+ url: `${base_url}leads?page=${page}`,
286
+ headers: {
287
+ Accept: "application/json",
288
+ Authorization: `Token ${this.props.apiToken}`
289
+ }
290
+ };
291
+ const response = yield (0, axios_1.default)(config);
292
+ housecallProResponse.status = "Success";
293
+ housecallProResponse.data = response.data;
294
+ }
295
+ catch (err) {
296
+ (0, stentor_logger_1.log)().error(`HousecallPro: Error getting leads ${err}`);
297
+ housecallProResponse.error = err;
298
+ }
299
+ return housecallProResponse;
300
+ });
301
+ }
302
+ getCompany() {
303
+ return __awaiter(this, void 0, void 0, function* () {
304
+ const housecallProResponse = { status: "Failure" };
305
+ try {
306
+ const config = {
307
+ method: "get",
308
+ url: `${base_url}company`,
309
+ headers: {
310
+ Accept: "application/json",
311
+ Authorization: `Token ${this.props.apiToken}`
312
+ }
313
+ };
314
+ const response = yield (0, axios_1.default)(config);
315
+ housecallProResponse.status = "Success";
316
+ housecallProResponse.data = response.data;
317
+ }
318
+ catch (err) {
319
+ (0, stentor_logger_1.log)().error(`HousecallPro: Error getting company ${err}`);
320
+ housecallProResponse.error = err;
321
+ }
322
+ return housecallProResponse;
323
+ });
324
+ }
325
+ getScheduleWindows() {
326
+ return __awaiter(this, void 0, void 0, function* () {
327
+ const housecallProResponse = { status: "Failure" };
328
+ try {
329
+ const config = {
330
+ method: "get",
331
+ url: `${base_url}company/schedule_availability`,
332
+ headers: {
333
+ Accept: "application/json",
334
+ Authorization: `Token ${this.props.apiToken}`
335
+ }
336
+ };
337
+ const response = yield (0, axios_1.default)(config);
338
+ housecallProResponse.status = "Success";
339
+ housecallProResponse.data = response.data;
340
+ }
341
+ catch (err) {
342
+ (0, stentor_logger_1.log)().error(`HousecallPro: Error getting scheduling windows ${err}`);
343
+ housecallProResponse.error = err;
344
+ }
345
+ return housecallProResponse;
346
+ });
347
+ }
348
+ getBookingWindows() {
349
+ return __awaiter(this, void 0, void 0, function* () {
350
+ const housecallProResponse = { status: "Failure" };
351
+ try {
352
+ const config = {
353
+ method: "get",
354
+ url: `${base_url}company/schedule_availability/booking_windows`,
355
+ headers: {
356
+ Accept: "application/json",
357
+ Authorization: `Token ${this.props.apiToken}`
358
+ }
359
+ };
360
+ const response = yield (0, axios_1.default)(config);
361
+ housecallProResponse.status = "Success";
362
+ housecallProResponse.data = response.data;
363
+ }
364
+ catch (err) {
365
+ (0, stentor_logger_1.log)().error(`HousecallPro: Error getting booking windows ${err}`);
366
+ housecallProResponse.error = err;
367
+ }
368
+ return housecallProResponse;
369
+ });
370
+ }
371
+ }
372
+ exports.HouseCallProService = HouseCallProService;
373
+ //# sourceMappingURL=HouseCallProService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HouseCallProService.js","sourceRoot":"","sources":["../src/HouseCallProService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kCAAkC;AAClC,iEAAqD;AAErD,mDAAqC;AACrC,kDAAkD;AASlD,MAAM,QAAQ,GAAG,+BAA+B,CAAC;AACjD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC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G,GAAG,CAAC;YACrC,CAAC;YAED,OAAO,oBAAoB,CAAC;QAChC,CAAC;KAAA;CACJ;AApYD,kDAoYC"}
package/lib/ai.d.ts ADDED
File without changes
package/lib/ai.js ADDED
@@ -0,0 +1,190 @@
1
+ // /*! Copyright (c) 2022, XAPPmedia */
2
+ // // Import necessary modules
3
+ // import OpenAI from "openai";
4
+ // import { log } from "stentor-logger";
5
+ // export interface JobTypeAiQuery {
6
+ // question: string;
7
+ // jobTypes: JobTypeDescriptor[];
8
+ // apiKey?: string;
9
+ // }
10
+ // export interface JobTypeDescriptor {
11
+ // id: number;
12
+ // name: string;
13
+ // summary: string;
14
+ // businessUnitIds?: number[];
15
+ // }
16
+ // export interface JobTypeAiResponse extends JobTypeDescriptor {
17
+ // confidence: number;
18
+ // }
19
+ // export async function guessJobTypes(query: JobTypeAiQuery): Promise<JobTypeAiResponse[]> {
20
+ // const { question, jobTypes, apiKey } = query;
21
+ // const openai = new OpenAI({
22
+ // apiKey: apiKey || process.env.OPENAI_API_KEY
23
+ // });
24
+ // const response = await openai.chat.completions.create({
25
+ // model: "gpt-4",
26
+ // messages: [
27
+ // {
28
+ // role: "system",
29
+ // content: `You are a helpful assistant for a plumbing company. Your job is to match a customer
30
+ // request to a specific job type based on a customer's input of a problem.
31
+ // Print your top three possible job types with most confident on top.
32
+ // With each new line being a job type, print the id, name, summary, and confidence on a scale between 0 and 1.
33
+ // Respond with a json object. Job Types in JSON: ${JSON.stringify(jobTypes)}`
34
+ // },
35
+ // {
36
+ // role: "user",
37
+ // content: question
38
+ // }
39
+ // ],
40
+ // temperature: 1,
41
+ // max_tokens: 256,
42
+ // top_p: 1,
43
+ // frequency_penalty: 0,
44
+ // presence_penalty: 0
45
+ // });
46
+ // const content = response?.choices?.[0]?.message?.content;
47
+ // let choices: JobTypeAiResponse[];
48
+ // try {
49
+ // choices = JSON.parse(content);
50
+ // } catch (err) {
51
+ // log().error(`OpenAI: Cannot parse response. QUESTION: "${question}" RESPONSE: "${content}"`);
52
+ // }
53
+ // if (!choices || choices.length === 0) {
54
+ // log().error(`OpenAI: Bad response:\n${JSON.stringify(response, null, 2)}`);
55
+ // }
56
+ // return choices || [];
57
+ // }
58
+ // // const testJobTypes: JobTypeDescriptor[] = [
59
+ // // {
60
+ // // id: 481,
61
+ // // name: "PLUM: Service",
62
+ // // summary: "Service job type"
63
+ // // },
64
+ // // {
65
+ // // id: 484,
66
+ // // name: "ELEC: Service",
67
+ // // summary: ""
68
+ // // },
69
+ // // {
70
+ // // id: 485,
71
+ // // name: "PLUM: Install",
72
+ // // summary: ""
73
+ // // },
74
+ // // {
75
+ // // id: 5008581,
76
+ // // name: "ELEC: Sales Estimate",
77
+ // // summary: "Age of the unit?"
78
+ // // },
79
+ // // {
80
+ // // id: 18006021,
81
+ // // name: "PLUM: Sales Estimate",
82
+ // // summary: ""
83
+ // // },
84
+ // // {
85
+ // // id: 18500011,
86
+ // // name: "HVAC: Service",
87
+ // // summary: ""
88
+ // // },
89
+ // // {
90
+ // // id: 18500012,
91
+ // // name: "HVAC: Install",
92
+ // // summary: ""
93
+ // // },
94
+ // // {
95
+ // // id: 18500023,
96
+ // // name: "HVAC: Sales Estimate",
97
+ // // summary: ""
98
+ // // },
99
+ // // {
100
+ // // id: 18500037,
101
+ // // name: "HVAC: Service Callback / Warranty",
102
+ // // summary: ""
103
+ // // },
104
+ // // {
105
+ // // id: 18500045,
106
+ // // name: "PLUM: Service Callback / Warranty",
107
+ // // summary: ""
108
+ // // },
109
+ // // {
110
+ // // id: 18500062,
111
+ // // name: "HVAC: SPP Visit - Spring",
112
+ // // summary: ""
113
+ // // },
114
+ // // {
115
+ // // id: 18500071,
116
+ // // name: "HVAC: SPP Visit - Fall",
117
+ // // summary: ""
118
+ // // },
119
+ // // {
120
+ // // id: 50002111,
121
+ // // name: "ELEC: Callback / Warranty",
122
+ // // summary: ""
123
+ // // },
124
+ // // {
125
+ // // id: 142421316,
126
+ // // name: "PLUM: SPP - Water Heater Flush",
127
+ // // summary: ""
128
+ // // },
129
+ // // {
130
+ // // id: 188446882,
131
+ // // name: "PLUM: Mid Atlantic Trenchless",
132
+ // // summary: ""
133
+ // // },
134
+ // // {
135
+ // // id: 188448026,
136
+ // // name: "PLUM: Water Heater Install",
137
+ // // summary: ""
138
+ // // },
139
+ // // {
140
+ // // id: 188448297,
141
+ // // name: "PLUM: Install Callback / Warranty ",
142
+ // // summary: ""
143
+ // // },
144
+ // // {
145
+ // // id: 188448540,
146
+ // // name: "HVAC: Marketed Tune Up",
147
+ // // summary: ""
148
+ // // },
149
+ // // {
150
+ // // id: 188448656,
151
+ // // name: "PLUM: Trenchless Install",
152
+ // // summary: ""
153
+ // // },
154
+ // // {
155
+ // // id: 188449170,
156
+ // // name: "PLUM: Tankless Install",
157
+ // // summary: ""
158
+ // // },
159
+ // // {
160
+ // // id: 188449576,
161
+ // // name: "HVAC: Install Callback / Warranty",
162
+ // // summary: ""
163
+ // // },
164
+ // // {
165
+ // // id: 189746127,
166
+ // // name: "HVAC: Water Heater Install",
167
+ // // summary: ""
168
+ // // },
169
+ // // {
170
+ // // id: 189766613,
171
+ // // name: "HVAC: Tankless Install",
172
+ // // summary: ""
173
+ // // }
174
+ // // ];
175
+ // // (function () {
176
+ // // const query = {
177
+ // // question: "There is a flood in the basement.",
178
+ // // jobTypes: testJobTypes,
179
+ // // apiKey: "xxxxx"
180
+ // // };
181
+ // // guessJobTypes(query)
182
+ // // .then((jobTypes) => {
183
+ // // log().error(`\nQUESTION: "${query.question}"\nJOBTYPES:\n${JSON.stringify(jobTypes, null, 2)}`);
184
+ // // })
185
+ // // .catch((err) => {
186
+ // // log().error(err.toString());
187
+ // // });
188
+ // // log().error("Done");
189
+ // // })();
190
+ //# sourceMappingURL=ai.js.map
package/lib/ai.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.js","sourceRoot":"","sources":["../src/ai.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAEvC,8BAA8B;AAC9B,+BAA+B;AA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B,mCAAmC;AACnC,kHAAkH;AAClH,gBAAgB;AAChB,+BAA+B;AAC/B,8CAA8C;AAC9C,iBAAiB;AAEjB,8BAA8B;AAC9B,WAAW"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ /*! Copyright (c) 2024, XAPP AI */
2
+ export * from "./HouseCallProService";
package/lib/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*! Copyright (c) 2024, XAPP AI */
18
+ __exportStar(require("./HouseCallProService"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kCAAkC;AAClC,wDAAsC"}
@@ -0,0 +1,151 @@
1
+ /*! Copyright (c) 2024, XAPP AI */
2
+ export interface HouseCallProExternalLeadExtras {
3
+ /**
4
+ * Typically aligned with the session ID to allow the same customer to have multiple conversations and create multiple leads.
5
+ */
6
+ externalId?: string;
7
+ /**
8
+ * The URL of the website the lead is on when the lead capture is complete
9
+ */
10
+ source?: string;
11
+ /**
12
+ * ID of the bot. Pass this in if you aren't using 'bot' or the STUDIO_APP_ID
13
+ */
14
+ botId?: string;
15
+ /**
16
+ * Was the session abandoned i.e. widget was closed (= no more data)?
17
+ */
18
+ isAbandoned?: boolean;
19
+ }
20
+ export interface HouseCallProLeadTranscript {
21
+ /**
22
+ * What the end user asked
23
+ */
24
+ question: string;
25
+ /**
26
+ * How the bot responded
27
+ */
28
+ answer: string;
29
+ }
30
+ export interface HouseCallProTitanLead extends HouseCallProExternalLeadExtras {
31
+ /**
32
+ * A transcript of the conversation that lead to the lead
33
+ */
34
+ transcript: HouseCallProLeadTranscript[];
35
+ /**
36
+ * The fields and their value for the lead.
37
+ */
38
+ fields: {
39
+ name: string;
40
+ value: string;
41
+ }[];
42
+ }
43
+ /**
44
+ * Address
45
+ */
46
+ export interface HouseCallProAddress {
47
+ street: string;
48
+ street_line_2?: string;
49
+ city: string;
50
+ state: string;
51
+ zip: string;
52
+ country: string;
53
+ }
54
+ /**
55
+ * Description of an appointment
56
+ */
57
+ export interface HCPAppointment {
58
+ id?: number;
59
+ start_time: string;
60
+ end_time: string;
61
+ arrival_window_minutes?: number;
62
+ dispatched_employees_is?: string[];
63
+ }
64
+ /**
65
+ * Description of a customer
66
+ *
67
+ * @export
68
+ * @interface HouseCallProCustomer
69
+ */
70
+ export interface HouseCallProCustomer {
71
+ customer_id?: string;
72
+ first_name?: string;
73
+ last_name?: string;
74
+ email?: string;
75
+ company?: string;
76
+ notification_enabled?: boolean;
77
+ mobile_number?: string;
78
+ home_number?: string;
79
+ work_number?: string;
80
+ tags?: string[];
81
+ lead_source?: string;
82
+ notes?: string;
83
+ note?: string;
84
+ addresses?: HouseCallProAddress[];
85
+ created_at?: string;
86
+ updated_at?: string;
87
+ }
88
+ export interface HouseCallProPagination<Data = unknown> {
89
+ page: number;
90
+ page_size: number;
91
+ total_pages: number;
92
+ total_items: number;
93
+ data: Data[];
94
+ }
95
+ export interface HouseCallProResponse<Data = any> {
96
+ status: "Success" | "Failure";
97
+ error?: string;
98
+ data?: Data;
99
+ }
100
+ export interface AddressQuery {
101
+ street?: string;
102
+ city?: string;
103
+ state?: string;
104
+ zip?: string;
105
+ country?: string;
106
+ }
107
+ export interface HouseCallProRequest {
108
+ first_name: string;
109
+ last_name: string;
110
+ email?: string;
111
+ home_number?: string;
112
+ address?: AddressQuery;
113
+ requestTime?: string;
114
+ partOfDayPreferred?: string;
115
+ notes?: string;
116
+ sessionId?: string;
117
+ newCustomer?: boolean;
118
+ message?: string;
119
+ contacts?: Contact[];
120
+ }
121
+ export interface Contact {
122
+ type: "Phone" | "Email";
123
+ value: string;
124
+ memo: string;
125
+ }
126
+ export interface BookingRequest extends HouseCallProRequest {
127
+ existingBookingId?: string;
128
+ }
129
+ export interface LocationRequest extends HouseCallProRequest {
130
+ customerId: number;
131
+ }
132
+ export interface CustomerQuery extends AddressQuery {
133
+ ids?: string[];
134
+ name?: string;
135
+ phone?: string;
136
+ email?: string;
137
+ }
138
+ export interface LocationQuery extends AddressQuery {
139
+ ids?: string[];
140
+ name?: string;
141
+ customerId?: string;
142
+ }
143
+ export interface JobsQuery {
144
+ createdOnOrAfter: string;
145
+ appointmentStatus?: "Scheduled" | "Dispatched" | "Working" | "Hold" | "Done" | "Canceled" | "Unused";
146
+ jobStatus?: "Scheduled" | "InProgress" | "Hold" | "Completed" | "Canceled";
147
+ customerId?: number;
148
+ businessUnitId?: number;
149
+ locationId?: number;
150
+ campaignId?: number;
151
+ }
package/lib/models.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2024, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":";AAAA,kCAAkC"}
package/lib/util.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Message } from "stentor-models";
2
+ import { HouseCallProLeadTranscript } from "./models";
3
+ import addresser from "addresser";
4
+ export declare function transformTranscript(transcript: Message[], botId?: string): HouseCallProLeadTranscript[];
5
+ export declare function parseAddress(addressString: string): Promise<addresser.IParsedAddress>;
6
+ export declare function queryfy(obj: {
7
+ [key: string]: any;
8
+ }, excludeKeys?: string[]): URLSearchParams;
package/lib/util.js ADDED
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.queryfy = exports.parseAddress = exports.transformTranscript = void 0;
16
+ /*! Copyright (c) 2024, XAPP AI */
17
+ const stentor_logger_1 = require("stentor-logger");
18
+ const addresser_1 = __importDefault(require("addresser"));
19
+ const axios_1 = __importDefault(require("axios"));
20
+ function transformTranscript(transcript, botId) {
21
+ const HousecallProTranscript = [];
22
+ const current = {
23
+ question: "",
24
+ answer: ""
25
+ };
26
+ // This is very fragile at the moment
27
+ transcript.forEach((value, index) => {
28
+ const message = value.message;
29
+ let isFromBot = false;
30
+ if (value.from && value.from.id) {
31
+ isFromBot =
32
+ value.from.id === botId || value.from.id === "bot" || value.from.id === process.env["STUDIO_APP_ID"];
33
+ }
34
+ // Either what they passed in, the app_id, or "bot" which is another possible default
35
+ if (isFromBot) {
36
+ // From the bot, the answer
37
+ current.answer = message;
38
+ }
39
+ else {
40
+ current.question = message;
41
+ }
42
+ if (index % 2) {
43
+ // push if we are on the add number
44
+ HousecallProTranscript.push(Object.assign({}, current));
45
+ // clean it
46
+ current.answer = "";
47
+ current.question = "";
48
+ }
49
+ else {
50
+ // If we are at the end and not on a odd number
51
+ if (index === transcript.length - 1) {
52
+ HousecallProTranscript.push(Object.assign({}, current));
53
+ }
54
+ }
55
+ });
56
+ return HousecallProTranscript;
57
+ }
58
+ exports.transformTranscript = transformTranscript;
59
+ function parseAddress(addressString) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ let parsedAddress;
62
+ if (!addressString) {
63
+ (0, stentor_logger_1.log)().info("No Address passed...");
64
+ return;
65
+ }
66
+ try {
67
+ addresser_1.default.parseAddress(addressString);
68
+ }
69
+ catch (err) {
70
+ (0, stentor_logger_1.log)().error(`Invalid address, go through Google ${addressString}: ${err}`);
71
+ const addrDetails = yield getAddressDetails(addressString);
72
+ return addrDetails;
73
+ }
74
+ try {
75
+ parsedAddress = addresser_1.default.parseAddress(addressString);
76
+ // Service Titan Requires Zip Code. Get it from Google
77
+ if ((parsedAddress === null || parsedAddress === void 0 ? void 0 : parsedAddress.addressLine1) && !(parsedAddress === null || parsedAddress === void 0 ? void 0 : parsedAddress.zipCode)) {
78
+ const addressDetails = yield getAddressDetails(addressString);
79
+ return addressDetails;
80
+ }
81
+ return parsedAddress;
82
+ }
83
+ catch (e) {
84
+ (0, stentor_logger_1.log)().error(`Invalid address ${addressString}: ${e}`);
85
+ return undefined;
86
+ }
87
+ });
88
+ }
89
+ exports.parseAddress = parseAddress;
90
+ function getAddressDetails(addressString) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ const predictions = yield axios_1.default.request({
93
+ method: "get",
94
+ url: `https://maps.googleapis.com/maps/api/place/autocomplete/json?input=${addressString}&key=${process.env.GOOGLE_PLACES_KEY}`
95
+ });
96
+ // Match found: Get Details
97
+ if (predictions.data.predictions.length > 0) {
98
+ const details = yield axios_1.default.request({
99
+ method: "get",
100
+ url: `https://maps.googleapis.com/maps/api/place/details/json?place_id=${predictions.data.predictions[0].place_id}&key=${process.env.GOOGLE_PLACES_KEY}`
101
+ });
102
+ return addresser_1.default.parseAddress(details.data.result.formatted_address);
103
+ }
104
+ else {
105
+ return;
106
+ }
107
+ });
108
+ }
109
+ function queryfy(obj, excludeKeys) {
110
+ const params = new URLSearchParams();
111
+ Object.keys(obj).forEach((key) => {
112
+ if (excludeKeys && excludeKeys.includes(key)) {
113
+ return;
114
+ }
115
+ const value = obj[key];
116
+ if (value !== undefined) {
117
+ if (Array.isArray(value)) {
118
+ params.append(key, value.join(",")); // %2C
119
+ }
120
+ else {
121
+ params.append(key, value.toString());
122
+ }
123
+ }
124
+ });
125
+ return params;
126
+ }
127
+ exports.queryfy = queryfy;
128
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kCAAkC;AAClC,mDAAqC;AAGrC,0DAAkC;AAClC,kDAA0B;AAE1B,SAAgB,mBAAmB,CAAC,UAAqB,EAAE,KAAc;IACrE,MAAM,sBAAsB,GAAiC,EAAE,CAAC;IAEhE,MAAM,OAAO,GAA+B;QACxC,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;KACb,CAAC;IAEF,qCAAqC;IACrC,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAChC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAE9B,IAAI,SAAS,GAAY,KAAK,CAAC;QAC/B,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YAC9B,SAAS;gBACL,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAC7G,CAAC;QAED,qFAAqF;QACrF,IAAI,SAAS,EAAE,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,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC7B,IAAI,WAAW,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3C,OAAO;QACX,CAAC;QACD,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACvB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM;YAC/C,CAAC;iBAAM,CAAC;gBACJ,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YACzC,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC;AAlBD,0BAkBC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@xapp/stentor-service-housecall-pro",
3
+ "license": "Apache-2.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "version": "1.54.0",
8
+ "description": "Service to integrate with Housecall Pro",
9
+ "types": "lib/index",
10
+ "main": "lib/index",
11
+ "files": [
12
+ "lib"
13
+ ],
14
+ "engines": {
15
+ "node": "^10 || ^12 || ^14 || ^16 || ^18 || ^20"
16
+ },
17
+ "devDependencies": {
18
+ "@types/chai": "4.3.12",
19
+ "@types/lodash": "4.17.0",
20
+ "@xapp/config": "0.2.3",
21
+ "chai": "4.4.1",
22
+ "dotenv": "16.4.4",
23
+ "mocha": "10.3.0",
24
+ "stentor-logger": "1.59.21",
25
+ "stentor-models": "1.59.18",
26
+ "stentor-service-fetch": "1.59.18",
27
+ "ts-node": "10.9.2",
28
+ "typescript": "5.4.2"
29
+ },
30
+ "peerDependencies": {
31
+ "stentor-logger": "1.x",
32
+ "stentor-models": "1.x",
33
+ "stentor-service-fetch": "1.x"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc -d true -p .",
37
+ "clean": "rm -rf ./lib/*",
38
+ "test": "exit 0",
39
+ "local": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
40
+ },
41
+ "gitHead": "c093f2fdc22f09cc17b853efd2eb041ef5aca56b",
42
+ "dependencies": {
43
+ "addresser": "1.1.20",
44
+ "openai": "4.28.4"
45
+ }
46
+ }