@xapp/stentor-service-serviceminder 1.61.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 +176 -0
- package/README.md +9 -0
- package/lib/ServiceMinderService.d.ts +23 -0
- package/lib/ServiceMinderService.js +220 -0
- package/lib/ServiceMinderService.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +1 -0
- package/lib/models.d.ts +196 -0
- package/lib/models.js +3 -0
- package/lib/models.js.map +1 -0
- package/lib/util.d.ts +12 -0
- package/lib/util.js +97 -0
- package/lib/util.js.map +1 -0
- package/package.json +45 -0
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,23 @@
|
|
|
1
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
+
import { FetchService } from "stentor-service-fetch";
|
|
3
|
+
import { BaseService, CrmResponse, CrmService, CrmServiceAvailability, CrmServiceAvailabilitySettings, CrmServiceJobType, ExternalLead } from "stentor-models";
|
|
4
|
+
import { CustomerQuery, ServiceMinderCustomer, ServiceMinderResponse } from "./models";
|
|
5
|
+
export interface ServiceMinderServiceProps extends BaseService, CrmServiceAvailabilitySettings {
|
|
6
|
+
appId: string;
|
|
7
|
+
channel?: string;
|
|
8
|
+
api_key: string;
|
|
9
|
+
openAI: {
|
|
10
|
+
apiKey: string;
|
|
11
|
+
};
|
|
12
|
+
defaultJobTypeId?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class ServiceMinderService extends FetchService implements CrmService {
|
|
15
|
+
private props;
|
|
16
|
+
constructor(props: ServiceMinderServiceProps);
|
|
17
|
+
getAvailability(): Promise<CrmServiceAvailability>;
|
|
18
|
+
getJobType(message: string): Promise<CrmServiceJobType>;
|
|
19
|
+
send(externalLead: ExternalLead): Promise<CrmResponse>;
|
|
20
|
+
getCustomers(query: CustomerQuery): Promise<ServiceMinderResponse>;
|
|
21
|
+
addCustomer(customer: ServiceMinderCustomer): Promise<ServiceMinderResponse>;
|
|
22
|
+
addNote(customer: ServiceMinderCustomer): Promise<ServiceMinderResponse>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
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.ServiceMinderService = 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 addresser_1 = require("addresser");
|
|
21
|
+
const base_url = "https://serviceminder.io/api/";
|
|
22
|
+
const lead_source = process.env.LEADSOURCE ? process.env.LEADSOURCE : "XAPP AI";
|
|
23
|
+
const util_1 = require("./util");
|
|
24
|
+
const console_1 = require("console");
|
|
25
|
+
class ServiceMinderService extends stentor_service_fetch_1.FetchService {
|
|
26
|
+
constructor(props) {
|
|
27
|
+
super(props);
|
|
28
|
+
this.props = Object.assign({}, props);
|
|
29
|
+
if (!this.props.channel) {
|
|
30
|
+
this.props.channel = "Chat";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
getAvailability() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
throw (0, console_1.error)("not implemented");
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
getJobType(message) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
(0, stentor_logger_1.log)().error(message);
|
|
41
|
+
throw (0, console_1.error)("not implemented");
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
// Send the lead or scheduling request
|
|
45
|
+
send(externalLead) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
var _a, _b, _c, _d, _e, _f;
|
|
48
|
+
const customerQuery = {};
|
|
49
|
+
const crmResponse = {
|
|
50
|
+
status: "Failure",
|
|
51
|
+
message: ""
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
let transcript = "";
|
|
55
|
+
(_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`));
|
|
56
|
+
// Parse first/last name
|
|
57
|
+
const names = (0, util_1.getName)(externalLead);
|
|
58
|
+
const address = (_b = externalLead.fields.find((x) => x.name == "ADDRESS")) === null || _b === void 0 ? void 0 : _b.value;
|
|
59
|
+
const phone = (_c = externalLead.fields.find((x) => x.name == "PHONE")) === null || _c === void 0 ? void 0 : _c.value;
|
|
60
|
+
const email = (_d = externalLead.fields.find((x) => x.name == "EMAIL")) === null || _d === void 0 ? void 0 : _d.value;
|
|
61
|
+
const message = (_e = externalLead.fields.find((x) => x.name == "MESSAGE")) === null || _e === void 0 ? void 0 : _e.value;
|
|
62
|
+
let parsedAddress;
|
|
63
|
+
try {
|
|
64
|
+
parsedAddress = yield (0, addresser_1.parseAddress)(address);
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
(0, stentor_logger_1.log)().error(`Serviceminder: Invalid address "${address}"`);
|
|
68
|
+
}
|
|
69
|
+
const crmRequest = {
|
|
70
|
+
Name: names,
|
|
71
|
+
Phone: phone,
|
|
72
|
+
Email: email,
|
|
73
|
+
Notes: [{ Title: "Transcript", Body: transcript }],
|
|
74
|
+
Message: message,
|
|
75
|
+
LeadSource: lead_source
|
|
76
|
+
};
|
|
77
|
+
if (parsedAddress) {
|
|
78
|
+
crmRequest.Address1 = parsedAddress.addressLine1;
|
|
79
|
+
(crmRequest.City = parsedAddress.placeName),
|
|
80
|
+
(crmRequest.State = parsedAddress.stateAbbreviation),
|
|
81
|
+
(crmRequest.Zip = parsedAddress.zipCode);
|
|
82
|
+
}
|
|
83
|
+
// Check if customer exists
|
|
84
|
+
if (phone) {
|
|
85
|
+
customerQuery.phone = phone;
|
|
86
|
+
}
|
|
87
|
+
if (email) {
|
|
88
|
+
customerQuery.email = email;
|
|
89
|
+
}
|
|
90
|
+
const customerMatches = yield this.getCustomers(customerQuery);
|
|
91
|
+
// Customer exists, use this account
|
|
92
|
+
if (customerMatches.status === "Success" && ((_f = customerMatches.data) === null || _f === void 0 ? void 0 : _f.length) > 0) {
|
|
93
|
+
crmRequest.Id = customerMatches.data[0].Id;
|
|
94
|
+
crmRequest.Message = transcript;
|
|
95
|
+
yield this.addNote(crmRequest);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const addCustomerResponse = yield this.addCustomer(crmRequest);
|
|
99
|
+
(0, stentor_logger_1.log)().info("Add customer: ", addCustomerResponse);
|
|
100
|
+
}
|
|
101
|
+
crmResponse.status = "Success";
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
(0, stentor_logger_1.log)().error(`Serviceminder error send(): ${err}`);
|
|
105
|
+
crmResponse.message = err;
|
|
106
|
+
}
|
|
107
|
+
return crmResponse;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
getCustomers(query) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const serviceminderResponse = {
|
|
113
|
+
status: "Failure"
|
|
114
|
+
};
|
|
115
|
+
const data = {
|
|
116
|
+
ApiKey: process.env.SM_API_KEY,
|
|
117
|
+
EmailSearch: null,
|
|
118
|
+
PhoneSearch: null,
|
|
119
|
+
NameSearch: null
|
|
120
|
+
};
|
|
121
|
+
if (query.email) {
|
|
122
|
+
data.EmailSearch = query.email;
|
|
123
|
+
}
|
|
124
|
+
else if (query.phone) {
|
|
125
|
+
data.PhoneSearch = query.phone;
|
|
126
|
+
}
|
|
127
|
+
else if (query.name) {
|
|
128
|
+
data.NameSearch = query.name;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const config = {
|
|
132
|
+
method: "post",
|
|
133
|
+
url: `${base_url}contacts/locate`,
|
|
134
|
+
headers: {
|
|
135
|
+
Accept: "application/json",
|
|
136
|
+
"Content-Type": "application/json"
|
|
137
|
+
},
|
|
138
|
+
data: JSON.stringify(data)
|
|
139
|
+
};
|
|
140
|
+
const response = yield (0, axios_1.default)(config);
|
|
141
|
+
serviceminderResponse.status = "Success";
|
|
142
|
+
serviceminderResponse.data = response.data;
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
(0, stentor_logger_1.log)().error(`ServiceMinder: Error searching customers ${err}`);
|
|
146
|
+
serviceminderResponse.error = err;
|
|
147
|
+
}
|
|
148
|
+
const customerMatches = serviceminderResponse.data;
|
|
149
|
+
serviceminderResponse.data = customerMatches === null || customerMatches === void 0 ? void 0 : customerMatches.Matches;
|
|
150
|
+
return serviceminderResponse;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
addCustomer(customer) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
const serviceMinderResponse = {
|
|
156
|
+
status: "Failure"
|
|
157
|
+
};
|
|
158
|
+
try {
|
|
159
|
+
const config = {
|
|
160
|
+
method: "post",
|
|
161
|
+
url: `${base_url}contacts/addupdate`,
|
|
162
|
+
headers: {
|
|
163
|
+
Accept: "application/json",
|
|
164
|
+
"Content-Type": "application/json"
|
|
165
|
+
},
|
|
166
|
+
data: JSON.stringify({
|
|
167
|
+
ApiKey: process.env.SM_API_KEY,
|
|
168
|
+
Matches: [customer]
|
|
169
|
+
})
|
|
170
|
+
};
|
|
171
|
+
const response = yield (0, axios_1.default)(config);
|
|
172
|
+
// eslint-disable-next-line no-console
|
|
173
|
+
console.log(response.data);
|
|
174
|
+
serviceMinderResponse.status = "Success";
|
|
175
|
+
const matches = response.data.Matches;
|
|
176
|
+
serviceMinderResponse.data = matches[0];
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
(0, stentor_logger_1.log)().error(`ServiceMinder: Error adding customer ${err}`);
|
|
180
|
+
serviceMinderResponse.error = err;
|
|
181
|
+
}
|
|
182
|
+
return serviceMinderResponse;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
addNote(customer) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
const serviceMinderResponse = {
|
|
188
|
+
status: "Failure"
|
|
189
|
+
};
|
|
190
|
+
try {
|
|
191
|
+
const config = {
|
|
192
|
+
method: "post",
|
|
193
|
+
url: `${base_url}contacts/addnote`,
|
|
194
|
+
headers: {
|
|
195
|
+
Accept: "application/json",
|
|
196
|
+
"Content-Type": "application/json"
|
|
197
|
+
},
|
|
198
|
+
data: JSON.stringify({
|
|
199
|
+
ApiKey: process.env.SM_API_KEY,
|
|
200
|
+
ContactId: customer.Id,
|
|
201
|
+
Note: { Title: "Transcript", Body: customer.Message }
|
|
202
|
+
})
|
|
203
|
+
};
|
|
204
|
+
const response = yield (0, axios_1.default)(config);
|
|
205
|
+
// eslint-disable-next-line no-console
|
|
206
|
+
console.log(response.data);
|
|
207
|
+
serviceMinderResponse.status = "Success";
|
|
208
|
+
const matches = response.data.Matches;
|
|
209
|
+
serviceMinderResponse.data = matches[0];
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
(0, stentor_logger_1.log)().error(`ServiceMinder: Error adding note ${err}`);
|
|
213
|
+
serviceMinderResponse.error = err;
|
|
214
|
+
}
|
|
215
|
+
return serviceMinderResponse;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.ServiceMinderService = ServiceMinderService;
|
|
220
|
+
//# sourceMappingURL=ServiceMinderService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceMinderService.js","sourceRoot":"","sources":["../src/ServiceMinderService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kCAAkC;AAClC,iEAAqD;AAUrD,mDAAqC;AACrC,kDAAkD;AAGlD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C;KAAA;IAEY,OAAO,CAAC,QAA+B;;YAChD,MAAM,qBAAqB,GAAiD;gBACxE,MAAM,EAAE,SAAS;aACpB,CAAC;YAEF,IAAI,CAAC;gBACD,MAAM,MAAM,GAAuB;oBAC/B,MAAM,EAAE,MAAM;oBACd,GAAG,EAAE,GAAG,QAAQ,kBAAkB;oBAClC,OAAO,EAAE;wBACL,MAAM,EAAE,kBAAkB;wBAC1B,cAAc,EAAE,kBAAkB;qBACrC;oBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;wBACjB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU;wBAC9B,SAAS,EAAE,QAAQ,CAAC,EAAE;wBACtB,IAAI,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,CAAC,OAAO,EAAE;qBACxD,CAAC;iBACL,CAAC;gBAEF,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAK,EAAC,MAAM,CAAC,CAAC;gBAErC,sCAAsC;gBACtC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;gBAE3B,qBAAqB,CAAC,MAAM,GAAG,SAAS,CAAC;gBACzC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAkC,CAAC;gBACjE,qBAAqB,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5C,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,IAAA,oBAAG,GAAE,CAAC,KAAK,CAAC,oCAAoC,GAAG,EAAE,CAAC,CAAC;gBACvD,qBAAqB,CAAC,KAAK,GAAG,GAAG,CAAC;YACtC,CAAC;YAED,OAAO,qBAAqB,CAAC;QACjC,CAAC;KAAA;CACJ;AAzND,oDAyNC"}
|
package/lib/index.d.ts
ADDED
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("./ServiceMinderService"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kCAAkC;AAClC,yDAAuC"}
|
package/lib/models.d.ts
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
+
import { IParsedAddress } from "addresser";
|
|
3
|
+
export interface ServiceMinderExternalLeadExtras {
|
|
4
|
+
/**
|
|
5
|
+
* Typically aligned with the session ID to allow the same customer to have multiple conversations and create multiple leads.
|
|
6
|
+
*/
|
|
7
|
+
externalId?: string;
|
|
8
|
+
/**
|
|
9
|
+
* The URL of the website the lead is on when the lead capture is complete
|
|
10
|
+
*/
|
|
11
|
+
source?: string;
|
|
12
|
+
/**
|
|
13
|
+
* ID of the bot. Pass this in if you aren't using 'bot' or the STUDIO_APP_ID
|
|
14
|
+
*/
|
|
15
|
+
botId?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Was the session abandoned i.e. widget was closed (= no more data)?
|
|
18
|
+
*/
|
|
19
|
+
isAbandoned?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ServiceMinderLeadTranscript {
|
|
22
|
+
/**
|
|
23
|
+
* What the end user asked
|
|
24
|
+
*/
|
|
25
|
+
question: string;
|
|
26
|
+
/**
|
|
27
|
+
* How the bot responded
|
|
28
|
+
*/
|
|
29
|
+
answer: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ServiceMinderLead extends ServiceMinderExternalLeadExtras {
|
|
32
|
+
/**
|
|
33
|
+
* A transcript of the conversation that lead to the lead
|
|
34
|
+
*/
|
|
35
|
+
transcript: ServiceMinderLeadTranscript[];
|
|
36
|
+
/**
|
|
37
|
+
* The fields and their value for the lead.
|
|
38
|
+
*/
|
|
39
|
+
fields: {
|
|
40
|
+
name: string;
|
|
41
|
+
value: string;
|
|
42
|
+
}[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Address
|
|
46
|
+
*/
|
|
47
|
+
export interface ServiceMinderAddress {
|
|
48
|
+
id?: string;
|
|
49
|
+
street: string;
|
|
50
|
+
street_line_2?: string;
|
|
51
|
+
city: string;
|
|
52
|
+
state: string;
|
|
53
|
+
zip: string;
|
|
54
|
+
country: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Description of an appointment
|
|
58
|
+
*/
|
|
59
|
+
export interface HCPAppointment {
|
|
60
|
+
id?: number;
|
|
61
|
+
start_time: string;
|
|
62
|
+
end_time: string;
|
|
63
|
+
arrival_window_minutes?: number;
|
|
64
|
+
dispatched_employees_is?: string[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Description of an schedule request
|
|
68
|
+
*/
|
|
69
|
+
export interface HCPSchedule {
|
|
70
|
+
scheduled_start: string;
|
|
71
|
+
scheduled_end: string;
|
|
72
|
+
arrival_window?: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Description of a customer
|
|
76
|
+
*
|
|
77
|
+
* @export
|
|
78
|
+
* @interface ServiceMinderCustomer
|
|
79
|
+
*/
|
|
80
|
+
export interface ServiceMinderCustomer {
|
|
81
|
+
Id?: string;
|
|
82
|
+
Name: string;
|
|
83
|
+
Company?: string;
|
|
84
|
+
Address1?: string;
|
|
85
|
+
Address2?: string;
|
|
86
|
+
City?: string;
|
|
87
|
+
State?: string;
|
|
88
|
+
Zip?: string;
|
|
89
|
+
Phone?: string;
|
|
90
|
+
Email?: string;
|
|
91
|
+
LeadSource?: string;
|
|
92
|
+
Channel?: string;
|
|
93
|
+
Campaign?: string;
|
|
94
|
+
Notes?: Note[];
|
|
95
|
+
Message: string;
|
|
96
|
+
}
|
|
97
|
+
export interface Note {
|
|
98
|
+
Id?: number;
|
|
99
|
+
Title?: string;
|
|
100
|
+
Body?: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Description of a job
|
|
104
|
+
*
|
|
105
|
+
* @export
|
|
106
|
+
* @interface ServiceMinderJob
|
|
107
|
+
*/
|
|
108
|
+
export interface ServiceMinderJob {
|
|
109
|
+
customer_id: string;
|
|
110
|
+
address_id: string;
|
|
111
|
+
schedule?: HCPSchedule;
|
|
112
|
+
tags?: string[];
|
|
113
|
+
lead_source?: string;
|
|
114
|
+
notes: string;
|
|
115
|
+
}
|
|
116
|
+
export interface ServiceMinderPagination<Data = unknown> {
|
|
117
|
+
page: number;
|
|
118
|
+
page_size: number;
|
|
119
|
+
total_pages: number;
|
|
120
|
+
total_items: number;
|
|
121
|
+
data: Data[];
|
|
122
|
+
}
|
|
123
|
+
export interface ServiceMinderResponse<Data = any> {
|
|
124
|
+
status: "Success" | "Failure";
|
|
125
|
+
error?: string;
|
|
126
|
+
data?: Data;
|
|
127
|
+
}
|
|
128
|
+
export interface AddressQuery {
|
|
129
|
+
street?: string;
|
|
130
|
+
city?: string;
|
|
131
|
+
state?: string;
|
|
132
|
+
zip?: string;
|
|
133
|
+
country?: string;
|
|
134
|
+
}
|
|
135
|
+
export interface ServiceMinderRequest {
|
|
136
|
+
first_name: string;
|
|
137
|
+
last_name: string;
|
|
138
|
+
email?: string;
|
|
139
|
+
home_number?: string;
|
|
140
|
+
address?: AddressQuery;
|
|
141
|
+
requestTime?: string;
|
|
142
|
+
partOfDayPreferred?: string;
|
|
143
|
+
notes?: string;
|
|
144
|
+
sessionId?: string;
|
|
145
|
+
newCustomer?: boolean;
|
|
146
|
+
message?: string;
|
|
147
|
+
contacts?: Contact[];
|
|
148
|
+
}
|
|
149
|
+
export interface Contact {
|
|
150
|
+
type: "Phone" | "Email";
|
|
151
|
+
value: string;
|
|
152
|
+
memo: string;
|
|
153
|
+
}
|
|
154
|
+
export interface BookingRequest extends ServiceMinderRequest {
|
|
155
|
+
existingBookingId?: string;
|
|
156
|
+
}
|
|
157
|
+
export interface LocationRequest extends ServiceMinderRequest {
|
|
158
|
+
customerId: number;
|
|
159
|
+
}
|
|
160
|
+
export interface CustomerQuery extends AddressQuery {
|
|
161
|
+
ids?: string[];
|
|
162
|
+
name?: string;
|
|
163
|
+
phone?: string;
|
|
164
|
+
email?: string;
|
|
165
|
+
}
|
|
166
|
+
export interface LocationQuery extends AddressQuery {
|
|
167
|
+
ids?: string[];
|
|
168
|
+
name?: string;
|
|
169
|
+
customerId?: string;
|
|
170
|
+
}
|
|
171
|
+
export interface JobsQuery {
|
|
172
|
+
createdOnOrAfter: string;
|
|
173
|
+
appointmentStatus?: "Scheduled" | "Dispatched" | "Working" | "Hold" | "Done" | "Canceled" | "Unused";
|
|
174
|
+
jobStatus?: "Scheduled" | "InProgress" | "Hold" | "Completed" | "Canceled";
|
|
175
|
+
customerId?: number;
|
|
176
|
+
businessUnitId?: number;
|
|
177
|
+
locationId?: number;
|
|
178
|
+
campaignId?: number;
|
|
179
|
+
}
|
|
180
|
+
export interface ProcessJobRequest {
|
|
181
|
+
dateTime?: string;
|
|
182
|
+
consentApproval?: boolean;
|
|
183
|
+
message?: string;
|
|
184
|
+
crmRequest?: ServiceMinderCustomer;
|
|
185
|
+
parsedAddress?: IParsedAddress;
|
|
186
|
+
preferredTime?: string;
|
|
187
|
+
}
|
|
188
|
+
export interface ServiceMinderBookingWindow {
|
|
189
|
+
start_time: string;
|
|
190
|
+
end_time: string;
|
|
191
|
+
available: boolean;
|
|
192
|
+
}
|
|
193
|
+
export interface ServiceMinderJobType {
|
|
194
|
+
id: string;
|
|
195
|
+
name: string;
|
|
196
|
+
}
|
package/lib/models.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":""}
|
package/lib/util.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
+
import { DateTime, ExternalLead } from "stentor-models";
|
|
3
|
+
export declare function getName(lead: ExternalLead): string;
|
|
4
|
+
export declare function leadToNote(lead: ExternalLead): string;
|
|
5
|
+
export declare function getUTCOffset(dateString: string): number;
|
|
6
|
+
/**
|
|
7
|
+
* Array of DateTime objects for the next n days from today
|
|
8
|
+
*
|
|
9
|
+
* @param n
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function getNextDays(n: number): DateTime[];
|
package/lib/util.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getName = getName;
|
|
4
|
+
exports.leadToNote = leadToNote;
|
|
5
|
+
exports.getUTCOffset = getUTCOffset;
|
|
6
|
+
exports.getNextDays = getNextDays;
|
|
7
|
+
//import { JobberContact } from "./ServiceMinder";
|
|
8
|
+
const stentor_logger_1 = require("stentor-logger");
|
|
9
|
+
function getName(lead) {
|
|
10
|
+
// Try to find a field with the name "FULL_NAME" in the lead.fields array
|
|
11
|
+
const fullNameField = lead.fields.find((field) => field.name === "FULL_NAME");
|
|
12
|
+
// If a "FULL_NAME" field is found, return its value
|
|
13
|
+
if (fullNameField)
|
|
14
|
+
return fullNameField.value;
|
|
15
|
+
// If no "FULL_NAME" field is found, try to find "FIRST_NAME" and "LAST_NAME" fields
|
|
16
|
+
const firstNameField = lead.fields.find((field) => field.name === "FIRST_NAME");
|
|
17
|
+
const lastNameField = lead.fields.find((field) => field.name === "LAST_NAME");
|
|
18
|
+
// If both "FIRST_NAME" and "LAST_NAME" fields are found, concatenate their values with a space in between
|
|
19
|
+
if (firstNameField && lastNameField)
|
|
20
|
+
return `${firstNameField.value} ${lastNameField.value}`;
|
|
21
|
+
// If either "FIRST_NAME" or "LAST_NAME" is missing, return an empty string or handle accordingly
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
function leadToNote(lead) {
|
|
25
|
+
// Initialize an empty string to hold the transcript
|
|
26
|
+
let transcript = "";
|
|
27
|
+
const appId = process.env.STUDIO_APP_ID;
|
|
28
|
+
// see if we have the name
|
|
29
|
+
const name = getName(lead);
|
|
30
|
+
// Loop over each item in the lead.transcript array
|
|
31
|
+
(lead.transcript || []).forEach((x) => {
|
|
32
|
+
var _a, _b, _c;
|
|
33
|
+
// Check the id of the 'from' field in the current item
|
|
34
|
+
// If the id is neither the STUDIO_APP_ID nor "bot", prefix the message with "user: "
|
|
35
|
+
// Otherwise, prefix the message with the value of STUDIO_APP_ID and ": "
|
|
36
|
+
let prefix = "";
|
|
37
|
+
if (((_a = x.from) === null || _a === void 0 ? void 0 : _a.id) !== appId && ((_b = x.from) === null || _b === void 0 ? void 0 : _b.id) != "bot") {
|
|
38
|
+
prefix = `${name || "user"}: `;
|
|
39
|
+
}
|
|
40
|
+
else if (((_c = x.from) === null || _c === void 0 ? void 0 : _c.id) === "bot") {
|
|
41
|
+
prefix = (appId || "bot") + ": ";
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
prefix = `unknown: `;
|
|
45
|
+
}
|
|
46
|
+
// Append the prefixed message to the transcript string, followed by a newline character
|
|
47
|
+
transcript += `${prefix} ${x.message} \n`;
|
|
48
|
+
});
|
|
49
|
+
// Return the constructed transcript string
|
|
50
|
+
return transcript;
|
|
51
|
+
}
|
|
52
|
+
// export function addMessageToTranscript(contact: JobberContact, transcriptData: ExternalLead) {
|
|
53
|
+
// if (contact.message) {
|
|
54
|
+
// transcriptData.transcript.push({
|
|
55
|
+
// from: {
|
|
56
|
+
// id: "User"
|
|
57
|
+
// },
|
|
58
|
+
// message: contact.message,
|
|
59
|
+
// createdTime: ""
|
|
60
|
+
// });
|
|
61
|
+
// }
|
|
62
|
+
// }
|
|
63
|
+
function getUTCOffset(dateString) {
|
|
64
|
+
const date = new Date(dateString);
|
|
65
|
+
const utcOffsetMinutes = date.getTimezoneOffset();
|
|
66
|
+
const utcOffsetHours = utcOffsetMinutes / 60;
|
|
67
|
+
return -utcOffsetHours; // Return negative because getTimezoneOffset returns positive for timezones ahead of UTC
|
|
68
|
+
}
|
|
69
|
+
function moveBackByMinutes(d, minutes) {
|
|
70
|
+
if (minutes !== 0) {
|
|
71
|
+
d.setMinutes(d.getMinutes() - minutes);
|
|
72
|
+
}
|
|
73
|
+
(0, stentor_logger_1.log)().info(`Jobber: Moved back ${minutes} minutes: ${d}`);
|
|
74
|
+
return d;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Array of DateTime objects for the next n days from today
|
|
78
|
+
*
|
|
79
|
+
* @param n
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
82
|
+
function getNextDays(n) {
|
|
83
|
+
const dates = [];
|
|
84
|
+
let today = new Date();
|
|
85
|
+
const serverOffset = today.getTimezoneOffset();
|
|
86
|
+
today = moveBackByMinutes(today, 240 - serverOffset); // TODO: visitor (browser) or service location address
|
|
87
|
+
for (let i = 1; i <= n; i++) {
|
|
88
|
+
const nextDay = new Date(today);
|
|
89
|
+
nextDay.setDate(today.getDate() + i);
|
|
90
|
+
const year = nextDay.getFullYear();
|
|
91
|
+
const month = (nextDay.getMonth() + 1).toString().padStart(2, "0");
|
|
92
|
+
const day = nextDay.getDate().toString().padStart(2, "0");
|
|
93
|
+
dates.push({ date: `${year}-${month}-${day}` });
|
|
94
|
+
}
|
|
95
|
+
return dates;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=util.js.map
|
package/lib/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAKA,0BAgBC;AAED,gCA8BC;AAcD,oCAKC;AAgBD,kCAiBC;AAvGD,kDAAkD;AAClD,mDAAqC;AAErC,SAAgB,OAAO,CAAC,IAAkB;IACtC,yEAAyE;IACzE,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;IAE9E,oDAAoD;IACpD,IAAI,aAAa;QAAE,OAAO,aAAa,CAAC,KAAK,CAAC;IAE9C,oFAAoF;IACpF,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;IAChF,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;IAE9E,0GAA0G;IAC1G,IAAI,cAAc,IAAI,aAAa;QAAE,OAAO,GAAG,cAAc,CAAC,KAAK,IAAI,aAAa,CAAC,KAAK,EAAE,CAAC;IAE7F,iGAAiG;IACjG,OAAO,EAAE,CAAC;AACd,CAAC;AAED,SAAgB,UAAU,CAAC,IAAkB;IACzC,oDAAoD;IACpD,IAAI,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,C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,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xapp/stentor-service-serviceminder",
|
|
3
|
+
"license": "Apache-2.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"version": "1.61.0",
|
|
8
|
+
"description": "Service to integrate with Serviceminder",
|
|
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.16",
|
|
19
|
+
"@xapp/config": "0.2.3",
|
|
20
|
+
"chai": "4.4.1",
|
|
21
|
+
"dotenv": "16.4.5",
|
|
22
|
+
"mocha": "10.5.2",
|
|
23
|
+
"stentor-logger": "1.59.80",
|
|
24
|
+
"stentor-models": "1.59.80",
|
|
25
|
+
"stentor-service-fetch": "1.59.80",
|
|
26
|
+
"ts-node": "10.9.2",
|
|
27
|
+
"typescript": "5.5.3"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"stentor-logger": "1.x",
|
|
31
|
+
"stentor-models": "1.x",
|
|
32
|
+
"stentor-service-fetch": "1.x"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc -d true -p .",
|
|
36
|
+
"clean": "rm -rf ./lib/*",
|
|
37
|
+
"test": "exit 0",
|
|
38
|
+
"local": "mocha --recursive --timeout 9000 -r ts-node/register \"./src/**/*.test.ts\""
|
|
39
|
+
},
|
|
40
|
+
"gitHead": "5baf0a740f2a487a155396d0c9544d0f40b089d8",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"addresser": "1.1.20",
|
|
43
|
+
"openai": "4.52.2"
|
|
44
|
+
}
|
|
45
|
+
}
|