@app-connect/core 1.7.1 → 1.7.3
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/README.md +1 -1
- package/connector/proxy/engine.js +163 -0
- package/connector/proxy/index.js +492 -0
- package/connector/registry.js +11 -8
- package/handlers/admin.js +12 -3
- package/handlers/auth.js +20 -10
- package/handlers/contact.js +26 -9
- package/handlers/disposition.js +19 -6
- package/handlers/log.js +62 -18
- package/index.js +48 -2
- package/lib/callLogComposer.js +196 -10
- package/lib/oauth.js +0 -1
- package/models/dynamo/connectorSchema.js +146 -0
- package/package.json +1 -1
- package/releaseNotes.json +40 -0
- package/test/connector/proxy/engine.test.js +93 -0
- package/test/connector/proxy/index.test.js +279 -0
- package/test/connector/proxy/sample.json +161 -0
- package/test/{adapter → connector}/registry.test.js +4 -4
- package/test/handlers/auth.test.js +3 -1
package/README.md
CHANGED
|
@@ -274,7 +274,7 @@ Gets comprehensive information about an connector including its capabilities and
|
|
|
274
274
|
**Parameters:**
|
|
275
275
|
- `platformName` (String): Platform identifier
|
|
276
276
|
|
|
277
|
-
**Returns:** Object with connector capabilities information
|
|
277
|
+
**Returns:** Promise with Object with connector capabilities information
|
|
278
278
|
|
|
279
279
|
### Exported Components
|
|
280
280
|
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
|
|
3
|
+
function getByPath(obj, path) {
|
|
4
|
+
if (!path || path === '$') return obj;
|
|
5
|
+
const parts = path.split('.');
|
|
6
|
+
let cur = obj;
|
|
7
|
+
for (const p of parts) {
|
|
8
|
+
if (cur == null) return undefined;
|
|
9
|
+
cur = cur[p];
|
|
10
|
+
}
|
|
11
|
+
return cur;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function renderTemplateString(template, context) {
|
|
15
|
+
if (typeof template !== 'string') return template;
|
|
16
|
+
// if only template value, return value with stringify
|
|
17
|
+
const onlyVarName = template.match(/^\{\{\s*([^}]+?)\s*\}\}$/);
|
|
18
|
+
if (onlyVarName) {
|
|
19
|
+
return getByPath(context, onlyVarName[1]);
|
|
20
|
+
}
|
|
21
|
+
return template.replace(/\{\{\s*([^}]+?)\s*\}\}/g, (_, expr) => {
|
|
22
|
+
const value = getByPath(context, expr.trim());
|
|
23
|
+
return value == null ? '' : String(value);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function renderDeep(input, context) {
|
|
28
|
+
if (input == null) return input;
|
|
29
|
+
if (typeof input === 'string') return renderTemplateString(input, context);
|
|
30
|
+
if (Array.isArray(input)) return input.map(v => renderDeep(v, context));
|
|
31
|
+
if (typeof input === 'object') {
|
|
32
|
+
const out = {};
|
|
33
|
+
for (const [k, v] of Object.entries(input)) {
|
|
34
|
+
out[k] = renderDeep(v, context);
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
return input;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function joinUrl(baseUrl, path) {
|
|
42
|
+
if (!baseUrl) return path;
|
|
43
|
+
if (!path) return baseUrl;
|
|
44
|
+
if (path.startsWith('http://') || path.startsWith('https://')) return path;
|
|
45
|
+
return `${baseUrl.replace(/\/$/, '')}/${path.replace(/^\//, '')}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getAuthHeaderFromAuthConfig({ auth, context, authHeader }) {
|
|
49
|
+
const authHeaders = {};
|
|
50
|
+
const headerName = auth?.headerName || 'Authorization';
|
|
51
|
+
if (auth && auth.credentialTemplate) {
|
|
52
|
+
const credentials = renderTemplateString(auth.credentialTemplate, context);
|
|
53
|
+
const encode = auth.encode === 'none' ? false : true;
|
|
54
|
+
const token = encode ? Buffer.from(credentials).toString('base64') : credentials;
|
|
55
|
+
authHeaders[headerName] = auth.scheme ? `${auth.scheme} ${token}` : token;
|
|
56
|
+
} else if (authHeader) {
|
|
57
|
+
authHeaders[headerName] = authHeader;
|
|
58
|
+
} else if (auth && auth.type === 'oauth' && context.user) {
|
|
59
|
+
authHeaders[headerName] = `${auth.scheme || 'Bearer'} ${context.user.accessToken}`;
|
|
60
|
+
}
|
|
61
|
+
return authHeaders;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function buildHeaders({ config, operation, authHeader, context }) {
|
|
65
|
+
const headers = renderDeep(Object.assign({}, config.requestDefaults?.defaultHeaders || {}), context);
|
|
66
|
+
const renderedOpHeaders = renderDeep(operation?.headers || {}, context);
|
|
67
|
+
for (const [k, v] of Object.entries(renderedOpHeaders)) headers[k] = v;
|
|
68
|
+
|
|
69
|
+
// Per-operation auth override
|
|
70
|
+
const authHeaders = getAuthHeaderFromAuthConfig({
|
|
71
|
+
auth: operation?.auth || config.auth,
|
|
72
|
+
context,
|
|
73
|
+
authHeader
|
|
74
|
+
});
|
|
75
|
+
for (const [k, v] of Object.entries(authHeaders)) headers[k] = v;
|
|
76
|
+
return headers;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function performRequest({ config, opName, inputs, user, authHeader }) {
|
|
80
|
+
const op = config.operations?.[opName];
|
|
81
|
+
if (!op) return null;
|
|
82
|
+
const context = Object.assign({}, inputs, {
|
|
83
|
+
user: user ? {
|
|
84
|
+
accessToken: user.accessToken,
|
|
85
|
+
id: user.id?.split('-')[0],
|
|
86
|
+
hostname: user.hostname,
|
|
87
|
+
timezoneName: user.timezoneName,
|
|
88
|
+
timezoneOffset: user.timezoneOffset,
|
|
89
|
+
platform: user.platform,
|
|
90
|
+
platformAdditionalInfo: user.platformAdditionalInfo,
|
|
91
|
+
refreshToken: user.refreshToken,
|
|
92
|
+
tokenExpiry: user.tokenExpiry,
|
|
93
|
+
} : {
|
|
94
|
+
accessToken: '',
|
|
95
|
+
},
|
|
96
|
+
authHeader,
|
|
97
|
+
apiKey: user?.accessToken,
|
|
98
|
+
secretKey: config.secretKey,
|
|
99
|
+
});
|
|
100
|
+
const url = joinUrl(config.requestDefaults?.baseUrl, renderTemplateString(op.url, context));
|
|
101
|
+
const method = (op.method || 'GET').toUpperCase();
|
|
102
|
+
const headers = buildHeaders({ config, operation: op, authHeader, context });
|
|
103
|
+
const params = renderDeep(op.query || {}, context);
|
|
104
|
+
const data = renderDeep(op.body || {}, context);
|
|
105
|
+
const timeout = (config.requestDefaults?.timeoutSeconds || 30) * 1000;
|
|
106
|
+
const axiosParams = { url, method, headers, params, data, timeout };
|
|
107
|
+
const response = await axios(axiosParams);
|
|
108
|
+
return response;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function mapFindContactResponse({ config, response }) {
|
|
112
|
+
const map = config.operations?.findContact?.responseMapping;
|
|
113
|
+
if (!map) return [];
|
|
114
|
+
const __ctx = { body: response.data };
|
|
115
|
+
const list = getByPath(__ctx, map.listPath || 'body') || [];
|
|
116
|
+
const itemMap = map.item || {};
|
|
117
|
+
return list.map(it => {
|
|
118
|
+
return {
|
|
119
|
+
id: getByPath(it, itemMap.idPath || 'id'),
|
|
120
|
+
name: getByPath(it, itemMap.namePath || 'name') || '',
|
|
121
|
+
phone: getByPath(it, itemMap.phonePath || 'phone') || undefined,
|
|
122
|
+
type: getByPath(it, itemMap.typePath || 'type') || 'Contact',
|
|
123
|
+
title: getByPath(it, itemMap.titlePath || 'title') || "",
|
|
124
|
+
company: getByPath(it, itemMap.companyPath || 'company') || "",
|
|
125
|
+
mostRecentActivityDate: getByPath(it, itemMap.mostRecentActivityDatePath || 'mostRecentActivityDate') || undefined,
|
|
126
|
+
additionalInfo: getByPath(it, itemMap.additionalInfoPath || 'additionalInfo') || null
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function mapCreateCallLogResponse({ config, response }) {
|
|
132
|
+
const map = config.operations?.createCallLog?.responseMapping;
|
|
133
|
+
if (!map) return { logId: undefined };
|
|
134
|
+
const __ctx = { body: response.data };
|
|
135
|
+
const logId = getByPath(__ctx, map.idPath || 'body.id');
|
|
136
|
+
|
|
137
|
+
return { logId: logId ? String(logId) : undefined };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function mapGetCallLogResponse({ config, response }) {
|
|
141
|
+
const map = config.operations?.getCallLog?.responseMapping || {};
|
|
142
|
+
const __ctx = { body: response.data };
|
|
143
|
+
const subject = getByPath(__ctx, map.subjectPath || 'body.subject');
|
|
144
|
+
const note = getByPath(__ctx, map.notePath || 'body.note');
|
|
145
|
+
const fullBody = getByPath(__ctx, map.fullBodyPath || 'body.note');
|
|
146
|
+
const fullLogResponse = response.data;
|
|
147
|
+
return {
|
|
148
|
+
callLogInfo: { subject, note, fullBody, fullLogResponse }
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
module.exports = {
|
|
153
|
+
getByPath,
|
|
154
|
+
renderTemplateString,
|
|
155
|
+
renderDeep,
|
|
156
|
+
joinUrl,
|
|
157
|
+
performRequest,
|
|
158
|
+
mapFindContactResponse,
|
|
159
|
+
mapCreateCallLogResponse,
|
|
160
|
+
mapGetCallLogResponse
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
|
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
const { parsePhoneNumber } = require('awesome-phonenumber');
|
|
3
|
+
const moment = require('moment');
|
|
4
|
+
const {
|
|
5
|
+
performRequest,
|
|
6
|
+
mapFindContactResponse,
|
|
7
|
+
mapCreateCallLogResponse,
|
|
8
|
+
mapGetCallLogResponse,
|
|
9
|
+
getByPath,
|
|
10
|
+
} = require('./engine');
|
|
11
|
+
const { Connector } = require('../../models/dynamo/connectorSchema');
|
|
12
|
+
const { UserModel } = require('../../models/userModel');
|
|
13
|
+
|
|
14
|
+
async function loadPlatformConfig(proxyId) {
|
|
15
|
+
if (!proxyId) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
20
|
+
return proxyConfig;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error('Error getting proxy config: ', proxyId);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function getAuthType({ proxyId, proxyConfig } = {}) {
|
|
28
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(proxyId));
|
|
29
|
+
if (!cfg) {
|
|
30
|
+
return 'apiKey';
|
|
31
|
+
}
|
|
32
|
+
return cfg.auth.type || 'apiKey';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function getOauthInfo({ proxyId, proxyConfig, tokenUrl, hostname } = {}) {
|
|
36
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(proxyId));
|
|
37
|
+
if (!cfg) {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
clientId: cfg.auth.clientId,
|
|
42
|
+
clientSecret: cfg.auth.clientSecret,
|
|
43
|
+
accessTokenUri: tokenUrl || cfg.auth.tokenUrl,
|
|
44
|
+
redirectUri: cfg.auth.redirectUri,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getBasicAuth({ apiKey }) {
|
|
49
|
+
return Buffer.from(`${apiKey}:`).toString('base64');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function getUserInfo({ authHeader, hostname, additionalInfo, platform, apiKey, proxyId, proxyConfig } = {}) {
|
|
53
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(proxyId));
|
|
54
|
+
if (!cfg || !cfg.operations?.getUserInfo) {
|
|
55
|
+
// Fallback if no getUserInfo operation defined
|
|
56
|
+
return {
|
|
57
|
+
successful: false,
|
|
58
|
+
returnMessage: {
|
|
59
|
+
messageType: 'warning',
|
|
60
|
+
message: `Could not load user information. The platform does not support getUserInfo operation.`,
|
|
61
|
+
ttl: 1000
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const response = await performRequest({
|
|
66
|
+
config: cfg,
|
|
67
|
+
opName: 'getUserInfo',
|
|
68
|
+
inputs: {
|
|
69
|
+
additionalInfo,
|
|
70
|
+
apiKey,
|
|
71
|
+
hostname,
|
|
72
|
+
platform,
|
|
73
|
+
},
|
|
74
|
+
user: {},
|
|
75
|
+
authHeader
|
|
76
|
+
});
|
|
77
|
+
const map = cfg.operations.getUserInfo.responseMapping || {};
|
|
78
|
+
const responseCtx = {
|
|
79
|
+
body: response.data,
|
|
80
|
+
additionalInfo,
|
|
81
|
+
apiKey,
|
|
82
|
+
hostname,
|
|
83
|
+
platform,
|
|
84
|
+
};
|
|
85
|
+
const rawUserId = map.idPath ? getByPath(responseCtx, map.idPath) : undefined;
|
|
86
|
+
const id = `${rawUserId}-${platform}`;
|
|
87
|
+
const name = map.namePath ? getByPath(responseCtx, map.namePath) : rawUserId;
|
|
88
|
+
const timezoneName = map.timezoneNamePath ? getByPath(responseCtx, map.timezoneNamePath) : undefined;
|
|
89
|
+
const overridingApiKey = map.overridingApiKeyPath ? getByPath(responseCtx, map.overridingApiKeyPath) : undefined;
|
|
90
|
+
// platformAdditionalInfo mapping and cleanup
|
|
91
|
+
const platformAdditionalInfo = Object.assign({}, additionalInfo || {});
|
|
92
|
+
if (platformAdditionalInfo.password) delete platformAdditionalInfo.password;
|
|
93
|
+
if (map.platformAdditionalInfoPaths && typeof map.platformAdditionalInfoPaths === 'object') {
|
|
94
|
+
for (const [key, expr] of Object.entries(map.platformAdditionalInfoPaths)) {
|
|
95
|
+
platformAdditionalInfo[key] = getByPath(responseCtx, expr);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const message = map.messagePath ? (getByPath(responseCtx, map.messagePath) || `Connected to ${platform}.`) : `Connected to ${platform}.`;
|
|
99
|
+
return {
|
|
100
|
+
successful: true,
|
|
101
|
+
platformUserInfo: Object.assign(
|
|
102
|
+
{ id, name },
|
|
103
|
+
timezoneName ? { timezoneName } : {},
|
|
104
|
+
overridingApiKey ? { overridingApiKey } : {},
|
|
105
|
+
Object.keys(platformAdditionalInfo).length ? { platformAdditionalInfo } : {}
|
|
106
|
+
),
|
|
107
|
+
returnMessage: {
|
|
108
|
+
messageType: 'success',
|
|
109
|
+
message,
|
|
110
|
+
ttl: 1000
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function getUserList({ user, authHeader, proxyConfig }) {
|
|
116
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
|
|
117
|
+
if (!cfg.operations?.getUserList) {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
const response = await performRequest({
|
|
121
|
+
config: cfg,
|
|
122
|
+
opName: 'getUserList',
|
|
123
|
+
inputs: { user },
|
|
124
|
+
user,
|
|
125
|
+
authHeader
|
|
126
|
+
});
|
|
127
|
+
const map = cfg.operations.getUserList.responseMapping || {};
|
|
128
|
+
const responseCtx = { body: response.data };
|
|
129
|
+
const userList = map.listPath ? getByPath(responseCtx, map.listPath) : [];
|
|
130
|
+
return (userList || []).map(item => ({
|
|
131
|
+
id: getByPath(item, map.idPath || 'id'),
|
|
132
|
+
name: getByPath(item, map.namePath || 'name'),
|
|
133
|
+
email: getByPath(item, map.emailPath || 'email'),
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function unAuthorize({ user }) {
|
|
138
|
+
const cfg = await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId);
|
|
139
|
+
if (cfg?.operations?.unAuthorize) {
|
|
140
|
+
await performRequest({
|
|
141
|
+
config: cfg,
|
|
142
|
+
opName: 'unAuthorize',
|
|
143
|
+
inputs: {},
|
|
144
|
+
user,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
user.accessToken = '';
|
|
148
|
+
user.refreshToken = '';
|
|
149
|
+
await user.save();
|
|
150
|
+
return {
|
|
151
|
+
successful: true,
|
|
152
|
+
returnMessage: {
|
|
153
|
+
messageType: 'success',
|
|
154
|
+
message: 'Logged out',
|
|
155
|
+
ttl: 1000
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function findContact({ user, authHeader, phoneNumber, overridingFormat, isExtension, proxyConfig }) {
|
|
161
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
|
|
162
|
+
if (!cfg.operations?.findContact) {
|
|
163
|
+
return { successful: true, matchedContactInfo: [] };
|
|
164
|
+
}
|
|
165
|
+
let formattedPhoneNumber = phoneNumber.replace(' ', '+')
|
|
166
|
+
const parsedPhoneNumber = parsePhoneNumber(formattedPhoneNumber);
|
|
167
|
+
const response = await performRequest({
|
|
168
|
+
config: cfg,
|
|
169
|
+
opName: 'findContact',
|
|
170
|
+
inputs: { phoneNumber, parsedPhoneNumber, overridingFormat, isExtension },
|
|
171
|
+
user,
|
|
172
|
+
authHeader
|
|
173
|
+
});
|
|
174
|
+
const matchedContactInfo = mapFindContactResponse({ config: cfg, response });
|
|
175
|
+
return {
|
|
176
|
+
successful: true,
|
|
177
|
+
matchedContactInfo,
|
|
178
|
+
returnMessage: {
|
|
179
|
+
messageType: 'success',
|
|
180
|
+
message: `Found ${matchedContactInfo.length} contacts`,
|
|
181
|
+
ttl: 3000
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function createContact({ user, authHeader, phoneNumber, newContactName, newContactType, additionalSubmission, proxyConfig }) {
|
|
187
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
|
|
188
|
+
if (!cfg.operations?.createContact) {
|
|
189
|
+
return { contactInfo: null, returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
|
|
190
|
+
}
|
|
191
|
+
const response = await performRequest({
|
|
192
|
+
config: cfg,
|
|
193
|
+
opName: 'createContact',
|
|
194
|
+
inputs: { phoneNumber, newContactName, newContactType, additionalSubmission },
|
|
195
|
+
user,
|
|
196
|
+
authHeader
|
|
197
|
+
});
|
|
198
|
+
const map = cfg.operations.createContact.responseMapping || {};
|
|
199
|
+
const responseCtx = { body: response.data };
|
|
200
|
+
const contactInfo = map.idPath ? {
|
|
201
|
+
id: getByPath(responseCtx, map.idPath || 'body.id'),
|
|
202
|
+
name: getByPath(responseCtx, map.namePath || 'body.name'),
|
|
203
|
+
type: getByPath(responseCtx, map.typePath || 'body.type') || 'Contact',
|
|
204
|
+
} : null;
|
|
205
|
+
return { contactInfo, returnMessage: { message: 'Contact created', messageType: 'success', ttl: 2000 } };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function findContactWithName({ user, authHeader, name, proxyConfig }) {
|
|
209
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
|
|
210
|
+
if (!cfg.operations?.findContactWithName) {
|
|
211
|
+
return { successful: true, matchedContactInfo: [] };
|
|
212
|
+
}
|
|
213
|
+
const response = await performRequest({
|
|
214
|
+
config: cfg,
|
|
215
|
+
opName: 'findContactWithName',
|
|
216
|
+
inputs: { name },
|
|
217
|
+
user,
|
|
218
|
+
authHeader
|
|
219
|
+
});
|
|
220
|
+
const matchedContactInfo = mapFindContactResponse({ config: cfg, response });
|
|
221
|
+
return {
|
|
222
|
+
successful: true,
|
|
223
|
+
matchedContactInfo,
|
|
224
|
+
returnMessage: {
|
|
225
|
+
messageType: 'success',
|
|
226
|
+
message: `Found ${matchedContactInfo.length} contacts`,
|
|
227
|
+
ttl: 3000
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function getLogFormatType(platform, proxyConfig) {
|
|
233
|
+
return proxyConfig ? proxyConfig.meta?.logFormat : 'custom';
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function createCallLog({
|
|
237
|
+
user,
|
|
238
|
+
contactInfo,
|
|
239
|
+
authHeader,
|
|
240
|
+
callLog,
|
|
241
|
+
note,
|
|
242
|
+
additionalSubmission,
|
|
243
|
+
aiNote,
|
|
244
|
+
transcript,
|
|
245
|
+
ringSenseTranscript = '',
|
|
246
|
+
ringSenseSummary = '',
|
|
247
|
+
ringSenseAIScore = '',
|
|
248
|
+
ringSenseBulletedSummary = '',
|
|
249
|
+
ringSenseLink = '',
|
|
250
|
+
composedLogDetails,
|
|
251
|
+
hashedAccountId,
|
|
252
|
+
isFromSSCL,
|
|
253
|
+
proxyConfig = null,
|
|
254
|
+
}) {
|
|
255
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
|
|
256
|
+
if (!cfg || !cfg.operations?.createCallLog) {
|
|
257
|
+
return { logId: undefined, returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
|
|
258
|
+
}
|
|
259
|
+
const response = await performRequest({
|
|
260
|
+
config: cfg,
|
|
261
|
+
opName: 'createCallLog',
|
|
262
|
+
inputs: {
|
|
263
|
+
contactInfo,
|
|
264
|
+
callLog,
|
|
265
|
+
note,
|
|
266
|
+
additionalSubmission,
|
|
267
|
+
aiNote,
|
|
268
|
+
transcript,
|
|
269
|
+
composedLogDetails,
|
|
270
|
+
hashedAccountId,
|
|
271
|
+
isFromSSCL,
|
|
272
|
+
subject: callLog.customSubject ?? `${callLog.direction} Call ${callLog.direction === 'Outbound' ? 'to' : 'from'} ${contactInfo.name}`,
|
|
273
|
+
startTime: moment(callLog.startTime).utc().toISOString(),
|
|
274
|
+
endTime: moment(callLog.startTime).utc().add(callLog.duration, 'seconds').toISOString(),
|
|
275
|
+
ringSenseTranscript,
|
|
276
|
+
ringSenseSummary,
|
|
277
|
+
ringSenseAIScore,
|
|
278
|
+
ringSenseBulletedSummary,
|
|
279
|
+
ringSenseLink,
|
|
280
|
+
},
|
|
281
|
+
user,
|
|
282
|
+
authHeader
|
|
283
|
+
});
|
|
284
|
+
const { logId } = mapCreateCallLogResponse({ config: cfg, response });
|
|
285
|
+
return {
|
|
286
|
+
logId,
|
|
287
|
+
returnMessage: {
|
|
288
|
+
message: 'Call logged',
|
|
289
|
+
messageType: 'success',
|
|
290
|
+
ttl: 2000
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async function getCallLog({ user, callLogId, contactId, authHeader, proxyConfig = null }) {
|
|
296
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
|
|
297
|
+
if (!cfg || !cfg.operations?.getCallLog) {
|
|
298
|
+
return { callLogInfo: null, returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
|
|
299
|
+
}
|
|
300
|
+
const response = await performRequest({
|
|
301
|
+
config: cfg,
|
|
302
|
+
opName: 'getCallLog',
|
|
303
|
+
inputs: { thirdPartyLogId: callLogId, contactId },
|
|
304
|
+
user,
|
|
305
|
+
authHeader
|
|
306
|
+
});
|
|
307
|
+
const mapped = mapGetCallLogResponse({ config: cfg, response });
|
|
308
|
+
return Object.assign(mapped, { returnMessage: { message: 'Call log fetched.', messageType: 'success', ttl: 3000 } });
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async function updateCallLog({
|
|
312
|
+
user,
|
|
313
|
+
existingCallLog,
|
|
314
|
+
authHeader,
|
|
315
|
+
recordingLink,
|
|
316
|
+
recordingDownloadLink,
|
|
317
|
+
subject,
|
|
318
|
+
note,
|
|
319
|
+
startTime,
|
|
320
|
+
duration,
|
|
321
|
+
result,
|
|
322
|
+
aiNote,
|
|
323
|
+
transcript,
|
|
324
|
+
legs,
|
|
325
|
+
ringSenseTranscript = '',
|
|
326
|
+
ringSenseSummary = '',
|
|
327
|
+
ringSenseAIScore = '',
|
|
328
|
+
ringSenseBulletedSummary = '',
|
|
329
|
+
ringSenseLink = '',
|
|
330
|
+
additionalSubmission,
|
|
331
|
+
composedLogDetails,
|
|
332
|
+
existingCallLogDetails,
|
|
333
|
+
hashedAccountId,
|
|
334
|
+
isFromSSCL,
|
|
335
|
+
proxyConfig = null,
|
|
336
|
+
}) {
|
|
337
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
|
|
338
|
+
if (!cfg || !cfg.operations?.updateCallLog) {
|
|
339
|
+
return { returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
|
|
340
|
+
}
|
|
341
|
+
await performRequest({
|
|
342
|
+
config: cfg,
|
|
343
|
+
opName: 'updateCallLog',
|
|
344
|
+
inputs: {
|
|
345
|
+
thirdPartyLogId: existingCallLog?.thirdPartyLogId,
|
|
346
|
+
existingCallLog,
|
|
347
|
+
recordingLink,
|
|
348
|
+
recordingDownloadLink,
|
|
349
|
+
subject,
|
|
350
|
+
note,
|
|
351
|
+
startTime: moment(startTime).utc().toISOString(),
|
|
352
|
+
endTime: moment(startTime).utc().add(duration, 'seconds').toISOString(),
|
|
353
|
+
duration,
|
|
354
|
+
result,
|
|
355
|
+
aiNote,
|
|
356
|
+
transcript,
|
|
357
|
+
legs,
|
|
358
|
+
additionalSubmission,
|
|
359
|
+
composedLogDetails,
|
|
360
|
+
existingCallLogDetails,
|
|
361
|
+
hashedAccountId,
|
|
362
|
+
isFromSSCL,
|
|
363
|
+
ringSenseTranscript,
|
|
364
|
+
ringSenseSummary,
|
|
365
|
+
ringSenseAIScore,
|
|
366
|
+
ringSenseBulletedSummary,
|
|
367
|
+
ringSenseLink,
|
|
368
|
+
},
|
|
369
|
+
user,
|
|
370
|
+
authHeader
|
|
371
|
+
});
|
|
372
|
+
return {
|
|
373
|
+
updatedNote: null,
|
|
374
|
+
returnMessage: {
|
|
375
|
+
message: 'Call log updated.',
|
|
376
|
+
messageType: 'success',
|
|
377
|
+
ttl: 3000
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async function upsertCallDisposition({ user, existingCallLog, authHeader, dispositions, proxyConfig }) {
|
|
383
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
|
|
384
|
+
if (!cfg.operations?.upsertCallDisposition) {
|
|
385
|
+
return { returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
|
|
386
|
+
}
|
|
387
|
+
await performRequest({
|
|
388
|
+
config: cfg,
|
|
389
|
+
opName: 'upsertCallDisposition',
|
|
390
|
+
inputs: { existingCallLog, dispositions, thirdPartyLogId: existingCallLog?.thirdPartyLogId },
|
|
391
|
+
user,
|
|
392
|
+
authHeader
|
|
393
|
+
});
|
|
394
|
+
return { logId: existingCallLog.thirdPartyLogId, returnMessage: { message: 'Disposition updated', messageType: 'success', ttl: 2000 } };
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
async function createMessageLog({ user, contactInfo, authHeader, message, additionalSubmission, recordingLink, faxDocLink, faxDownloadLink, imageLink, videoLink, proxyConfig }) {
|
|
398
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
|
|
399
|
+
if (!cfg.operations?.createMessageLog) {
|
|
400
|
+
return { logId: undefined, returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
|
|
401
|
+
}
|
|
402
|
+
const response = await performRequest({
|
|
403
|
+
config: cfg,
|
|
404
|
+
opName: 'createMessageLog',
|
|
405
|
+
inputs: {
|
|
406
|
+
contactInfo,
|
|
407
|
+
message,
|
|
408
|
+
additionalSubmission,
|
|
409
|
+
recordingLink,
|
|
410
|
+
faxDocLink,
|
|
411
|
+
faxDownloadLink,
|
|
412
|
+
imageLink,
|
|
413
|
+
videoLink,
|
|
414
|
+
creationTime: moment(message.creationTime).utc().toISOString(),
|
|
415
|
+
},
|
|
416
|
+
user,
|
|
417
|
+
authHeader
|
|
418
|
+
});
|
|
419
|
+
const map = cfg.operations.createMessageLog.responseMapping || {};
|
|
420
|
+
const responseCtx = { body: response.data };
|
|
421
|
+
const logId = getByPath(responseCtx, map.idPath || 'body.id');
|
|
422
|
+
return {
|
|
423
|
+
logId: logId ? String(logId) : undefined,
|
|
424
|
+
returnMessage: { message: 'Message logged', messageType: 'success', ttl: 1000 }
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
async function updateMessageLog({ user, contactInfo, existingMessageLog, message, authHeader, additionalSubmission, imageLink, videoLink, proxyConfig }) {
|
|
429
|
+
const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
|
|
430
|
+
if (!cfg.operations?.updateMessageLog) {
|
|
431
|
+
return { returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
|
|
432
|
+
}
|
|
433
|
+
await performRequest({
|
|
434
|
+
config: cfg,
|
|
435
|
+
opName: 'updateMessageLog',
|
|
436
|
+
inputs: {
|
|
437
|
+
contactInfo,
|
|
438
|
+
existingMessageLog,
|
|
439
|
+
thirdPartyLogId: existingMessageLog?.thirdPartyLogId,
|
|
440
|
+
message,
|
|
441
|
+
additionalSubmission,
|
|
442
|
+
imageLink,
|
|
443
|
+
videoLink,
|
|
444
|
+
creationTime: moment(message.creationTime).utc().toISOString(),
|
|
445
|
+
},
|
|
446
|
+
user,
|
|
447
|
+
authHeader
|
|
448
|
+
});
|
|
449
|
+
return { returnMessage: { message: 'Message log updated', messageType: 'success', ttl: 3000 } };
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
async function getLicenseStatus({ userId, platform }) {
|
|
453
|
+
const user = await UserModel.findByPk(userId);
|
|
454
|
+
if (!user || !user.accessToken) {
|
|
455
|
+
return { isLicenseValid: false, licenseStatus: 'Invalid (User not found)', licenseStatusDescription: '' };
|
|
456
|
+
}
|
|
457
|
+
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
458
|
+
const cfg = await loadPlatformConfig(proxyId);
|
|
459
|
+
if (!cfg.operations?.getLicenseStatus) {
|
|
460
|
+
return { isLicenseValid: true, licenseStatus: 'Basic', licenseStatusDescription: '' };
|
|
461
|
+
}
|
|
462
|
+
const response = await performRequest({
|
|
463
|
+
config: cfg,
|
|
464
|
+
opName: 'getLicenseStatus',
|
|
465
|
+
inputs: { userId, platform },
|
|
466
|
+
user,
|
|
467
|
+
});
|
|
468
|
+
const map = cfg.operations.getLicenseStatus.responseMapping || {};
|
|
469
|
+
const responseCtx = { body: response.data };
|
|
470
|
+
const isLicenseValid = getByPath(responseCtx, map.isLicenseValidPath || 'body.isLicenseValid');
|
|
471
|
+
const licenseStatus = getByPath(responseCtx, map.licenseStatusPath || 'body.licenseStatus');
|
|
472
|
+
const licenseStatusDescription = getByPath(responseCtx, map.licenseStatusDescriptionPath || 'body.licenseStatusDescription');
|
|
473
|
+
return { isLicenseValid, licenseStatus, licenseStatusDescription };
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
exports.getAuthType = getAuthType;
|
|
477
|
+
exports.getOauthInfo = getOauthInfo;
|
|
478
|
+
exports.getBasicAuth = getBasicAuth;
|
|
479
|
+
exports.getUserInfo = getUserInfo;
|
|
480
|
+
exports.createCallLog = createCallLog;
|
|
481
|
+
exports.updateCallLog = updateCallLog;
|
|
482
|
+
exports.getCallLog = getCallLog;
|
|
483
|
+
exports.createMessageLog = createMessageLog;
|
|
484
|
+
exports.updateMessageLog = updateMessageLog;
|
|
485
|
+
exports.findContact = findContact;
|
|
486
|
+
exports.createContact = createContact;
|
|
487
|
+
exports.findContactWithName = findContactWithName;
|
|
488
|
+
exports.unAuthorize = unAuthorize;
|
|
489
|
+
exports.getLicenseStatus = getLicenseStatus;
|
|
490
|
+
exports.upsertCallDisposition = upsertCallDisposition;
|
|
491
|
+
exports.getUserList = getUserList;
|
|
492
|
+
exports.getLogFormatType = getLogFormatType;
|