@tiledesk/tiledesk-tybot-connector 3.0.0 → 3.0.2

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.
@@ -22,6 +22,7 @@ class Directives {
22
22
  static FUNCTION_VALUE = "functionvalue";
23
23
  static JSON_CONDITION = "jsoncondition";
24
24
  static JSON_CONDITION_2 = "jsoncondition2"; // NEW: azione JSON Condition V2 del Design Studio
25
+ static JSON_CONDITION_MULTI = "jsonconditionmulti"; // NEW: condizione a piu' casi in sequenza, un'uscita per caso
25
26
  static SET_ATTRIBUTE = "setattribute";
26
27
  static SET_ATTRIBUTE_V2 = "setattribute-v2";
27
28
  static REPLY = 'reply';
@@ -63,6 +64,8 @@ class Directives {
63
64
  static MOVE_TO_UNASSIGNED = "move_to_unassigned";
64
65
  static CONNECT_BLOCK = "connect_block";
65
66
  static ADD_TAGS = 'add_tags'
67
+ static INVITE_HUMAN = "invite_human";
68
+ static REMOVE_HUMAN = "remove_human";
66
69
  static WEB_RESPONSE = "web_response";
67
70
  static FLOW_LOG = "flow_log";
68
71
  static ADD_KB_CONTENT = "add_kb_content";
@@ -60,12 +60,15 @@ const OUTPUT_CATALOG = {
60
60
  ifonlineagents: TRUE_FALSE,
61
61
  ifonlineagentsv2: TRUE_FALSE,
62
62
  ifopenhours: TRUE_FALSE,
63
+ invite_human: TRUE_FALSE,
64
+ remove_human: TRUE_FALSE,
63
65
  jsonconditionmulti: [array((c) => '/case/' + c._tdCaseId, 'cases', '_tdCaseId', 'intent'), field('/else', 'elseIntent')],
64
66
  jsoncondition: TRUE_FALSE,
65
67
  jsoncondition2: TRUE_FALSE,
66
68
  invoke_subagent: TRUE_FALSE,
67
69
  askgpt: TRUE_FALSE,
68
70
  askgptv2: TRUE_FALSE,
71
+ docparse_extract: TRUE_FALSE,
69
72
  gpt_task: TRUE_FALSE,
70
73
  gpt_assistant: TRUE_FALSE,
71
74
  ai_prompt: TRUE_FALSE,
@@ -16,6 +16,9 @@ class HttpUtils {
16
16
  if (options.json !== null) {
17
17
  axios_options.data = options.json
18
18
  }
19
+ if (typeof options.timeout === 'number' && options.timeout > 0) {
20
+ axios_options.timeout = options.timeout
21
+ }
19
22
  if (options.url.startsWith("https:")) {
20
23
  const httpsAgent = new https.Agent({
21
24
  rejectUnauthorized: false,
@@ -36,23 +39,24 @@ class HttpUtils {
36
39
  }
37
40
  })
38
41
  .catch((error) => {
39
- if (error.response?.data) {
40
- if (typeof error.response.data === 'string') {
41
- winston.error("Axios error response data: " + error.response.data);
42
- } else {
43
- winston.error("Axios error response data: ", error.response.data);
44
- }
45
- } else if (error.response) {
46
- winston.error("Axios error response: ", error.response);
47
- } else {
48
- winston.error("Axios error: ", error);
49
- }
42
+ // Never log the error/response/config objects: they carry request headers (Authorization: JWT ...).
43
+ winston.error("HTTP request error: ", HttpUtils.errorSummary(error, options.url));
50
44
  if (callback) {
51
45
  callback(error, null);
52
46
  }
53
47
  });
54
48
  }
55
49
 
50
+ static errorSummary(error, url) {
51
+ return {
52
+ message: error?.message,
53
+ code: error?.code,
54
+ status: error?.response?.status,
55
+ url: typeof url === 'string' ? url.split('?')[0] : undefined,
56
+ data: error?.response?.data
57
+ };
58
+ }
59
+
56
60
  // static myrequest(options, callback, log) {
57
61
  // winston.verbose("** API URL: " + options.url);
58
62
  // winston.debug("** Options: ", options);
@@ -1,7 +1,6 @@
1
1
  const { TiledeskExpression } = require('../TiledeskExpression');
2
2
  const { Filler } = require('../tiledeskChatbotPlugs/Filler');
3
3
  const { TiledeskChatbotConst } = require('../engine/TiledeskChatbotConst');
4
- const { TiledeskChatbot } = require('../engine/TiledeskChatbot.js');
5
4
  let parser = require('accept-language-parser');
6
5
  const { Directives } = require('../tiledeskChatbotPlugs/directives/Directives.js');
7
6
  require('dotenv').config();
@@ -854,6 +853,10 @@ class TiledeskChatbotUtil {
854
853
  message.attributes.payload = { ...message.attributes.payload, ...message.request.attributes.payload }
855
854
  winston.debug("(TiledeskChatbotUtil) Forced Set message.attributes.payload ", message.attributes.payload);
856
855
  }
856
+ // --- START TYPE (set by the request creator, e.g. "webhook") ---
857
+ if (message && message.request && message.request.attributes && message.request.attributes.start_type) {
858
+ add("start_type", message.request.attributes.start_type);
859
+ }
857
860
 
858
861
  // --- ATTRIBUTES ---
859
862
  if (message.attributes) {
package/utils/winston.js CHANGED
@@ -3,6 +3,83 @@ var appRoot = require('app-root-path');
3
3
  var winston = require('winston');
4
4
  var level = process.env.LOG_LEVEL || "info";
5
5
 
6
+ const SECRET_KEY = /^(authorization|token|x-api-key|apikey|api_key|gptkey|password|secret)$/i;
7
+ const SECRET_TOKEN = /\b(JWT|Bearer)\s+[A-Za-z0-9._~+\/=-]+/g;
8
+ const MAX_DEPTH = 8;
9
+ const MAX_NODES = 5000;
10
+
11
+ function redactString(str) {
12
+ return str.replace(SECRET_TOKEN, '$1 [REDACTED]');
13
+ }
14
+
15
+ // Returns a redacted COPY of value: the caller's objects are never mutated.
16
+ function redactValue(value, depth, ancestors, budget) {
17
+ if (typeof value === 'string') {
18
+ return redactString(value);
19
+ }
20
+ if (value === null || typeof value !== 'object') {
21
+ return value;
22
+ }
23
+ if (value instanceof Date || Buffer.isBuffer(value)) {
24
+ return value;
25
+ }
26
+ if (ancestors.has(value)) {
27
+ return '[Circular]';
28
+ }
29
+ if (depth >= MAX_DEPTH || budget.nodes-- <= 0) {
30
+ return '[Truncated]';
31
+ }
32
+ ancestors.add(value);
33
+ let out;
34
+ if (Array.isArray(value)) {
35
+ out = value.map((v) => redactValue(v, depth + 1, ancestors, budget));
36
+ }
37
+ else {
38
+ out = {};
39
+ if (value instanceof Error) {
40
+ // message and stack are not enumerable on Error
41
+ out.name = value.name;
42
+ out.message = redactString(String(value.message));
43
+ if (value.stack) {
44
+ out.stack = redactString(String(value.stack));
45
+ }
46
+ }
47
+ for (const key of Object.keys(value)) {
48
+ if (SECRET_KEY.test(key)) {
49
+ out[key] = '[REDACTED]';
50
+ }
51
+ else {
52
+ let v;
53
+ try { v = value[key]; } catch (e) { v = '[Unreadable]'; }
54
+ out[key] = redactValue(v, depth + 1, ancestors, budget);
55
+ }
56
+ }
57
+ }
58
+ ancestors.delete(value);
59
+ return out;
60
+ }
61
+
62
+ const redactSecrets = winston.format((info) => {
63
+ const budget = { nodes: MAX_NODES };
64
+ const ancestors = new Set();
65
+ const out = {};
66
+ for (const key of Object.keys(info)) {
67
+ if (SECRET_KEY.test(key)) {
68
+ out[key] = '[REDACTED]';
69
+ }
70
+ else {
71
+ out[key] = redactValue(info[key], 0, ancestors, budget);
72
+ }
73
+ }
74
+ // keep winston's internal symbols (LEVEL, ...) and redact the splat args
75
+ for (const sym of Object.getOwnPropertySymbols(info)) {
76
+ out[sym] = sym === Symbol.for('splat')
77
+ ? redactValue(info[sym], 0, ancestors, budget)
78
+ : info[sym];
79
+ }
80
+ return out;
81
+ });
82
+
6
83
  var options = {
7
84
  file: {
8
85
  level:level ,
@@ -12,7 +89,7 @@ var options = {
12
89
  maxsize: 5242880, // 5MB
13
90
  maxFiles: 5,
14
91
  colorize: false,
15
- format: winston.format.simple()
92
+ format: winston.format.combine(redactSecrets(), winston.format.simple())
16
93
  },
17
94
  console: {
18
95
  level: level,
@@ -20,7 +97,7 @@ var options = {
20
97
  json: true,
21
98
  colorize: true,
22
99
  // timestamp: true,
23
- format: winston.format.simple()
100
+ format: winston.format.combine(redactSecrets(), winston.format.simple())
24
101
  },
25
102
  };
26
103
 
@@ -40,3 +117,4 @@ logger.stream = {
40
117
 
41
118
 
42
119
  module.exports = logger;
120
+ module.exports.redactSecrets = redactSecrets;