@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.
- package/CHANGELOG.md +10 -1
- package/ExtApi.js +37 -0
- package/index backup.js +656 -0
- package/index.js +58 -461
- package/models/IntentForm.js +12 -13
- package/models/MockBotsDataSource.js +74 -0
- package/models/MockIntentsMachine.js +39 -0
- package/models/MongodbBotsDataSource.js +73 -0
- package/models/MongodbIntentsMachine.js +55 -0
- package/models/{TiledeskChatbot_Intents_Adapter.js → TiledeskChatbot backup.js } +0 -1
- package/models/TiledeskChatbot.js +206 -180
- package/models/TiledeskIntentsMachine.js +90 -0
- package/models/faqKbService.js +27 -0
- package/models/faqService.js +22 -0
- package/models/faq_kb.js +11 -28
- package/package.json +2 -2
- package/test/close_directive_test.js +49 -0
- package/test/directives_test.js +24 -26
- package/test/disable_input_text_directive_test.js +88 -0
- package/test/mock_query_test.js +276 -0
- package/test/single_test.sh +4 -0
- package/test/when_open_directive_test.js +167 -0
- package/tiledeskChatbotPlugs/CHANGELOG.md +2 -0
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +66 -46
- package/tiledeskChatbotPlugs/directives/DirClose.js +25 -0
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +6 -6
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +52 -0
- package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +45 -0
- package/tiledeskChatbotPlugs/directives/DirIntent.js +50 -0
- package/tiledeskChatbotPlugs/directives/DirMessage.js +5 -4
- package/tiledeskChatbotPlugs/directives/DirWhenOpen.js +95 -0
- package/tiledeskChatbotPlugs/directives/Directives.js +3 -0
- package/tiledeskChatbotPlugs/package.json +1 -1
- package/models/MongoDBIntentsDataSource.js +0 -22
- package/models/StaticIntentsDataSource.js +0 -110
- package/test/chatbot_query_test.js_ +0 -41
package/models/faq_kb.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
var mongoose = require('mongoose');
|
|
2
2
|
var Schema = mongoose.Schema;
|
|
3
|
-
//const uuidv4 = require('uuid/v4');
|
|
4
|
-
//const uuidv4 = require('uuid');
|
|
5
3
|
|
|
6
4
|
var Faq_kbSchema = new Schema({
|
|
7
5
|
name: {
|
|
@@ -10,16 +8,13 @@ var Faq_kbSchema = new Schema({
|
|
|
10
8
|
index:true
|
|
11
9
|
},
|
|
12
10
|
description: {
|
|
13
|
-
type: String
|
|
14
|
-
// index:true
|
|
11
|
+
type: String
|
|
15
12
|
},
|
|
16
13
|
url: {
|
|
17
|
-
type: String
|
|
18
|
-
// required: true
|
|
14
|
+
type: String
|
|
19
15
|
},
|
|
20
16
|
webhook_url: {
|
|
21
|
-
type: String
|
|
22
|
-
// required: true
|
|
17
|
+
type: String
|
|
23
18
|
},
|
|
24
19
|
webhook_enabled: {
|
|
25
20
|
type: Boolean,
|
|
@@ -31,18 +26,11 @@ var Faq_kbSchema = new Schema({
|
|
|
31
26
|
required: true,
|
|
32
27
|
index: true
|
|
33
28
|
},
|
|
34
|
-
// kbkey_remote: { //serve?
|
|
35
|
-
// type: String,
|
|
36
|
-
// },
|
|
37
29
|
type: {
|
|
38
30
|
type: String,
|
|
39
31
|
default: 'internal',
|
|
40
32
|
index: true
|
|
41
33
|
},
|
|
42
|
-
// external: {
|
|
43
|
-
// type: Boolean,
|
|
44
|
-
// default: false
|
|
45
|
-
// },
|
|
46
34
|
trashed: {
|
|
47
35
|
type: Boolean,
|
|
48
36
|
index: true
|
|
@@ -57,7 +45,14 @@ var Faq_kbSchema = new Schema({
|
|
|
57
45
|
type: String,
|
|
58
46
|
required: false,
|
|
59
47
|
default: 'en'
|
|
60
|
-
|
|
48
|
+
},
|
|
49
|
+
public: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
index: true
|
|
52
|
+
},
|
|
53
|
+
certified: {
|
|
54
|
+
type: Boolean,
|
|
55
|
+
index: true
|
|
61
56
|
},
|
|
62
57
|
attributes: {
|
|
63
58
|
type: Object,
|
|
@@ -71,18 +66,6 @@ var Faq_kbSchema = new Schema({
|
|
|
71
66
|
}
|
|
72
67
|
);
|
|
73
68
|
|
|
74
|
-
Faq_kbSchema.virtual('fullName').get(function () {
|
|
75
|
-
// winston.debug("faq_kb fullName virtual called");
|
|
76
|
-
return (this.name);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
69
|
var faq_kb = mongoose.model('faq_kb', Faq_kbSchema);
|
|
80
70
|
|
|
81
|
-
if (process.env.MONGOOSE_SYNCINDEX) {
|
|
82
|
-
faq_kb.syncIndexes();
|
|
83
|
-
console.log("faq_kb syncIndexes");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
71
|
module.exports = faq_kb
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiledesk/tiledesk-tybot-connector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
4
4
|
"description": "Tiledesk Tybot connector",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@tiledesk/helpcenter-query-client": "^0.1.8",
|
|
15
15
|
"@tiledesk/tiledesk-chatbot-client": "^0.5.30",
|
|
16
16
|
"@tiledesk/tiledesk-chatbot-util": "^0.8.38",
|
|
17
|
-
"@tiledesk/tiledesk-client": "^0.8.
|
|
17
|
+
"@tiledesk/tiledesk-client": "^0.8.38",
|
|
18
18
|
"axios": "^0.27.2",
|
|
19
19
|
"body-parser": "^1.19.0",
|
|
20
20
|
"cors": "^2.8.5",
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
const { ExtUtil } = require('../ExtUtil');
|
|
3
|
+
const { DirectivesChatbotPlug } = require('../tiledeskChatbotPlugs/DirectivesChatbotPlug');
|
|
4
|
+
const { DirClose } = require('../tiledeskChatbotPlugs/directives/DirClose');
|
|
5
|
+
const supportRequest = require('./support_request.js').request;
|
|
6
|
+
|
|
7
|
+
describe('Directive DirClose', function() {
|
|
8
|
+
|
|
9
|
+
it('test directive DirClose', async () => {
|
|
10
|
+
class MockTdClient {
|
|
11
|
+
closeRequest(request_id, callback) {
|
|
12
|
+
callback(null, {});
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
close_directive = {
|
|
16
|
+
name: "close"
|
|
17
|
+
};
|
|
18
|
+
let dir = new DirClose({
|
|
19
|
+
tdclient: new MockTdClient()
|
|
20
|
+
});
|
|
21
|
+
dir.execute(close_directive, "A-REQUEST-ID", () => {
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('test directive DirClose in pipeline', async () => {
|
|
26
|
+
const message_text = `\\_tdclose`;
|
|
27
|
+
const answer = {
|
|
28
|
+
text: message_text,
|
|
29
|
+
attributes: {
|
|
30
|
+
splits: true,
|
|
31
|
+
directives: true,
|
|
32
|
+
markbot: true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let directivesPlug = new DirectivesChatbotPlug({supportRequest: supportRequest, TILEDESK_API_ENDPOINT: "APIURL", token: "token", log: false, HELP_CENTER_API_ENDPOINT: "HELP_CENTER_API_ENDPOINT"});
|
|
36
|
+
const bot_answer = await ExtUtil.execPipelineExt(supportRequest, answer, directivesPlug, null, false);
|
|
37
|
+
// console.log("bot_answer:", bot_answer);
|
|
38
|
+
// console.log("directivesPlug.directives:", directivesPlug.directives);
|
|
39
|
+
assert.strictEqual(bot_answer.text, "");
|
|
40
|
+
assert(bot_answer.attributes.commands == null);
|
|
41
|
+
assert(directivesPlug.directives != null);
|
|
42
|
+
assert(directivesPlug.directives.length == 1);
|
|
43
|
+
assert(directivesPlug.directives[0].name === "close");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
package/test/directives_test.js
CHANGED
|
@@ -3,37 +3,35 @@ const { ExtUtil } = require('../ExtUtil');
|
|
|
3
3
|
const { DirectivesChatbotPlug } = require('../tiledeskChatbotPlugs/DirectivesChatbotPlug');
|
|
4
4
|
const supportRequest = require('./support_request.js').request;
|
|
5
5
|
|
|
6
|
-
describe('
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
describe('Directives', function() {
|
|
7
|
+
|
|
8
|
+
it('test directives and splits', async () => {
|
|
9
|
+
const message_text = `message1
|
|
10
10
|
|
|
11
11
|
message2
|
|
12
12
|
* button1
|
|
13
13
|
\\_tdWait`;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
assert(bot_answer.attributes.commands != null);
|
|
30
|
-
assert(bot_answer.attributes.commands.length == 3);
|
|
14
|
+
const answer = {
|
|
15
|
+
text: message_text,
|
|
16
|
+
attributes: {
|
|
17
|
+
splits: true,
|
|
18
|
+
directives: true,
|
|
19
|
+
markbot: true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
let directivesPlug = new DirectivesChatbotPlug({supportRequest: supportRequest, TILEDESK_API_ENDPOINT: "APIURL", token: "token", log: false, HELP_CENTER_API_ENDPOINT: "HELP_CENTER_API_ENDPOINT"});
|
|
23
|
+
const bot_answer = await ExtUtil.execPipelineExt(supportRequest, answer, directivesPlug, null, false);
|
|
24
|
+
// console.log("bot as obj", bot_answer);
|
|
25
|
+
// console.log("bot", JSON.stringify(bot_answer));
|
|
26
|
+
assert.strictEqual(bot_answer.text, "message1\n\nmessage2");
|
|
27
|
+
assert(bot_answer.attributes.commands != null);
|
|
28
|
+
assert(bot_answer.attributes.commands.length == 3);
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
// console.log("Directives:", directivesPlug.directives)
|
|
31
|
+
assert(directivesPlug.directives != null);
|
|
32
|
+
assert(directivesPlug.directives.length == 1);
|
|
33
|
+
assert(directivesPlug.directives[0].name.toLowerCase() == "wait");
|
|
34
|
+
});
|
|
37
35
|
|
|
38
36
|
});
|
|
39
37
|
|
|
@@ -0,0 +1,88 @@
|
|
|
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('Directive DirDisableInputText', function() {
|
|
7
|
+
|
|
8
|
+
it('test directive DisableInputText (basic)', async () => {
|
|
9
|
+
const message_text = `message1
|
|
10
|
+
message2
|
|
11
|
+
* button1
|
|
12
|
+
\\_tddisableinputtext`;
|
|
13
|
+
const answer = {
|
|
14
|
+
text: message_text,
|
|
15
|
+
attributes: {
|
|
16
|
+
splits: true,
|
|
17
|
+
directives: true,
|
|
18
|
+
markbot: true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
let directivesPlug = new DirectivesChatbotPlug({supportRequest: supportRequest, TILEDESK_API_ENDPOINT: "APIURL", token: "token", log: false, HELP_CENTER_API_ENDPOINT: "HELP_CENTER_API_ENDPOINT"});
|
|
22
|
+
const bot_answer = await ExtUtil.execPipelineExt(supportRequest, answer, directivesPlug, null, false);
|
|
23
|
+
assert.strictEqual(bot_answer.text, "message1\nmessage2");
|
|
24
|
+
assert(bot_answer.attributes.commands == null);
|
|
25
|
+
assert(bot_answer.attributes.disableInputMessage == true);
|
|
26
|
+
assert(directivesPlug.directives != null);
|
|
27
|
+
assert(directivesPlug.directives.length == 1);
|
|
28
|
+
assert(directivesPlug.directives[0].name.toLowerCase() == "disableinputtext");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('test directive DisableInputText (placeholder message option: --label)', async () => {
|
|
32
|
+
const message_text = `message1
|
|
33
|
+
message2
|
|
34
|
+
* button1
|
|
35
|
+
\\_tddisableinputtext --label "Press a button to reply"`;
|
|
36
|
+
const answer = {
|
|
37
|
+
text: message_text,
|
|
38
|
+
attributes: {
|
|
39
|
+
splits: true,
|
|
40
|
+
directives: true,
|
|
41
|
+
markbot: true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let directivesPlug = new DirectivesChatbotPlug({supportRequest: supportRequest, TILEDESK_API_ENDPOINT: "APIURL", token: "token", log: false, HELP_CENTER_API_ENDPOINT: "HELP_CENTER_API_ENDPOINT"});
|
|
45
|
+
const bot_answer = await ExtUtil.execPipelineExt(supportRequest, answer, directivesPlug, null, false);
|
|
46
|
+
// console.log("bot as obj", bot_answer);
|
|
47
|
+
// console.log("bot", JSON.stringify(bot_answer));
|
|
48
|
+
assert.strictEqual(bot_answer.text, "message1\nmessage2");
|
|
49
|
+
assert(bot_answer.attributes.commands == null);
|
|
50
|
+
assert(bot_answer.attributes.disableInputMessage == true);
|
|
51
|
+
assert(bot_answer.attributes.inputMessagePlaceholder === "Press a button to reply");
|
|
52
|
+
// console.log("Directives:", directivesPlug.directives)
|
|
53
|
+
assert(directivesPlug.directives != null);
|
|
54
|
+
assert(directivesPlug.directives.length == 1);
|
|
55
|
+
assert(directivesPlug.directives[0].name.toLowerCase() == "disableinputtext");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('test directive DisableInputText (placeholder message, short form option: -l)', async () => {
|
|
59
|
+
const message_text = `message1
|
|
60
|
+
message2
|
|
61
|
+
* button1
|
|
62
|
+
\\_tddisableinputtext -l "Press a button to reply"`;
|
|
63
|
+
const answer = {
|
|
64
|
+
text: message_text,
|
|
65
|
+
attributes: {
|
|
66
|
+
splits: true,
|
|
67
|
+
directives: true,
|
|
68
|
+
markbot: true
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
let directivesPlug = new DirectivesChatbotPlug({supportRequest: supportRequest, TILEDESK_API_ENDPOINT: "APIURL", token: "token", log: false, HELP_CENTER_API_ENDPOINT: "HELP_CENTER_API_ENDPOINT"});
|
|
72
|
+
const bot_answer = await ExtUtil.execPipelineExt(supportRequest, answer, directivesPlug, null, false);
|
|
73
|
+
// console.log("bot as obj", bot_answer);
|
|
74
|
+
// console.log("bot", JSON.stringify(bot_answer));
|
|
75
|
+
assert.strictEqual(bot_answer.text, "message1\nmessage2");
|
|
76
|
+
assert(bot_answer.attributes.commands == null);
|
|
77
|
+
assert(bot_answer.attributes.disableInputMessage == true);
|
|
78
|
+
assert(bot_answer.attributes.inputMessagePlaceholder === "Press a button to reply");
|
|
79
|
+
// console.log("Directives:", directivesPlug.directives)
|
|
80
|
+
assert(directivesPlug.directives != null);
|
|
81
|
+
assert(directivesPlug.directives.length == 1);
|
|
82
|
+
assert(directivesPlug.directives[0].name.toLowerCase() == "disableinputtext");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
|
|
2
|
+
var assert = require('assert');
|
|
3
|
+
const { TiledeskChatbot } = require('../models/TiledeskChatbot.js');
|
|
4
|
+
const { MockBotsDataSource } = require('../models/MockBotsDataSource.js');
|
|
5
|
+
const { MockIntentsMachine } = require('../models/MockIntentsMachine.js');
|
|
6
|
+
|
|
7
|
+
const testBots = {
|
|
8
|
+
"bots": {
|
|
9
|
+
"bot1": {
|
|
10
|
+
"webhook_enabled": false,
|
|
11
|
+
"_id": 'bot1',
|
|
12
|
+
"name": 'test bot',
|
|
13
|
+
"id_project": 'project1',
|
|
14
|
+
"intents": {
|
|
15
|
+
"intent1": {
|
|
16
|
+
intent_display_name: "intent1",
|
|
17
|
+
questions: [
|
|
18
|
+
"intent1 question1",
|
|
19
|
+
"intent1 question2"
|
|
20
|
+
],
|
|
21
|
+
answer: "reply to intent1"
|
|
22
|
+
},
|
|
23
|
+
"intent2": {
|
|
24
|
+
intent_display_name: "intent1",
|
|
25
|
+
questions: [
|
|
26
|
+
"intent2 question1",
|
|
27
|
+
"intent2 question2"
|
|
28
|
+
],
|
|
29
|
+
answer: "reply to intent2"
|
|
30
|
+
},
|
|
31
|
+
"intent3": {
|
|
32
|
+
intent_display_name: "intent3",
|
|
33
|
+
questions: [
|
|
34
|
+
"intent3 question1",
|
|
35
|
+
"intent3 question2"
|
|
36
|
+
],
|
|
37
|
+
answer: "reply to intent3"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"questions_intent": {
|
|
41
|
+
|
|
42
|
+
"intent1 question1": "intent1",
|
|
43
|
+
"intent1 question2": "intent1",
|
|
44
|
+
|
|
45
|
+
"intent2 question1": "intent2",
|
|
46
|
+
"intent2 question2": "intent2",
|
|
47
|
+
|
|
48
|
+
"intent3 question1": "intent3",
|
|
49
|
+
"intent3 question2": "intent3"
|
|
50
|
+
},
|
|
51
|
+
"intents_nlp" : {
|
|
52
|
+
"query1": {
|
|
53
|
+
"intent_display_name": "intent1"
|
|
54
|
+
},
|
|
55
|
+
"query2": {
|
|
56
|
+
"intent_display_name": "intent2"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe('Basic Tilebot', function() {
|
|
64
|
+
it('create TiledeskChatbot instance',async () => {
|
|
65
|
+
const chatbot = new TiledeskChatbot({
|
|
66
|
+
botsDataSource: {},
|
|
67
|
+
intentsFinder: {},
|
|
68
|
+
botId: "bot1",
|
|
69
|
+
bot: {},
|
|
70
|
+
token: "token",
|
|
71
|
+
APIURL: "APIURL",
|
|
72
|
+
APIKEY: "___",
|
|
73
|
+
tdcache: null,
|
|
74
|
+
requestId: "request1",
|
|
75
|
+
projectId: "project1",
|
|
76
|
+
log: false
|
|
77
|
+
});
|
|
78
|
+
assert(chatbot != null);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('query intent-action', async () => {
|
|
82
|
+
const dataSource = new MockBotsDataSource(testBots);
|
|
83
|
+
const botId = "bot1";
|
|
84
|
+
const bot = await dataSource.getBotById(botId);
|
|
85
|
+
const chatbot = new TiledeskChatbot({
|
|
86
|
+
botsDataSource: dataSource,
|
|
87
|
+
intentsFinder: {},
|
|
88
|
+
botId: botId,
|
|
89
|
+
bot: bot,
|
|
90
|
+
token: "token",
|
|
91
|
+
APIURL: "APIURL",
|
|
92
|
+
APIKEY: "___",
|
|
93
|
+
tdcache: null,
|
|
94
|
+
requestId: "requestId",
|
|
95
|
+
projectId: "projectId",
|
|
96
|
+
log: false
|
|
97
|
+
});
|
|
98
|
+
assert(chatbot != null);
|
|
99
|
+
const message = {
|
|
100
|
+
text: "not important",
|
|
101
|
+
attributes: {
|
|
102
|
+
action: "intent1"
|
|
103
|
+
},
|
|
104
|
+
request: {
|
|
105
|
+
request_id: "requestId"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const reply = await chatbot.replyToMessage(message);
|
|
109
|
+
assert(reply);
|
|
110
|
+
assert(reply.text === testBots.bots[botId].intents.intent1.answer);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('query exact match', async () => {
|
|
114
|
+
const dataSource = new MockBotsDataSource(testBots);
|
|
115
|
+
const botId = "bot1";
|
|
116
|
+
const bot = await dataSource.getBotById(botId);
|
|
117
|
+
const chatbot = new TiledeskChatbot({
|
|
118
|
+
botsDataSource: dataSource,
|
|
119
|
+
intentsFinder: {},
|
|
120
|
+
botId: botId,
|
|
121
|
+
bot: bot,
|
|
122
|
+
token: "token",
|
|
123
|
+
APIURL: "APIURL",
|
|
124
|
+
APIKEY: "___",
|
|
125
|
+
tdcache: null,
|
|
126
|
+
requestId: "requestId",
|
|
127
|
+
projectId: "projectId",
|
|
128
|
+
log: false
|
|
129
|
+
});
|
|
130
|
+
assert(chatbot != null);
|
|
131
|
+
const message = {
|
|
132
|
+
text: "intent1 question1",
|
|
133
|
+
request: {
|
|
134
|
+
request_id: "requestId"
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const reply = await chatbot.replyToMessage(message);
|
|
138
|
+
assert(reply);
|
|
139
|
+
assert(reply.text === testBots.bots[botId].intents.intent1.answer);
|
|
140
|
+
assert(reply.attributes.intent_info.intent_name === testBots.bots[botId].intents.intent1.intent_display_name);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('query with /intent_name query syntax', async () => {
|
|
144
|
+
const dataSource = new MockBotsDataSource(testBots);
|
|
145
|
+
const botId = "bot1";
|
|
146
|
+
const bot = await dataSource.getBotById(botId);
|
|
147
|
+
const chatbot = new TiledeskChatbot({
|
|
148
|
+
botsDataSource: dataSource,
|
|
149
|
+
intentsFinder: {},
|
|
150
|
+
botId: botId,
|
|
151
|
+
bot: bot,
|
|
152
|
+
token: "token",
|
|
153
|
+
APIURL: "APIURL",
|
|
154
|
+
APIKEY: "___",
|
|
155
|
+
tdcache: null,
|
|
156
|
+
requestId: "requestId",
|
|
157
|
+
projectId: "projectId",
|
|
158
|
+
log: false
|
|
159
|
+
});
|
|
160
|
+
assert(chatbot != null);
|
|
161
|
+
const message = {
|
|
162
|
+
text: "/intent1",
|
|
163
|
+
request: {
|
|
164
|
+
request_id: "requestId"
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const reply = await chatbot.replyToMessage(message);
|
|
168
|
+
assert(reply);
|
|
169
|
+
assert(reply.text === testBots.bots[botId].intents.intent1.answer);
|
|
170
|
+
assert(reply.attributes.intent_info.intent_name === testBots.bots[botId].intents.intent1.intent_display_name);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('query NLP', async () => {
|
|
174
|
+
const dataSource = new MockBotsDataSource(testBots);
|
|
175
|
+
const intentsMachine = new MockIntentsMachine(testBots);
|
|
176
|
+
const botId = "bot1";
|
|
177
|
+
const bot = await dataSource.getBotById(botId);
|
|
178
|
+
const chatbot = new TiledeskChatbot({
|
|
179
|
+
botsDataSource: dataSource,
|
|
180
|
+
intentsFinder: intentsMachine,
|
|
181
|
+
botId: botId,
|
|
182
|
+
bot: bot,
|
|
183
|
+
token: "token",
|
|
184
|
+
APIURL: "APIURL",
|
|
185
|
+
APIKEY: "___",
|
|
186
|
+
tdcache: null,
|
|
187
|
+
requestId: "requestId",
|
|
188
|
+
projectId: "projectId",
|
|
189
|
+
log: false
|
|
190
|
+
});
|
|
191
|
+
assert(chatbot != null);
|
|
192
|
+
const message = {
|
|
193
|
+
text: "query1",
|
|
194
|
+
request: {
|
|
195
|
+
request_id: "requestId"
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const reply = await chatbot.replyToMessage(message);
|
|
199
|
+
assert(reply);
|
|
200
|
+
assert(reply.text === testBots.bots[botId].intents.intent1.answer);
|
|
201
|
+
assert(reply.attributes.intent_info.intent_name === testBots.bots[botId].intents.intent1.intent_display_name);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('query with defaultFallback', async () => {
|
|
205
|
+
// clone and add defaultFallback
|
|
206
|
+
let testIntents_with_defaultFallback = JSON.parse(JSON.stringify(testBots));
|
|
207
|
+
// This doesn't work. Objects are copied by reference. Only first level properties are cloned.
|
|
208
|
+
//let testIntentsDataSource_with_defaultFallback = Object.assign({}, testIntentsDataSource);
|
|
209
|
+
// added defaultFallback intent
|
|
210
|
+
const botId = "bot1";
|
|
211
|
+
testIntents_with_defaultFallback.bots[botId].intents["defaultFallback"] = {
|
|
212
|
+
intent_display_name: "defaultFallback",
|
|
213
|
+
questions: [],
|
|
214
|
+
answer: "reply for defaultFallback"
|
|
215
|
+
}
|
|
216
|
+
const dataSource = new MockBotsDataSource(testIntents_with_defaultFallback);
|
|
217
|
+
const bot = await dataSource.getBotById(botId);
|
|
218
|
+
const intentsMachine = new MockIntentsMachine(testBots);
|
|
219
|
+
const chatbot = new TiledeskChatbot({
|
|
220
|
+
botsDataSource: dataSource,
|
|
221
|
+
intentsFinder: intentsMachine,
|
|
222
|
+
botId: botId,
|
|
223
|
+
bot: bot,
|
|
224
|
+
token: "token",
|
|
225
|
+
APIURL: "APIURL",
|
|
226
|
+
APIKEY: "___",
|
|
227
|
+
tdcache: null,
|
|
228
|
+
requestId: "requestId",
|
|
229
|
+
projectId: "projectId",
|
|
230
|
+
log: false
|
|
231
|
+
});
|
|
232
|
+
assert(chatbot != null);
|
|
233
|
+
const message = {
|
|
234
|
+
text: "query unknown",
|
|
235
|
+
request: {
|
|
236
|
+
request_id: "requestId"
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const reply = await chatbot.replyToMessage(message);
|
|
240
|
+
assert(reply);
|
|
241
|
+
assert(reply.text === testIntents_with_defaultFallback.bots[botId].intents["defaultFallback"].answer);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('query with missing defaultFallback', async () => {
|
|
245
|
+
const dataSource = new MockBotsDataSource(testBots);
|
|
246
|
+
const botId = "bot1";
|
|
247
|
+
const bot = await dataSource.getBotById(botId);
|
|
248
|
+
const intentsMachine = new MockIntentsMachine(testBots);
|
|
249
|
+
const chatbot = new TiledeskChatbot({
|
|
250
|
+
botsDataSource: dataSource,
|
|
251
|
+
intentsFinder: intentsMachine,
|
|
252
|
+
botId: botId,
|
|
253
|
+
bot: bot,
|
|
254
|
+
token: "token",
|
|
255
|
+
APIURL: "APIURL",
|
|
256
|
+
APIKEY: "___",
|
|
257
|
+
tdcache: null,
|
|
258
|
+
requestId: "requestId",
|
|
259
|
+
projectId: "projectId",
|
|
260
|
+
log: false
|
|
261
|
+
});
|
|
262
|
+
assert(chatbot != null);
|
|
263
|
+
const message = {
|
|
264
|
+
text: "query unknown",
|
|
265
|
+
request: {
|
|
266
|
+
request_id: "requestId"
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const reply = await chatbot.replyToMessage(message);
|
|
270
|
+
assert(reply == null);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|