@tiledesk/tiledesk-tybot-connector 0.2.95 → 0.2.96

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 CHANGED
@@ -5,6 +5,30 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ <!-- // CHECK IT!!!
9
+ # v0.2.98
10
+ - Added possibility to select namespace by name
11
+ - Added filler to namespace in DirAskGPTv2
12
+ - Added filler to command.settings in DirReply
13
+
14
+ # v0.2.97
15
+ - Added a limit in upload and download for WebRequestV2: maxContentLength: 10000000, // max 10mb response size, maxBodyLength: 10000000 // max 10mb request body size
16
+ - Added jsonCondition test on json objects properties
17
+ - Added flowError on JSONCondition when result = null
18
+ - Added fix on Filler -->
19
+
20
+ # v0.2.96
21
+ - Added timestamp (number) and now (Date Object) attributes
22
+
23
+ - Added a limit in upload and download for WebRequestV2: maxContentLength: 10000000, // max 10mb response size, maxBodyLength: 10000000 // max 10mb request body size
24
+ - Added jsonCondition test on json objects properties
25
+ - Added flowError on JSONCondition when result = null
26
+ - Added fix on Filler
27
+
28
+ - Added possibility to select namespace by name
29
+ - Added filler to namespace in DirAskGPTv2
30
+ - Added filler to command.settings in DirReply
31
+
8
32
  # v0.2.95
9
33
  - If Online Agents V2 - bug fix (If Project Available Agents V2 -> MWeb)
10
34
 
@@ -359,7 +359,7 @@ class TiledeskExpression {
359
359
  // console.log("operand1_s:", operand1_s);
360
360
  }
361
361
  else {
362
- console.error("Condition evaluation stopped because of invalid operand", condition.operand1);
362
+ console.error("Condition evaluation stopped because of invalid operand1", condition.operand1);
363
363
  return null;
364
364
  }
365
365
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.2.95",
3
+ "version": "0.2.96",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -4,6 +4,12 @@ var engine = new Liquid();
4
4
  class Filler {
5
5
 
6
6
  fill(text, parameters) {
7
+ // create dynamic attributes
8
+ if (parameters) {
9
+ parameters["timestamp"] = Date.now(); // type number
10
+ parameters["now"] = new Date(); // type Object
11
+ }
12
+
7
13
  // legacy parser first
8
14
  if (text == null || text == undefined || typeof text !== 'string') {
9
15
  // console.log("Skip filling. 'text' is null or not a string");
@@ -171,6 +171,25 @@ class DirAskGPTV2 {
171
171
  }
172
172
 
173
173
 
174
+ if (action.namespaceAsName) {
175
+ // Namespace could be an attribute
176
+ const filled_namespace = filler.fill(action.namespace, requestVariables)
177
+
178
+ // namespace = await this.getNamespaceIdFromName(server_base_url, action.namespace)
179
+ namespace = await this.getNamespaceIdFromName(server_base_url, filled_namespace);
180
+ if (this.log) { console.log("DirAskGPT - Retrieved namespace id from name ", namespace); }
181
+ }
182
+
183
+ if (!namespace) {
184
+ console.log("DirAskGPT - Error: namespace is undefined")
185
+ if (falseIntent) {
186
+ await this.chatbot.addParameter("flowError", "AskGPT Error: namespace is undefined");
187
+ await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
188
+ callback(true);
189
+ return;
190
+ }
191
+ }
192
+
174
193
  let json = {
175
194
  question: filled_question,
176
195
  gptkey: key,
@@ -202,7 +221,7 @@ class DirAskGPTV2 {
202
221
  }
203
222
 
204
223
  if (this.log) { console.log("DirAskGPT json:", json); }
205
-
224
+
206
225
  const HTTPREQUEST = {
207
226
  // url: server_base_url + "/" + this.context.projectId + "/kb/qa",
208
227
  url: kb_endpoint + "/qa",
@@ -546,6 +565,38 @@ class DirAskGPTV2 {
546
565
  return objectTranscript;
547
566
  }
548
567
 
568
+ async getNamespaceIdFromName(server_base_url, name) {
569
+ return new Promise((resolve) => {
570
+
571
+ const HTTPREQUEST = {
572
+ url: server_base_url + "/" + this.context.projectId + "/kb/namespace/all",
573
+ headers: {
574
+ 'Content-Type': 'application/json',
575
+ 'Authorization': 'JWT ' + this.context.token
576
+ },
577
+ method: "GET"
578
+ }
579
+ if (this.log) { console.log("DirAskGPT get all namespaces HTTPREQUEST", HTTPREQUEST); }
580
+
581
+ this.#myrequest(
582
+ HTTPREQUEST, async (err, namespaces) => {
583
+ if (err) {
584
+ console.error("(httprequest) DirAskGPT get all namespaces err: ", err);
585
+ resolve(null)
586
+ } else {
587
+ if (this.log) { console.log("(httprequest) DirAskGPT get all namespaces resbody: ", namespaces); }
588
+
589
+ let namespace = namespaces.find(n => n.name === name);
590
+ let namespace_id = namespace.id;
591
+
592
+ resolve(namespace_id);
593
+ }
594
+ }
595
+ )
596
+ })
597
+
598
+ }
599
+
549
600
 
550
601
  }
551
602
 
@@ -122,7 +122,7 @@ class DirDepartment {
122
122
  callback();
123
123
  }
124
124
  else {
125
- console.log("DirDepartment response:",JSON.stringify(res));
125
+ if (this.log) { console.log("DirDepartment response:",JSON.stringify(res)); }
126
126
  callback(deps);
127
127
  }
128
128
  });
@@ -110,6 +110,7 @@ class DirIfOnlineAgentsV2 {
110
110
  if (this.log) {console.log("(DirIfOnlineAgents) selectedOption === all | getProjectAvailableAgents(null, true)"); }
111
111
  agents = await this.getProjectAvailableAgents(null, true);
112
112
  if (this.log) {console.log("(DirIfOnlineAgents) agents:", agents); }
113
+ console.log("(DirIfOnlineAgents) agents:", agents);
113
114
  }
114
115
 
115
116
  if (agents && agents.length > 0) {
@@ -216,7 +216,6 @@ class DirIfOpenHours {
216
216
  }
217
217
  axios(axios_options)
218
218
  .then((res) => {
219
- console.log("siamo quiii")
220
219
  if (this.log) {
221
220
  console.log("Response for url:", options.url);
222
221
  console.log("Response headers:\n", JSON.stringify(res.headers));
@@ -233,7 +232,6 @@ class DirIfOpenHours {
233
232
  }
234
233
  })
235
234
  .catch((error) => {
236
- console.log("siamo quiii")
237
235
  // console.error("An error occurred:", JSON.stringify(error.data));
238
236
  if (callback) {
239
237
  callback(error, null);
@@ -119,6 +119,9 @@ class DirJSONCondition {
119
119
  }
120
120
  }
121
121
  else {
122
+ if (result === null) {
123
+ await this.chatbot.addParameter("flowError", "An error occurred evaluating condition: result === null");
124
+ }
122
125
  if (falseIntentDirective) {
123
126
  this.intentDir.execute(falseIntentDirective, () => {
124
127
  // console.log("result === false. stopOnConditionMet?", stopOnConditionMet);
@@ -77,6 +77,12 @@ class DirReply {
77
77
  TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
78
78
  if (this.log) {console.log("command filled:", command.message.text);}
79
79
  }
80
+ if (command.type === 'settings' && command.settings) {
81
+ Object.keys(command.settings).forEach(k => {
82
+ command.settings[k] = filler.fill(command.settings[k], requestAttributes)
83
+ if (this.log) {console.log("settings command filled:", command.settings[k]);}
84
+ })
85
+ }
80
86
  }
81
87
  }
82
88
  }
@@ -105,16 +105,16 @@ class DirSetAttributeV2 {
105
105
  if (this.log) {console.log("(SetAttributeV2) filling in setattribute...");}
106
106
  await this.fillValues(action.operation.operands);
107
107
  }
108
- console.log("action.operation.operands.length", action.operation.operands.length);
109
- console.log("action.operation.operands[0].type", action.operation.operands[0].type);
108
+ if (this.log) { console.log("action.operation.operands.length", action.operation.operands.length); }
109
+ if (this.log) { console.log("action.operation.operands[0].type", action.operation.operands[0].type); }
110
110
 
111
111
  // FUN FACT: THIS TOOK A LOT OF EFFERT BUT IT WAS NEVER USED. YOU CAN SIMPLY CREATE A JSON ATTRIBUTE APPLYING
112
112
  // JSONparse FUNCTION TO AN ATTRIBUTE.
113
113
  if (action.operation.operands && action.operation.operands.length === 1 && action.operation.operands[0].type === "json") {
114
114
  if (this.log) {console.log("(SetAttributeV2) setting json value...");}
115
- console.log("(SetAttributeV2) setting json value... destination:", action.destination);
115
+ if (this.log) { console.log("(SetAttributeV2) setting json value... destination:", action.destination); }
116
116
  const json_value = JSON.parse(action.operation.operands[0].value);
117
- console.log("(SetAttributeV2) json_value:", json_value);
117
+ if (this.log) { console.log("(SetAttributeV2) json_value:", json_value); }
118
118
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.destination, json_value);
119
119
  callback();
120
120
  return; // on json types no operations are permitted beyond assignment
@@ -273,7 +273,9 @@ class DirWebRequestV2 {
273
273
  method: options.method,
274
274
  params: options.params,
275
275
  headers: options.headers,
276
- timeout: options.timeout
276
+ timeout: options.timeout,
277
+ maxContentLength: 10000000, // max 10mb response size
278
+ maxBodyLength: 10000000 // max 10mb request body size
277
279
  }
278
280
 
279
281
  if (options.json !== null) {