@tiledesk/tiledesk-tybot-connector 0.2.96 → 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
@@ -17,6 +17,12 @@ available on:
17
17
  - Added flowError on JSONCondition when result = null
18
18
  - Added fix on Filler -->
19
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 )
25
+
20
26
  # v0.2.96
21
27
  - Added timestamp (number) and now (Date Object) attributes
22
28
 
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",
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);
@@ -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 };
@@ -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
  }
@@ -50,6 +50,7 @@ class Directives {
50
50
  static REPLY_V2 = 'replyv2';
51
51
  static IF_ONLINE_AGENTS_V2 = "ifonlineagentsv2";
52
52
  static CONTACT_UPDATE = "leadupdate";
53
+ static CLEAR_TRANSCRIPT = "clear_transcript";
53
54
 
54
55
  // static WHEN_ONLINE_MOVE_TO_AGENT = "whenonlinemovetoagent"; // DEPRECATED?
55
56
  // static WHEN_OFFLINE_HOURS = "whenofflinehours"; // DEPRECATED // adds a message on top of the original message when offline hours opts: --replace