@tiledesk/tiledesk-tybot-connector 0.2.35 → 0.2.37
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +121 -176
- package/tiledeskChatbotPlugs/directives/DirAskGPT_OLD.js +405 -0
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +133 -200
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +434 -0
- package/tiledeskChatbotPlugs/directives/DirQapla.js +41 -70
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
const axios = require("axios").default;
|
|
2
|
+
const { TiledeskChatbot } = require("../../models/TiledeskChatbot");
|
|
3
|
+
const { Filler } = require("../Filler");
|
|
4
|
+
let https = require("https");
|
|
5
|
+
const { DirIntent } = require("./DirIntent");
|
|
6
|
+
require('dotenv').config();
|
|
7
|
+
|
|
8
|
+
class DirGptTask {
|
|
9
|
+
|
|
10
|
+
constructor(context) {
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('context object is mandatory');
|
|
13
|
+
}
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.tdcache = this.context.tdcache;
|
|
16
|
+
this.requestId = this.context.requestId;
|
|
17
|
+
this.intentDir = new DirIntent(context);
|
|
18
|
+
this.log = context.log;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
execute(directive, callback) {
|
|
22
|
+
if (this.log) { console.log("GptTask directive: ", directive); }
|
|
23
|
+
let action;
|
|
24
|
+
if (directive.action) {
|
|
25
|
+
action = directive.action;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.error("Incorrect directive: ", JSON.stringify(directive));
|
|
29
|
+
callback();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.go(action, (stop) => {
|
|
33
|
+
callback(stop);
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async go(action, callback) {
|
|
38
|
+
if (this.log) { console.log("DirGptTask action:", JSON.stringify(action)); }
|
|
39
|
+
if (!this.tdcache) {
|
|
40
|
+
console.error("Error: DirGptTask tdcache is mandatory");
|
|
41
|
+
callback();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let trueIntent = action.trueIntent;
|
|
46
|
+
let falseIntent = action.falseIntent;
|
|
47
|
+
let trueIntentAttributes = action.trueIntentAttributes;
|
|
48
|
+
let falseIntentAttributes = action.falseIntentAttributes;
|
|
49
|
+
|
|
50
|
+
if (this.log) {
|
|
51
|
+
console.log("DirAskGPT trueIntent", trueIntent)
|
|
52
|
+
console.log("DirAskGPT falseIntent", falseIntent)
|
|
53
|
+
console.log("DirAskGPT trueIntentAttributes", trueIntentAttributes)
|
|
54
|
+
console.log("DirAskGPT falseIntentAttributes", falseIntentAttributes)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// default value
|
|
58
|
+
let answer = "No answer.";
|
|
59
|
+
|
|
60
|
+
if (!action.question || action.question === '') {
|
|
61
|
+
console.error("Error: DirGptTask question attribute is mandatory. Executing condition false...")
|
|
62
|
+
if (falseIntent) {
|
|
63
|
+
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
64
|
+
callback(true);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
callback();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let requestVariables = null;
|
|
72
|
+
requestVariables =
|
|
73
|
+
await TiledeskChatbot.allParametersStatic(
|
|
74
|
+
this.tdcache, this.requestId
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
const filler = new Filler();
|
|
78
|
+
const filled_question = filler.fill(action.question, requestVariables);
|
|
79
|
+
|
|
80
|
+
let max_tokens = action.max_tokens;
|
|
81
|
+
let temperature = action.temperature;
|
|
82
|
+
|
|
83
|
+
if (this.log) {
|
|
84
|
+
console.log("DirGptTask max_tokens: ", max_tokens);
|
|
85
|
+
console.log("DirGptTask temperature: ", temperature);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
89
|
+
const openai_url = process.env.OPENAI_ENDPOINT + "/chat/completions";
|
|
90
|
+
if (this.log) {
|
|
91
|
+
console.log("DirGptTask server_base_url ", server_base_url);
|
|
92
|
+
console.log("DirGptTask openai_url ", openai_url);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const INTEGRATIONS_HTTPREQUEST = {
|
|
96
|
+
url: server_base_url + "/" + this.context.projectId + "/integration/name/openai",
|
|
97
|
+
headers: {
|
|
98
|
+
'Content-Type': 'application/json',
|
|
99
|
+
'Authorization': 'JWT ' + this.context.token
|
|
100
|
+
},
|
|
101
|
+
method: "GET"
|
|
102
|
+
}
|
|
103
|
+
if (this.log) { console.log("DirGptTask INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
|
|
104
|
+
|
|
105
|
+
this.#myrequest(
|
|
106
|
+
INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
|
|
107
|
+
if (err) {
|
|
108
|
+
if (callback) {
|
|
109
|
+
console.error("(httprequest) DirGptTask get integrations err:", err);
|
|
110
|
+
// Don't stop the flow here. Try aniway to retrieve the key from KBs
|
|
111
|
+
// callback();
|
|
112
|
+
// return;
|
|
113
|
+
}
|
|
114
|
+
} else if (callback) {
|
|
115
|
+
if (this.log) { console.log("DirGptTask get integration resbody: ", integration); }
|
|
116
|
+
|
|
117
|
+
let key;
|
|
118
|
+
if (integration &&
|
|
119
|
+
integration.value) {
|
|
120
|
+
key = integration.value.apikey;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// key not present in integrations - for retro compatibility search in kbsettings
|
|
124
|
+
if (!key) {
|
|
125
|
+
|
|
126
|
+
// if (this.log) { console.log("DirGptTask - Key not found in Integrations. Searching in kb settings...")}
|
|
127
|
+
if (this.log) { console.log("DirGptTask - Key not found in Integrations. Searching in kb settings..."); }
|
|
128
|
+
|
|
129
|
+
const KB_HTTPREQUEST = {
|
|
130
|
+
url: server_base_url + "/" + this.context.projectId + "/kbsettings",
|
|
131
|
+
headers: {
|
|
132
|
+
'Content-Type': 'application/json',
|
|
133
|
+
'Authorization': 'JWT ' + this.context.token
|
|
134
|
+
},
|
|
135
|
+
method: "GET"
|
|
136
|
+
}
|
|
137
|
+
if (this.log) { console.log("DirGptTask KB_HTTPREQUEST", KB_HTTPREQUEST); }
|
|
138
|
+
|
|
139
|
+
this.#myrequest(
|
|
140
|
+
KB_HTTPREQUEST, async (err, resbody) => {
|
|
141
|
+
if (err) {
|
|
142
|
+
if (callback) {
|
|
143
|
+
console.error("(httprequest) DirGptTask Get KnowledgeBase err:", err);
|
|
144
|
+
await this.#assignAttributes(action, answer);
|
|
145
|
+
if (falseIntent) {
|
|
146
|
+
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
147
|
+
callback(true);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
callback();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
} else if (callback) {
|
|
154
|
+
if (this.log) { console.log("DirGptTask Get KnowledgeBase settings resbody:", resbody); }
|
|
155
|
+
|
|
156
|
+
if (!resbody.gptkey) {
|
|
157
|
+
await this.#assignAttributes(action, answer);
|
|
158
|
+
if (falseIntent) {
|
|
159
|
+
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
160
|
+
callback(true);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
callback();
|
|
164
|
+
return;
|
|
165
|
+
|
|
166
|
+
} else {
|
|
167
|
+
|
|
168
|
+
if (this.log) { console.log("DirGptTask - Key found in KbSettings") };
|
|
169
|
+
|
|
170
|
+
key = resbody.gptkey;
|
|
171
|
+
|
|
172
|
+
let json = {
|
|
173
|
+
"model": action.model,
|
|
174
|
+
"messages": [
|
|
175
|
+
{
|
|
176
|
+
"role": "user",
|
|
177
|
+
"content": filled_question
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
"max_tokens": action.max_tokens,
|
|
181
|
+
"temperature": action.temperature
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
let message = { role: "", content: "" };
|
|
185
|
+
if (action.context) {
|
|
186
|
+
message.role = "system";
|
|
187
|
+
message.content = action.context;
|
|
188
|
+
json.messages.unshift(message);
|
|
189
|
+
}
|
|
190
|
+
if (this.log) { console.log("DirGptTask json: ", json) }
|
|
191
|
+
|
|
192
|
+
const HTTPREQUEST = {
|
|
193
|
+
url: openai_url,
|
|
194
|
+
headers: {
|
|
195
|
+
'Content-Type': 'application/json',
|
|
196
|
+
'Authorization': 'Bearer ' + key
|
|
197
|
+
},
|
|
198
|
+
json: json,
|
|
199
|
+
method: 'POST'
|
|
200
|
+
}
|
|
201
|
+
if (this.log) { console.log("DirGptTask HTTPREQUEST: ", HTTPREQUEST); }
|
|
202
|
+
this.#myrequest(
|
|
203
|
+
HTTPREQUEST, async (err, resbody) => {
|
|
204
|
+
if (err) {
|
|
205
|
+
if (this.log) {
|
|
206
|
+
console.error("(httprequest) DirGptTask openai err:", err);
|
|
207
|
+
console.error("(httprequest) DirGptTask openai err:", err.response.data);
|
|
208
|
+
}
|
|
209
|
+
await this.#assignAttributes(action, answer);
|
|
210
|
+
if (falseIntent) {
|
|
211
|
+
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
212
|
+
callback(true);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
callback();
|
|
216
|
+
return;
|
|
217
|
+
} else {
|
|
218
|
+
if (this.log) { console.log("DirGptTask resbody: ", JSON.stringify(resbody)); }
|
|
219
|
+
answer = resbody.choices[0].message.content;
|
|
220
|
+
let answer_json = await this.convertToJson(answer);
|
|
221
|
+
await this.#assignAttributes(action, answer_json);
|
|
222
|
+
if (trueIntent) {
|
|
223
|
+
await this.#executeCondition(true, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
224
|
+
callback(true);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
callback();
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
} else {
|
|
237
|
+
|
|
238
|
+
if (this.log) { console.log("DirGptTask - Key found in Integrations") };
|
|
239
|
+
|
|
240
|
+
let json = {
|
|
241
|
+
"model": action.model,
|
|
242
|
+
"messages": [
|
|
243
|
+
{
|
|
244
|
+
"role": "user",
|
|
245
|
+
"content": filled_question
|
|
246
|
+
}
|
|
247
|
+
],
|
|
248
|
+
"max_tokens": action.max_tokens,
|
|
249
|
+
"temperature": action.temperature
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
let message = { role: "", content: "" };
|
|
253
|
+
if (action.context) {
|
|
254
|
+
message.role = "system";
|
|
255
|
+
message.content = action.context;
|
|
256
|
+
json.messages.unshift(message);
|
|
257
|
+
}
|
|
258
|
+
if (this.log) { console.log("DirGptTask json: ", json) }
|
|
259
|
+
|
|
260
|
+
const HTTPREQUEST = {
|
|
261
|
+
url: openai_url,
|
|
262
|
+
headers: {
|
|
263
|
+
'Content-Type': 'application/json',
|
|
264
|
+
'Authorization': 'Bearer ' + key
|
|
265
|
+
},
|
|
266
|
+
json: json,
|
|
267
|
+
method: 'POST'
|
|
268
|
+
}
|
|
269
|
+
if (this.log) { console.log("DirGptTask HTTPREQUEST: ", HTTPREQUEST); }
|
|
270
|
+
this.#myrequest(
|
|
271
|
+
HTTPREQUEST, async (err, resbody) => {
|
|
272
|
+
if (err) {
|
|
273
|
+
if (this.log) {
|
|
274
|
+
console.error("(httprequest) DirGptTask openai err:", err);
|
|
275
|
+
console.error("(httprequest) DirGptTask openai err:", err.response.data);
|
|
276
|
+
}
|
|
277
|
+
await this.#assignAttributes(action, answer);
|
|
278
|
+
if (falseIntent) {
|
|
279
|
+
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
280
|
+
callback(true);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
callback();
|
|
284
|
+
return;
|
|
285
|
+
} else {
|
|
286
|
+
if (this.log) { console.log("DirGptTask resbody: ", JSON.stringify(resbody)); }
|
|
287
|
+
answer = resbody.choices[0].message.content;
|
|
288
|
+
// check if answer is a json
|
|
289
|
+
let answer_json = await this.convertToJson(answer);
|
|
290
|
+
await this.#assignAttributes(action, answer_json);
|
|
291
|
+
if (trueIntent) {
|
|
292
|
+
await this.#executeCondition(true, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
293
|
+
callback(true);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
callback();
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async convertToJson(data) {
|
|
309
|
+
|
|
310
|
+
return new Promise((resolve) => {
|
|
311
|
+
let json = null;
|
|
312
|
+
try {
|
|
313
|
+
json = JSON.parse(data);
|
|
314
|
+
resolve(json)
|
|
315
|
+
} catch(err) {
|
|
316
|
+
resolve(data)
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async #executeCondition(result, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes, callback) {
|
|
323
|
+
let trueIntentDirective = null;
|
|
324
|
+
if (trueIntent) {
|
|
325
|
+
trueIntentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
|
|
326
|
+
}
|
|
327
|
+
let falseIntentDirective = null;
|
|
328
|
+
if (falseIntent) {
|
|
329
|
+
falseIntentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
330
|
+
}
|
|
331
|
+
if (result === true) {
|
|
332
|
+
if (trueIntentDirective) {
|
|
333
|
+
this.intentDir.execute(trueIntentDirective, () => {
|
|
334
|
+
if (callback) {
|
|
335
|
+
callback();
|
|
336
|
+
}
|
|
337
|
+
})
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
if (this.log) { console.log("No trueIntentDirective specified"); }
|
|
341
|
+
if (callback) {
|
|
342
|
+
callback();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
if (falseIntentDirective) {
|
|
348
|
+
this.intentDir.execute(falseIntentDirective, () => {
|
|
349
|
+
if (callback) {
|
|
350
|
+
callback();
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
if (this.log) { console.log("No falseIntentDirective specified"); }
|
|
356
|
+
if (callback) {
|
|
357
|
+
callback();
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
async #assignAttributes(action, answer) {
|
|
364
|
+
if (this.log) {
|
|
365
|
+
console.log("assignAttributes action:", action)
|
|
366
|
+
console.log("assignAttributes answer:", answer)
|
|
367
|
+
}
|
|
368
|
+
if (this.context.tdcache) {
|
|
369
|
+
if (action.assignReplyTo && answer) {
|
|
370
|
+
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignReplyTo, answer);
|
|
371
|
+
}
|
|
372
|
+
// if (action.assignSourceTo && source) {
|
|
373
|
+
// await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignSourceTo, source);
|
|
374
|
+
// }
|
|
375
|
+
// Debug log
|
|
376
|
+
if (this.log) {
|
|
377
|
+
const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
378
|
+
for (const [key, value] of Object.entries(all_parameters)) {
|
|
379
|
+
if (this.log) { console.log("(askgpt) request parameter:", key, "value:", value, "type:", typeof value) }
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
#myrequest(options, callback) {
|
|
386
|
+
if (this.log) {
|
|
387
|
+
console.log("API URL:", options.url);
|
|
388
|
+
console.log("** Options:", JSON.stringify(options));
|
|
389
|
+
}
|
|
390
|
+
let axios_options = {
|
|
391
|
+
url: options.url,
|
|
392
|
+
method: options.method,
|
|
393
|
+
params: options.params,
|
|
394
|
+
headers: options.headers
|
|
395
|
+
}
|
|
396
|
+
if (options.json !== null) {
|
|
397
|
+
axios_options.data = options.json
|
|
398
|
+
}
|
|
399
|
+
if (this.log) {
|
|
400
|
+
console.log("axios_options:", JSON.stringify(axios_options));
|
|
401
|
+
}
|
|
402
|
+
if (options.url.startsWith("https:")) {
|
|
403
|
+
const httpsAgent = new https.Agent({
|
|
404
|
+
rejectUnauthorized: false,
|
|
405
|
+
});
|
|
406
|
+
axios_options.httpsAgent = httpsAgent;
|
|
407
|
+
}
|
|
408
|
+
axios(axios_options)
|
|
409
|
+
.then((res) => {
|
|
410
|
+
if (this.log) {
|
|
411
|
+
console.log("Response for url:", options.url);
|
|
412
|
+
console.log("Response headers:\n", JSON.stringify(res.headers));
|
|
413
|
+
}
|
|
414
|
+
if (res && res.status == 200 && res.data) {
|
|
415
|
+
if (callback) {
|
|
416
|
+
callback(null, res.data);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
if (callback) {
|
|
421
|
+
callback(new Error("Response status is not 200"), null);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
})
|
|
425
|
+
.catch((error) => {
|
|
426
|
+
// console.error("An error occurred:", JSON.stringify(error.data));
|
|
427
|
+
if (callback) {
|
|
428
|
+
callback(error, null);
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
module.exports = { DirGptTask }
|
|
@@ -62,92 +62,63 @@ class DirQapla {
|
|
|
62
62
|
callback();
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
const key = action.apiKey;
|
|
66
|
+
console.log("action.key: ", action.apiKey)
|
|
67
|
+
|
|
68
|
+
if (!key) {
|
|
69
|
+
console.error("DirQapla ERROR - key is undefined");
|
|
70
|
+
callback();
|
|
71
|
+
}
|
|
72
|
+
|
|
65
73
|
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
66
74
|
const qapla_base_url = process.env.QAPLA_ENDPOINT || "https://api.qapla.it/1.2"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
if (this.log) {
|
|
76
|
+
console.log("DirQapla server_base_url: ", qapla_base_url);
|
|
77
|
+
console.log("DirQapla qapla_base_url: ", qapla_base_url);
|
|
78
|
+
}
|
|
79
|
+
const QAPLA_HTTPREQUEST = {
|
|
80
|
+
url: qapla_base_url + "/getShipment/",
|
|
70
81
|
headers: {
|
|
71
|
-
'Content-Type': 'application/json'
|
|
72
|
-
|
|
82
|
+
'Content-Type': 'application/json'
|
|
83
|
+
},
|
|
84
|
+
params: {
|
|
85
|
+
apiKey: key,
|
|
86
|
+
trackingNumber: tracking_number
|
|
73
87
|
},
|
|
74
88
|
method: "GET"
|
|
75
89
|
}
|
|
76
|
-
if (this.log) { console.log("DirQapla
|
|
90
|
+
if (this.log) { console.log("DirQapla QAPLA_HTTPREQUEST", QAPLA_HTTPREQUEST); }
|
|
77
91
|
|
|
78
92
|
this.#myrequest(
|
|
79
|
-
|
|
93
|
+
QAPLA_HTTPREQUEST, async (err, resbody) => {
|
|
80
94
|
if (err) {
|
|
81
95
|
if (callback) {
|
|
82
|
-
console.error("(httprequest) DirQapla
|
|
96
|
+
console.error("(httprequest) DirQapla getShipment err:", err);
|
|
83
97
|
callback();
|
|
84
98
|
}
|
|
85
99
|
} else if (callback) {
|
|
86
|
-
if (this.log) { console.log("DirQapla
|
|
87
|
-
|
|
88
|
-
let
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
console.log("DirQapla invalid or empty key");
|
|
100
|
-
callback();
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
100
|
+
if (this.log) { console.log("DirQapla getShipment resbody: ", resbody); }
|
|
101
|
+
|
|
102
|
+
let status = null;;
|
|
103
|
+
let result;
|
|
104
|
+
let error;
|
|
105
|
+
|
|
106
|
+
if (resbody.getShipment &&
|
|
107
|
+
resbody.getShipment.shipments &&
|
|
108
|
+
resbody.getShipment.shipments[0] &&
|
|
109
|
+
resbody.getShipment.shipments[0].status &&
|
|
110
|
+
resbody.getShipment.shipments[0].status.qaplaStatus &&
|
|
111
|
+
resbody.getShipment.shipments[0].status.qaplaStatus.status) {
|
|
112
|
+
status = resbody.getShipment.shipments[0].status.qaplaStatus.status;
|
|
103
113
|
}
|
|
104
114
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
'Content-Type': 'application/json'
|
|
110
|
-
},
|
|
111
|
-
params: {
|
|
112
|
-
apiKey: key,
|
|
113
|
-
trackingNumber: tracking_number
|
|
114
|
-
},
|
|
115
|
-
method: "GET"
|
|
116
|
-
}
|
|
117
|
-
if (this.log) { console.log("DirQapla QAPLA_HTTPREQUEST", QAPLA_HTTPREQUEST); }
|
|
118
|
-
|
|
119
|
-
this.#myrequest(
|
|
120
|
-
QAPLA_HTTPREQUEST, async (err, resbody) => {
|
|
121
|
-
if (err) {
|
|
122
|
-
if (callback) {
|
|
123
|
-
console.error("(httprequest) DirQapla getShipment err:", err);
|
|
124
|
-
callback();
|
|
125
|
-
}
|
|
126
|
-
} else if (callback) {
|
|
127
|
-
if (this.log) { console.log("DirQapla getShipment resbody: ", resbody); }
|
|
128
|
-
|
|
129
|
-
let status = null;;
|
|
130
|
-
let result;
|
|
131
|
-
let error;
|
|
132
|
-
|
|
133
|
-
if (resbody.getShipment &&
|
|
134
|
-
resbody.getShipment.shipments &&
|
|
135
|
-
resbody.getShipment.shipments[0] &&
|
|
136
|
-
resbody.getShipment.shipments[0].status &&
|
|
137
|
-
resbody.getShipment.shipments[0].status.qaplaStatus &&
|
|
138
|
-
resbody.getShipment.shipments[0].status.qaplaStatus.status) {
|
|
139
|
-
status = resbody.getShipment.shipments[0].status.qaplaStatus.status;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
result = resbody.getShipment.result;
|
|
143
|
-
error = resbody.getShipment.error;
|
|
144
|
-
await this.#assignAttributes(action, status, result, error);
|
|
145
|
-
callback();
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
)
|
|
115
|
+
result = resbody.getShipment.result;
|
|
116
|
+
error = resbody.getShipment.error;
|
|
117
|
+
await this.#assignAttributes(action, status, result, error);
|
|
118
|
+
callback();
|
|
149
119
|
}
|
|
150
|
-
}
|
|
120
|
+
}
|
|
121
|
+
)
|
|
151
122
|
}
|
|
152
123
|
|
|
153
124
|
|