@tiledesk/tiledesk-tybot-connector 0.2.96-rc1 → 0.2.97

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,19 +5,36 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
- # v0.2.96-rc1
9
- - Added support for response_format in GptTask
10
- - Added namespaceAsName parameter in AskGPTv2
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
11
13
 
12
14
  # v0.2.97
13
15
  - Added a limit in upload and download for WebRequestV2: maxContentLength: 10000000, // max 10mb response size, maxBodyLength: 10000000 // max 10mb request body size
14
16
  - Added jsonCondition test on json objects properties
15
17
  - Added flowError on JSONCondition when result = null
16
- - Added fix on Filler
18
+ - Added fix on Filler -->
19
+
20
+ # v0.2.97
21
+ - Added support for "chatbotToken” attribute
22
+ - Added new Action: clear_transcript
23
+ - Exclude transcript generation when request type differs from "support-group-*"
24
+ - "step" key reset on DirWait => this.chatbot.addParameter( step_key, 0 )
17
25
 
18
26
  # v0.2.96
19
27
  - Added timestamp (number) and now (Date Object) attributes
20
28
 
29
+ - Added a limit in upload and download for WebRequestV2: maxContentLength: 10000000, // max 10mb response size, maxBodyLength: 10000000 // max 10mb request body size
30
+ - Added jsonCondition test on json objects properties
31
+ - Added flowError on JSONCondition when result = null
32
+ - Added fix on Filler
33
+
34
+ - Added possibility to select namespace by name
35
+ - Added filler to namespace in DirAskGPTv2
36
+ - Added filler to command.settings in DirReply
37
+
21
38
  # v0.2.95
22
39
  - If Online Agents V2 - bug fix (If Project Available Agents V2 -> MWeb)
23
40
 
@@ -162,9 +179,6 @@ available on:
162
179
  - added flow attribute "decodedCustomJWT"
163
180
 
164
181
  # v0.2.57
165
- - Changed env variables for AskGPT actions
166
- - Added support for temperature, top_k, max_tokens and context for AskGPTV2 action
167
- - Added support for context with variables for GptTask action
168
182
  - fixed catching reply error in index.js: reply = await chatbot.replyToMessage(message);
169
183
  - Added context and top_k parameter in DirAskGPTV2
170
184
 
package/index.js CHANGED
@@ -171,8 +171,10 @@ router.post('/ext/:botid', async (req, res) => {
171
171
  // if (log) {console.log("forced conversion of \\\\start /start");}
172
172
  // message.text = "/start";
173
173
  // }
174
- await TiledeskChatbotUtil.updateRequestAttributes(chatbot, message, projectId, requestId);
175
- await TiledeskChatbotUtil.updateConversationTranscript(chatbot, message);
174
+ await TiledeskChatbotUtil.updateRequestAttributes(chatbot, token, message, projectId, requestId);
175
+ if (requestId.startsWith("support-group-")) {
176
+ await TiledeskChatbotUtil.updateConversationTranscript(chatbot, message);
177
+ }
176
178
 
177
179
  let reply = null;
178
180
  try {
@@ -30,6 +30,7 @@ class TiledeskChatbotConst {
30
30
  static REQ_USER_LEAD_ID_KEY = "userLeadId";
31
31
  static REQ_USER_COMPANY_KEY = "userCompany";
32
32
  static REQ_TICKET_ID_KEY = "ticketId";
33
+ static REQ_CHATBOT_TOKEN = "chatbotToken";
33
34
 
34
35
 
35
36
  // static REQ_DEPARTMENT_ID_KEY = "tdDepartmentId";
@@ -442,6 +442,13 @@ class TiledeskChatbotUtil {
442
442
  }
443
443
  }
444
444
 
445
+ static async clearConversationTranscript(chatbot, callback) {
446
+ await chatbot.addParameter("transcript", "");
447
+ if (callback) {
448
+ callback();
449
+ }
450
+ }
451
+
445
452
  static transcriptJSON(transcript) {
446
453
  const regexp = /(<.*>)/gm;
447
454
  const parts = transcript.split(regexp);
@@ -506,7 +513,7 @@ class TiledeskChatbotUtil {
506
513
  return message;
507
514
  }
508
515
 
509
- static async updateRequestAttributes(chatbot, message, projectId, requestId) {
516
+ static async updateRequestAttributes(chatbot, chatbotToken, message, projectId, requestId) {
510
517
  // update request context
511
518
  try {
512
519
  if (chatbot.log) {console.log("Updating request variables. Message:", JSON.stringify(message));}
@@ -519,7 +526,10 @@ class TiledeskChatbotUtil {
519
526
  // TODO add projectName too
520
527
  await chatbot.addParameter(TiledeskChatbotConst.REQ_REQUEST_ID_KEY, requestId);
521
528
  if (chatbot.bot) {
522
- await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_NAME_KEY, chatbot.bot.name);
529
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_NAME_KEY, chatbot.bot.name);
530
+ }
531
+ if (chatbotToken) {
532
+ await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken);
523
533
  }
524
534
 
525
535
  if (message.text && message.sender !== "_tdinternal") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.2.96-rc1",
3
+ "version": "0.2.97",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -50,6 +50,7 @@ const { DirAssistant } = require('./directives/DirAssistant');
50
50
  const { DirReplyV2 } = require('./directives/DirReplyV2');
51
51
  const { DirIfOnlineAgentsV2 } = require('./directives/DirIfOnlineAgentsV2');
52
52
  const { DirContactUpdate } = require('./directives/DirContactUpdate');
53
+ const { DirClearTranscript } = require('./directives/DirClearTranscript');
53
54
 
54
55
  class DirectivesChatbotPlug {
55
56
 
@@ -684,12 +685,19 @@ class DirectivesChatbotPlug {
684
685
  });
685
686
  }
686
687
  else if (directive_name === Directives.CONTACT_UPDATE) {
687
- console.log("...CONTACT_UPDATE");
688
+ // console.log("...CONTACT_UPDATE");
688
689
  new DirContactUpdate(context).execute(directive, async () => {
689
690
  let next_dir = await this.nextDirective(this.directives);
690
691
  this.process(next_dir);
691
692
  });
692
693
  }
694
+ else if (directive_name === Directives.CLEAR_TRANSCRIPT) {
695
+ console.log("...CLEAR_TRANSCRIPT");
696
+ new DirClearTranscript(context).execute(directive, async () => {
697
+ let next_dir = await this.nextDirective(this.directives);
698
+ this.process(next_dir);
699
+ });
700
+ }
693
701
  else {
694
702
  //console.log("Unhandled Post-message Directive:", directive_name);
695
703
  let next_dir = await this.nextDirective(this.directives);
@@ -172,7 +172,11 @@ class DirAskGPTV2 {
172
172
 
173
173
 
174
174
  if (action.namespaceAsName) {
175
- namespace = await this.getNamespaceIdFromName(server_base_url, action.namespace)
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);
176
180
  if (this.log) { console.log("DirAskGPT - Retrieved namespace id from name ", namespace); }
177
181
  }
178
182
 
@@ -572,7 +576,7 @@ class DirAskGPTV2 {
572
576
  },
573
577
  method: "GET"
574
578
  }
575
- if (this.log) { console.log("DirAskGPT check quote availability HTTPREQUEST", HTTPREQUEST); }
579
+ if (this.log) { console.log("DirAskGPT get all namespaces HTTPREQUEST", HTTPREQUEST); }
576
580
 
577
581
  this.#myrequest(
578
582
  HTTPREQUEST, async (err, namespaces) => {
@@ -580,8 +584,7 @@ class DirAskGPTV2 {
580
584
  console.error("(httprequest) DirAskGPT get all namespaces err: ", err);
581
585
  resolve(null)
582
586
  } else {
583
- if (this.log) { console.log("(httprequest) DirAskGPT Increment token quote resbody: ", namespaces); }
584
- console.log("(httprequest) DirAskGPT Increment token quote resbody: ", namespaces);
587
+ if (this.log) { console.log("(httprequest) DirAskGPT get all namespaces resbody: ", namespaces); }
585
588
 
586
589
  let namespace = namespaces.find(n => n.name === name);
587
590
  let namespace_id = namespace.id;
@@ -0,0 +1,23 @@
1
+
2
+ const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
3
+
4
+ class DirClearTranscript {
5
+
6
+ constructor(context) {
7
+ if (!context) {
8
+ throw new Error('context object is mandatory.');
9
+ }
10
+ this.context = context;
11
+ this.tdclient = context.tdclient;
12
+ this.requestId = context.requestId;
13
+ }
14
+
15
+ execute(directive, callback) {
16
+ TiledeskChatbotUtil.clearConversationTranscript(this.context.chatbot, () => {
17
+ callback();
18
+ });
19
+ }
20
+
21
+ }
22
+
23
+ module.exports = { DirClearTranscript };
@@ -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
  });
@@ -168,12 +168,6 @@ class DirGptTask {
168
168
  json.messages.push(message);
169
169
  }
170
170
 
171
- if (action.format_type) {
172
- json.response_format = {
173
- type: action.format_type
174
- }
175
- }
176
-
177
171
  if (transcript) {
178
172
  transcript.forEach(msg => {
179
173
  if (!msg.content.startsWith('/')) {
@@ -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);
@@ -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
@@ -1,7 +1,17 @@
1
1
 
2
+ const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
+
2
4
  class DirWait {
3
5
 
4
- constructor() {
6
+ constructor(context) {
7
+ if (!context) {
8
+ throw new Error('context object is mandatory.');
9
+ }
10
+ this.context = context;
11
+ this.tdclient = context.tdclient;
12
+ this.tdcache = context.tdcache;
13
+ this.requestId = context.requestId;
14
+ this.log = context.log;
5
15
  }
6
16
 
7
17
  execute(directive, callback) {
@@ -38,10 +48,11 @@ class DirWait {
38
48
  })
39
49
  }
40
50
 
41
- go(action, callback) {
42
- // console.log(">>>>__", callback)
51
+ async go(action, callback) {
52
+ // reset step
53
+ const step_key = TiledeskChatbot.requestCacheKey(this.requestId) + ":step";
54
+ await this.chatbot.addParameter( step_key, 0 );
43
55
  setTimeout(() => {
44
- // console.log("QUINO....__")
45
56
  callback();
46
57
  }, action.millis);
47
58
  }
@@ -40,7 +40,6 @@ class Directives {
40
40
  static HUBSPOT = 'hubspot';
41
41
  static CUSTOMERIO = 'customerio';
42
42
  static BREVO = 'brevo';
43
- static N8N = 'n8n';
44
43
  /**** VOICE CHANNEL ****/
45
44
  static DTMF_FORM = 'dtmf_form';
46
45
  static DTMF_MENU = 'dtmf_menu';
@@ -51,6 +50,7 @@ class Directives {
51
50
  static REPLY_V2 = 'replyv2';
52
51
  static IF_ONLINE_AGENTS_V2 = "ifonlineagentsv2";
53
52
  static CONTACT_UPDATE = "leadupdate";
53
+ static CLEAR_TRANSCRIPT = "clear_transcript";
54
54
 
55
55
  // static WHEN_ONLINE_MOVE_TO_AGENT = "whenonlinemovetoagent"; // DEPRECATED?
56
56
  // static WHEN_OFFLINE_HOURS = "whenofflinehours"; // DEPRECATED // adds a message on top of the original message when offline hours opts: --replace