@tiledesk/tiledesk-tybot-connector 2.0.13 → 2.0.15-rc1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "2.0.13",
3
+ "version": "2.0.15-rc1",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,7 +15,7 @@
15
15
  "@tiledesk/tiledesk-chatbot-client": "^0.5.30",
16
16
  "@tiledesk/tiledesk-chatbot-util": "^0.8.39",
17
17
  "@tiledesk/tiledesk-client": "^0.10.13",
18
- "@tiledesk/tiledesk-multi-worker": "^0.3.1-rc10",
18
+ "@tiledesk/tiledesk-multi-worker": "^0.3.1-rc12",
19
19
  "accept-language-parser": "^1.5.0",
20
20
  "app-root-path": "^3.1.0",
21
21
  "axios": "^1.7.7",
@@ -54,13 +54,13 @@ const { DirMoveToUnassigned } = require('./directives/DirMoveToUnassigned');
54
54
  const { DirAddTags } = require('./directives/DirAddTags');
55
55
  const { DirSendWhatsapp } = require('./directives/DirSendWhatsapp');
56
56
  const { DirReplaceBotV3 } = require('./directives/DirReplaceBotV3');
57
- const { DirAiTask, DirAiPrompt } = require('./directives/DirAiPrompt');
57
+ const { DirAiPrompt } = require('./directives/DirAiPrompt');
58
58
  const { DirWebResponse } = require('./directives/DirWebResponse');
59
59
  const { DirConnectBlock } = require('./directives/DirConnectBlock');
60
+ const { DirAddKbContent } = require('./directives/DirAddKbContent');
61
+ const { DirFlowLog } = require('./directives/DirFlowLog');
60
62
 
61
63
  const winston = require('../utils/winston');
62
- const { DirFlowLog } = require('./directives/DirFlowLog');
63
- const { DirAddKbContent } = require('./directives/DirAddKbContent');
64
64
 
65
65
  class DirectivesChatbotPlug {
66
66
 
@@ -219,14 +219,13 @@ class DirectivesChatbotPlug {
219
219
  directive_name = directive.name.toLowerCase();
220
220
  }
221
221
  if (directive && directive.action) {
222
- const action_id = directive.action["_tdActionId"];
223
- const locked_action_id = await this.chatbot.currentLockedAction(this.supportRequest.request_id);
224
- if ( locked_action_id && (locked_action_id !== action_id) ) {
225
- let next_dir = await this.nextDirective(this.directives);
226
- this.process(next_dir);
227
- return;
228
- }
229
-
222
+ const action_id = directive.action["_tdActionId"];
223
+ const locked_action_id = await this.chatbot.currentLockedAction(this.supportRequest.request_id);
224
+ if ( locked_action_id && (locked_action_id !== action_id) ) {
225
+ let next_dir = await this.nextDirective(this.directives);
226
+ this.process(next_dir);
227
+ return;
228
+ }
230
229
  }
231
230
  if (directive == null || (directive !== null && directive["name"] === undefined)) {
232
231
  winston.debug("(DirectivesChatbotPlug) stop process(). directive is (null?): ", directive);
@@ -704,6 +703,19 @@ class DirectivesChatbotPlug {
704
703
  }
705
704
  });
706
705
  }
706
+ else if (directive_name === Directives.WEBHOOK) {
707
+ // console.log(".....DirIntent")
708
+ new DirIntent(context).execute(directive, async (stop) => {
709
+ if (stop) {
710
+ if (context.log) { console.log("Stopping Actions on:", JSON.stringify(directive));}
711
+ this.theend();
712
+ }
713
+ else {
714
+ let next_dir = await this.nextDirective(this.directives);
715
+ this.process(next_dir);
716
+ }
717
+ });
718
+ }
707
719
  else if (directive_name === Directives.WEB_RESPONSE) {
708
720
  new DirWebResponse(context).execute(directive, async () => {
709
721
  let next_dir = await this.nextDirective(this.directives);
@@ -716,6 +728,12 @@ class DirectivesChatbotPlug {
716
728
  this.process(next_dir);
717
729
  })
718
730
  }
731
+ else if (directive_name === Directives.ADD_KB_CONTENT) {
732
+ new DirAddKbContent(context).execute(directive, async () => {
733
+ let next_dir = await this.nextDirective(this.directives);
734
+ this.process(next_dir);
735
+ });
736
+ }
719
737
  else {
720
738
  let next_dir = await this.nextDirective(this.directives);
721
739
  this.process(next_dir);
@@ -248,7 +248,8 @@ class DirAskGPTV2 {
248
248
  namespace: namespace,
249
249
  model: model,
250
250
  citations: citations,
251
- engine: engine
251
+ engine: engine,
252
+ debug: true
252
253
  };
253
254
  if (top_k) {
254
255
  json.top_k = top_k;
@@ -305,7 +306,7 @@ class DirAskGPTV2 {
305
306
  }
306
307
  else if (resbody.success === true) {
307
308
  winston.debug("DirAskGPTV2 resbody: ", resbody);
308
- await this.#assignAttributes(action, resbody.answer, resbody.source);
309
+ await this.#assignAttributes(action, resbody.answer, resbody.source, resbody.content_chunks);
309
310
  if (publicKey === true) {
310
311
  let tokens_usage = {
311
312
  tokens: resbody.prompt_token_size,
@@ -376,7 +377,7 @@ class DirAskGPTV2 {
376
377
  }
377
378
  }
378
379
 
379
- async #assignAttributes(action, answer, source) {
380
+ async #assignAttributes(action, answer, source, chunks) {
380
381
  winston.debug("DirAskGPTV2assignAttributes action: ", action)
381
382
  winston.debug("DirAskGPTV2assignAttributes answer: ", answer)
382
383
  winston.debug("DirAskGPTV2assignAttributes source: ", source)
@@ -387,6 +388,9 @@ class DirAskGPTV2 {
387
388
  if (action.assignSourceTo && source) {
388
389
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignSourceTo, source);
389
390
  }
391
+ if (action.assignChunksTo && chunks) {
392
+ await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignChunksTo, chunks);
393
+ }
390
394
  }
391
395
  }
392
396
 
@@ -64,6 +64,7 @@ class DirIntent {
64
64
  "request": {
65
65
  "request_id": requestId,
66
66
  "id_project": projectId
67
+ // "bot_id": botId
67
68
  }
68
69
  },
69
70
  "token": this.token
@@ -35,7 +35,6 @@ class DirWebRequestV2 {
35
35
  callback();
36
36
  return;
37
37
  }
38
- this.logger.info("Executing WebRequest action ", directive.action)
39
38
  this.go(action, (stop) => {
40
39
  this.logger.info("[Web Request] Action completed");
41
40
  callback(stop);
@@ -119,7 +118,7 @@ class DirWebRequestV2 {
119
118
  this.logger.debug("[Web Request] resbody: ", resbody);
120
119
 
121
120
  if (err) {
122
- this.logger.error("WebRequest error: ", err);
121
+ this.logger.error("[Web Request] error: ", err);
123
122
  winston.log("webRequest error: ", err);
124
123
  if (callback) {
125
124
  if (falseIntent) {
@@ -58,6 +58,7 @@ class Directives {
58
58
  static MOVE_TO_UNASSIGNED = "move_to_unassigned";
59
59
  static CONNECT_BLOCK = "connect_block";
60
60
  static ADD_TAGS = 'add_tags'
61
+ static WEBHOOK = 'webhook';
61
62
  static WEB_RESPONSE = "web_response";
62
63
  static FLOW_LOG = "flow_log";
63
64
  static ADD_KB_CONTENT = "add_kb_content";
@@ -333,27 +333,6 @@ class TiledeskChatbotUtil {
333
333
  }
334
334
  });
335
335
  }
336
-
337
- // "buttons": [
338
- // {
339
- // "type": "action",
340
- // "value": "Button1", // obbligatorio sempre
341
- // "action": "#bb347206-d639-4926-94c9-e94930623dce", // mandatory
342
- // "show_echo": true, // lo inserisco sempre
343
- // "alias": "button1 alias"
344
- // },
345
- // {
346
- // "type": "text",
347
- // "value": "Button2 text", // obbligatorio sempre
348
- // "show_echo": true // lo inserisco sempre
349
- // },
350
- // {
351
- // "type": "url",
352
- // "value": "Button3 link", // obbligatorio sempre
353
- // "link": "http://", // obbligatorio
354
- // "show_echo": true // lo inserisco sempre
355
- // }
356
- // ]
357
336
  }
358
337
  catch(error) {
359
338
  winston.warn("Invalid json_buttons:", error)
@@ -602,8 +581,10 @@ class TiledeskChatbotUtil {
602
581
  }
603
582
  let currentLeadName = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY);
604
583
  winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail);
584
+ console.log("currentLeadName: ", currentLeadName)
605
585
  if (message.request.lead.fullname && !currentLeadName) {
606
586
  // worth saving
587
+ console.log("inside if")
607
588
  winston.debug("(TiledeskChatbotUtil) worth saving email");
608
589
  try {
609
590
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, message.request.lead.fullname);
package/TdCache copy.js DELETED
@@ -1,242 +0,0 @@
1
- const redis = require('redis');
2
-
3
- class TdCache {
4
-
5
- constructor(config) {
6
- this.redis_host = config.host;
7
- this.redis_port = config.port;
8
- this.redis_password = config.password;
9
- this.client = null;
10
- }
11
-
12
- async connect(callback) {
13
- // client = redis.createClient();
14
- return new Promise( async (resolve, reject) => {
15
- this.client = redis.createClient(
16
- {
17
- host: this.redis_host,
18
- port: this.redis_port,
19
- password: this.redis_password
20
- });
21
- this.client.on('error', err => {
22
- reject(err);
23
- if (callback) {
24
- callback(err);
25
- }
26
- });
27
- // this.client.on('connect', function() {
28
- // console.log('Redis Connected!');
29
- // });
30
- this.client.on('ready',function() {
31
- console.log("connected")
32
- resolve();
33
- if (callback) {
34
- callback();
35
- }
36
- //console.log("Redis is ready.");
37
- });
38
- });
39
- }
40
-
41
- async set(key, value, options) {
42
- //console.log("setting key value", key, value)
43
- if (!options) {
44
- options = {EX: 86400}
45
- }
46
- return new Promise( async (resolve, reject) => {
47
- if (options && options.EX) {
48
- //console.log("expires:", options.EX)
49
- try {
50
- await this.client.set(
51
- key,
52
- value,
53
- 'EX', options.EX);
54
- }
55
- catch(error) {
56
- reject(error)
57
- }
58
- }
59
- else {
60
- try {
61
- //console.log("setting here...key", key, value)
62
- await this.client.set(
63
- key,
64
- value);
65
- }
66
- catch(error) {
67
- console.error("Error", error);
68
- reject(error)
69
- }
70
- }
71
- if (options && options.callback) {
72
- options.callback();
73
- }
74
- //console.log("resolving...", key);
75
- return resolve();
76
- });
77
- }
78
-
79
- async incr(key) {
80
- // console.log("incr key:", key)
81
- return new Promise( async (resolve, reject) => {
82
- try {
83
- // console.log("incr here...key", key)
84
- await this.client.incr(key);
85
- }
86
- catch(error) {
87
- console.error("Error on incr:", error);
88
- reject(error)
89
- }
90
- return resolve();
91
- });
92
- }
93
-
94
- async hset(dict_key, key, value, options) {
95
- //console.log("hsetting dict_key key value", dict_key, key, value)
96
- return new Promise( async (resolve, reject) => {
97
- if (options && options.EX) {
98
- //console.log("expires:", options.EX)
99
- try {
100
- await this.client.hset(
101
- dict_key,
102
- key,
103
- value,
104
- 'EX', options.EX);
105
- }
106
- catch(error) {
107
- reject(error)
108
- }
109
- }
110
- else {
111
- try {
112
- //console.log("setting here...key", key, value)
113
- await this.client.hset(
114
- dict_key,
115
- key,
116
- value);
117
- }
118
- catch(error) {
119
- console.error("Error", error);
120
- reject(error)
121
- }
122
- }
123
- if (options && options.callback) {
124
- options.callback();
125
- }
126
- return resolve();
127
- });
128
- }
129
-
130
- async hdel(dict_key, key, options) {
131
- //console.log("hsetting dict_key key value", dict_key, key, value)
132
- return new Promise( async (resolve, reject) => {
133
- if (options && options.EX) {
134
- //console.log("expires:", options.EX)
135
- try {
136
- await this.client.hdel(
137
- dict_key,
138
- key,
139
- 'EX', options.EX);
140
- }
141
- catch(error) {
142
- reject(error)
143
- }
144
- }
145
- else {
146
- try {
147
- //console.log("setting here...key", key, value)
148
- await this.client.hdel(
149
- dict_key,
150
- key);
151
- }
152
- catch(error) {
153
- console.error("Error", error);
154
- reject(error);
155
- }
156
- }
157
- if (options && options.callback) {
158
- options.callback();
159
- }
160
- return resolve();
161
- });
162
- }
163
-
164
- async setJSON(key, value, options) {
165
- const _string = JSON.stringify(value);
166
- return await this.set(key, _string, options);
167
- }
168
-
169
- async get(key, callback) {
170
- //console.log("getting key", key)
171
- return new Promise( async (resolve, reject) => {
172
- this.client.get(key, (err, value) => {
173
- if (err) {
174
- reject(err);
175
- }
176
- else {
177
- if (callback) {
178
- callback(value);
179
- }
180
- return resolve(value);
181
- }
182
- });
183
- });
184
- }
185
-
186
- async hgetall(dict_key, callback) {
187
- //console.log("hgetting dics", dict_key);
188
- return new Promise( async (resolve, reject) => {
189
- this.client.hgetall(dict_key, (err, value) => {
190
- if (err) {
191
- reject(err);
192
- if (callback) {
193
- callback(err, null);
194
- }
195
- }
196
- else {
197
- if (callback) {
198
- callback(null, value);
199
- }
200
- resolve(value);
201
- }
202
- });
203
- });
204
- }
205
-
206
- async hget(dict_key, key, callback) {
207
- //console.log("hgetting dics", dict_key);
208
- return new Promise( async (resolve, reject) => {
209
- this.client.hget(dict_key, key, (err, value) => {
210
- if (err) {
211
- reject(err);
212
- if (callback) {
213
- callback(err, null);
214
- }
215
- }
216
- else {
217
- if (callback) {
218
- callback(null, value);
219
- }
220
- resolve(value);
221
- }
222
- });
223
- });
224
- }
225
-
226
- async getJSON(key, callback) {
227
- const value = await this.get(key);
228
- return JSON.parse(value);
229
- }
230
-
231
- async del(key, callback) {
232
- return new Promise( async (resolve, reject) => {
233
- await this.client.del(key);
234
- if (callback) {
235
- callback();
236
- }
237
- return resolve();
238
- })
239
- }
240
- }
241
-
242
- module.exports = { TdCache };