@tiledesk/tiledesk-tybot-connector 0.1.21 → 0.1.23

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/ExtApi.js +37 -0
  3. package/index backup.js +656 -0
  4. package/index.js +58 -461
  5. package/models/IntentForm.js +12 -13
  6. package/models/MockBotsDataSource.js +74 -0
  7. package/models/MockIntentsMachine.js +39 -0
  8. package/models/MongodbBotsDataSource.js +73 -0
  9. package/models/MongodbIntentsMachine.js +55 -0
  10. package/models/{TiledeskChatbot_Intents_Adapter.js → TiledeskChatbot backup.js } +0 -1
  11. package/models/TiledeskChatbot.js +206 -180
  12. package/models/TiledeskIntentsMachine.js +90 -0
  13. package/models/faqKbService.js +27 -0
  14. package/models/faqService.js +22 -0
  15. package/models/faq_kb.js +11 -28
  16. package/package.json +2 -2
  17. package/test/close_directive_test.js +49 -0
  18. package/test/directives_test.js +24 -26
  19. package/test/disable_input_text_directive_test.js +88 -0
  20. package/test/mock_query_test.js +276 -0
  21. package/test/single_test.sh +4 -0
  22. package/test/when_open_directive_test.js +167 -0
  23. package/tiledeskChatbotPlugs/CHANGELOG.md +2 -0
  24. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +66 -46
  25. package/tiledeskChatbotPlugs/directives/DirClose.js +25 -0
  26. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +6 -6
  27. package/tiledeskChatbotPlugs/directives/DirDepartment.js +52 -0
  28. package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +45 -0
  29. package/tiledeskChatbotPlugs/directives/DirIntent.js +50 -0
  30. package/tiledeskChatbotPlugs/directives/DirMessage.js +5 -4
  31. package/tiledeskChatbotPlugs/directives/DirWhenOpen.js +95 -0
  32. package/tiledeskChatbotPlugs/directives/Directives.js +3 -0
  33. package/tiledeskChatbotPlugs/package.json +1 -1
  34. package/models/MongoDBIntentsDataSource.js +0 -22
  35. package/models/StaticIntentsDataSource.js +0 -110
  36. package/test/chatbot_query_test.js_ +0 -41
@@ -0,0 +1,95 @@
1
+ const { param } = require("express/lib/request");
2
+
3
+ class DirWhenOpen {
4
+
5
+ constructor(config) {
6
+ if (!config.tdclient) {
7
+ throw new Error('config.tdclient (TiledeskClient) object is mandatory.');
8
+ }
9
+ this.tdclient = config.tdclient;
10
+ if (config.checkOpen == null || config.checkOpen === true) {
11
+ // null => defaults to checkOpen
12
+ this.checkOpen = true;
13
+ }
14
+ else {
15
+ this.checkOpen = false;
16
+ }
17
+ this.log = config.log;
18
+ }
19
+
20
+ execute(directive, directives, current_directive_index, callback) {
21
+ this.tdclient.openNow((err, result) => {
22
+ if (this.log) {console.log("openNow():", result);}
23
+ if (err) {
24
+ console.error("Agent in DirWhenOpen Error:", err);
25
+ callback();
26
+ return;
27
+ }
28
+ else {
29
+ if (directive.parameter) {
30
+ if (result && result.isopen && this.checkOpen) {
31
+ if (this.log) {console.log("execute the action on 'open'");}
32
+ let directive_to_execute = this.directiveFromParameter(directive.parameter);
33
+ if (this.log) {console.log("directive_to_execute:", directive_to_execute);}
34
+ if (directive_to_execute) {
35
+ directives.splice(current_directive_index + 1, 0, directive_to_execute);
36
+ }
37
+ callback();
38
+ return;
39
+ }
40
+
41
+ if (result && !result.isopen && this.checkOpen === false) {
42
+ if (this.log) {console.log("execute the action on 'closed'");}
43
+ let directive_to_execute = this.directiveFromParameter(directive.parameter);
44
+ if (directive_to_execute) {
45
+ directives.splice(current_directive_index + 1, 0, directive_to_execute);
46
+ }
47
+ callback();
48
+ return;
49
+ }
50
+ if (this.log) {
51
+ console.log("condition is checkOpen:", this.checkOpen);
52
+ console.log("result.isopen:", result.isopen);
53
+ console.log("condition not matched!");
54
+ }
55
+ callback();
56
+ }
57
+ else {
58
+ if (this.log) {console.log("no directive to execute.");}
59
+ callback();
60
+ }
61
+ }
62
+ });
63
+ }
64
+
65
+ directiveFromParameter(parameter) {
66
+ const DIRECTIVE_PREFIX = "_td";
67
+ const AGENT_DIRECTIVE_CMD = "\\agent"
68
+ const directive_pattern = /((\\{1}_td[a-zA-Z_0-9]*)|(\\agent))[ ]*(.*)[\r\n]*/m;
69
+ let match = null;
70
+ let directive = null;
71
+ match = directive_pattern.exec(parameter);
72
+ if (match && match.length >= 1) {
73
+ let final_msg_text = parameter.substring(0, match.index) + parameter.substring(match.index + match[0].length);
74
+ if (match.length >= 2) {
75
+ let directive_name = match[1];
76
+ if (directive_name !== AGENT_DIRECTIVE_CMD) {
77
+ // REMOVES THE "DIRECTIVE_PREFIX" from the directive name
78
+ directive_name = match[1].substring(DIRECTIVE_PREFIX.length + 1)
79
+ }
80
+ else if (directive_name === AGENT_DIRECTIVE_CMD) {
81
+ directive_name = this.AGENT_DIRECTIVE
82
+ }
83
+ directive = {
84
+ name: directive_name
85
+ };
86
+ if (match[1] !== AGENT_DIRECTIVE_CMD && match.length >= 5 && match[4] && match[4].trim().length > 0) {
87
+ directive.parameter = match[4];
88
+ }
89
+ }
90
+ }
91
+ return directive;
92
+ }
93
+ }
94
+
95
+ module.exports = { DirWhenOpen };
@@ -12,6 +12,9 @@ class Directives {
12
12
  static WHEN_NO_AVAILABLE_AGENTS = "whennoavailableagents";
13
13
  static WHEN_OFFLINE_HOURS = "whenofflinehours"; // adds a message on top of the original message when offline hours opts: --replace
14
14
  //static WHEN_OFFLINE_HOURS_REPLACE_MESSAGE = "whenofflinehoursreplacemessage"; // REMOVE
15
+ static DISABLE_INPUT_TEXT = "disableinputtext";
16
+ static WHEN_OPEN = "whenopen";
17
+ static WHEN_CLOSED = "whenclosed";
15
18
  static DEFLECT_TO_HELP_CENTER = "deflecttohelpcenter";
16
19
  static WAIT = "wait";
17
20
  static LOCK_INTENT = "lockintent";
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-chatbot-plugs",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Tiledesk Chatbot Plugs",
5
5
  "engines": {
6
6
  "node": ">=12.x"
@@ -1,22 +0,0 @@
1
- class StaticIntentsQueryAdapter {
2
-
3
- constructor() {
4
- }
5
-
6
- async getByExactMatch(text) {
7
- const intent_display_name = questions_intent[text];
8
- if (intent_display_name) {
9
- return intents[intent_display_name];
10
- }
11
- return null;
12
- }
13
-
14
- async getByNLP(text) {
15
- return getByExactMatch(text);
16
- }
17
-
18
- async getByIntentName(intentName) {
19
- return questions_intent[text];
20
- }
21
-
22
- }
@@ -1,110 +0,0 @@
1
- class StaticIntentsDataSource {
2
-
3
- constructor(intentsDataSource) {
4
- if (intentsDataSource) {
5
- this.intentsDataSource = intentsDataSource;
6
- }
7
- else {
8
- this.intentsDataSource = defaultIntentsSataSource;
9
- }
10
- }
11
-
12
- async getByExactMatch(text) {
13
- const intent_display_name = questions_intent[text];
14
- if (intent_display_name) {
15
- return intents[intent_display_name];
16
- }
17
- return null;
18
- }
19
-
20
- async getByNLP(text) {
21
- return getByExactMatch(text);
22
- }
23
-
24
- async getByIntentName(intentName) {
25
- return questions_intent[text];
26
- }
27
-
28
- }
29
-
30
- const defaultIntentsSataSource = {
31
- "intents" = {
32
- "intent1": {
33
- intent_display_name: "intent1",
34
- questions: [
35
- "intent1 question1",
36
- "intent1 question2"
37
- ],
38
- answer: "reply to intent1"
39
- },
40
- "intent2": {
41
- intent_display_name: "intent1",
42
- questions: [
43
- "intent2 question1",
44
- "intent2 question2"
45
- ],
46
- answer: "reply to intent2"
47
- },
48
- "intent3": {
49
- intent_display_name: "intent3",
50
- questions: [
51
- "intent3 question1",
52
- "intent3 question2"
53
- ],
54
- answer: "reply to intent3"
55
- }
56
- },
57
- "questions_intent": {
58
-
59
- "intent1 question1": "intent1",
60
- "intent1 question2": "intent1",
61
-
62
- "intent2 question1": "intent2",
63
- "intent2 question2": "intent2",
64
-
65
- "intent3 question1": "intent3",
66
- "intent3 question2": "intent3"
67
- }
68
- }
69
-
70
-
71
- const intents = {
72
- "intent1": {
73
- intent_display_name: "intent1",
74
- questions: [
75
- "intent1 question1",
76
- "intent1 question2"
77
- ],
78
- answer: "reply to intent1"
79
- },
80
- "intent2": {
81
- intent_display_name: "intent1",
82
- questions: [
83
- "intent2 question1",
84
- "intent2 question2"
85
- ],
86
- answer: "reply to intent2"
87
- },
88
- "intent3": {
89
- intent_display_name: "intent3",
90
- questions: [
91
- "intent3 question1",
92
- "intent3 question2"
93
- ],
94
- answer: "reply to intent3"
95
- }
96
- }
97
-
98
- const questions_intent = {
99
-
100
- "intent1 question1": "intent1",
101
- "intent1 question2": "intent1",
102
-
103
- "intent2 question1": "intent2",
104
- "intent2 question2": "intent2",
105
-
106
- "intent3 question1": "intent3",
107
- "intent3 question2": "intent3"
108
- }
109
-
110
- module.exports = { StaticIntentsDataSource }
@@ -1,41 +0,0 @@
1
- var assert = require('assert');
2
- const { ExtUtil } = require('../ExtUtil');
3
- const { DirectivesChatbotPlug } = require('../tiledeskChatbotPlugs/DirectivesChatbotPlug');
4
- const supportRequest = require('./support_request.js').request;
5
-
6
- describe('MessagePipeline', function() {
7
-
8
- it('test directives and splits', async () => {
9
- const message_text = `message1
10
-
11
- message2
12
- * button1
13
- \\_tdWait`;
14
- const answer = {
15
- text: message_text,
16
- attributes: {
17
- splits: true,
18
- directives: true,
19
- markbot: true,
20
- disableInputMessage: true,
21
- inputMessagePlaceholder: 'Compile the form before proceeding'
22
- }
23
- }
24
- let directivesPlug = new DirectivesChatbotPlug({supportRequest: supportRequest, TILEDESK_API_ENDPOINT: "APIURL", token: "token", log: false, HELP_CENTER_API_ENDPOINT: "HELP_CENTER_API_ENDPOINT"});
25
- const bot_answer = await ExtUtil.execPipelineExt(supportRequest, answer, directivesPlug, null, false);
26
- console.log("bot as obj", bot_answer);
27
- console.log("bot", JSON.stringify(bot_answer));
28
- assert.strictEqual(bot_answer.text, "message1\n\nmessage2");
29
- assert(bot_answer.attributes.commands != null);
30
- assert(bot_answer.attributes.commands.length == 3);
31
-
32
- console.log("Directives:", directivesPlug.directives)
33
- assert(directivesPlug.directives != null);
34
- assert(directivesPlug.directives.length == 1);
35
- assert(directivesPlug.directives[0].name.toLowerCase() == "wait");
36
- });
37
-
38
- });
39
-
40
-
41
-