@tiledesk/tiledesk-tybot-connector 0.1.13 → 0.1.16
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 +14 -2
- package/ExtApi.js +2 -14
- package/ExtUtil.js +7 -4
- package/TdCache.js +170 -0
- package/index (copy).js +718 -0
- package/index.js +390 -203
- package/index_compare.js +471 -0
- package/models/IntentForm.js +190 -0
- package/models/TiledeskChatbot.js +400 -0
- package/models/faq.js +5 -6
- package/models/faq_kb.js +3 -2
- package/package.json +9 -9
- package/test/chatbot_query_test.js +41 -0
- package/test/directives_test.js +41 -0
- package/test/support_request.js +249 -0
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +16 -2
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +93 -0
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +30 -0
- package/tiledeskChatbotPlugs/directives/DirMessage.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirOfflineHours.js +2 -2
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +24 -0
- package/tiledeskChatbotPlugs/directives/Directives.js +2 -0
- package/tiledeskChatbotPlugs/directives/DEPRECATED_HelpCenter.js +0 -82
- package/tiledeskChatbotPlugs/directives/REMOVE_DirNoAvailableAgents.js +0 -61
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
# Tiledesk tybotRoute
|
|
2
2
|
|
|
3
|
-
**npm @tiledesk/tiledesk-tybot-connector@0.1.
|
|
3
|
+
**npm @tiledesk/tiledesk-tybot-connector@0.1.16**
|
|
4
4
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
+
### 0.1.16
|
|
9
|
+
- added Redis support to share some parameters (message.requestId, message.projectId) with Apps
|
|
10
|
+
|
|
11
|
+
### 0.1.15
|
|
12
|
+
- refactored with the models/TiledeskChatbot class
|
|
13
|
+
- added triggeredByMessageId property to the bot reply
|
|
14
|
+
- added "tdMessageId" parameter to be used during processing
|
|
15
|
+
|
|
16
|
+
### 0.1.14 online
|
|
17
|
+
- more replaceAll moved to replace(//)
|
|
18
|
+
- console.log clean
|
|
19
|
+
|
|
8
20
|
### 0.1.13 online
|
|
9
21
|
- replaceAll replaced by replace(//)
|
|
10
|
-
- TEMP: const depId = supportRequest.department._id
|
|
22
|
+
- TEMP: const depId = supportRequest.department._id
|
|
11
23
|
|
|
12
24
|
### 0.1.12 online - TEMP: const depId = supportRequest.department._id;
|
|
13
25
|
|
package/ExtApi.js
CHANGED
|
@@ -38,7 +38,6 @@ class ExtApi {
|
|
|
38
38
|
const jwt_token = this.fixToken(token);
|
|
39
39
|
const url = `${this.ENDPOINT}/ext/${projectId}/requests/${requestId}/messages`;
|
|
40
40
|
if (this.log) {console.log("sendSupportMessageExt URL", url);}
|
|
41
|
-
console.log("sendSupportMessageExt:", url);
|
|
42
41
|
const HTTPREQUEST = {
|
|
43
42
|
url: url,
|
|
44
43
|
headers: {
|
|
@@ -51,8 +50,9 @@ class ExtApi {
|
|
|
51
50
|
this.myrequest(
|
|
52
51
|
HTTPREQUEST,
|
|
53
52
|
function(err, resbody) {
|
|
54
|
-
console.log("sendSupportMessageExt resbody:", resbody);
|
|
53
|
+
//console.log("sendSupportMessageExt resbody:", resbody);
|
|
55
54
|
if (err) {
|
|
55
|
+
//console.error("sendSupportMessageExt error:", err)
|
|
56
56
|
if (callback) {
|
|
57
57
|
callback(err);
|
|
58
58
|
}
|
|
@@ -104,18 +104,6 @@ class ExtApi {
|
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
|
-
/*
|
|
108
|
-
static async execPipelineExt(static_bot_answer, directivesPlug) {
|
|
109
|
-
const messagePipeline = new MessagePipeline(static_bot_answer, null);
|
|
110
|
-
//const webhookurl = bot.webhook_url;
|
|
111
|
-
//messagePipeline.addPlug(new WebhookChatbotPlug(message.request, webhookurl, token));
|
|
112
|
-
messagePipeline.addPlug(directivesPlug);
|
|
113
|
-
messagePipeline.addPlug(new SplitsChatbotPlug(this.log));
|
|
114
|
-
messagePipeline.addPlug(new MarkbotChatbotPlug(this.log));
|
|
115
|
-
const bot_answer = await messagePipeline.exec();
|
|
116
|
-
if (this.log) {console.log("End pipeline ext, bot_answer:", JSON.stringify(bot_answer));}
|
|
117
|
-
return bot_answer;
|
|
118
|
-
}*/
|
|
119
107
|
}
|
|
120
108
|
|
|
121
109
|
module.exports = { ExtApi };
|
package/ExtUtil.js
CHANGED
|
@@ -3,7 +3,8 @@ const { MessagePipeline } = require('./tiledeskChatbotPlugs/MessagePipeline');
|
|
|
3
3
|
const { DirectivesChatbotPlug } = require('./tiledeskChatbotPlugs/DirectivesChatbotPlug');
|
|
4
4
|
const { SplitsChatbotPlug } = require('./tiledeskChatbotPlugs/SplitsChatbotPlug');
|
|
5
5
|
const { MarkbotChatbotPlug } = require('./tiledeskChatbotPlugs/MarkbotChatbotPlug');
|
|
6
|
-
const {
|
|
6
|
+
const { FillParamsChatbotPlug } = require('./tiledeskChatbotPlugs/FillParamsChatbotPlug');
|
|
7
|
+
//const { WebhookChatbotPlug } = require('./tiledeskChatbotPlugs/WebhookChatbotPlug');
|
|
7
8
|
|
|
8
9
|
// PROD
|
|
9
10
|
/*const { MessagePipeline } = require('@tiledesk/tiledesk-chatbot-plugs/MessagePipeline');
|
|
@@ -14,13 +15,15 @@ const { WebhookChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/Webhook
|
|
|
14
15
|
|
|
15
16
|
class ExtUtil {
|
|
16
17
|
|
|
17
|
-
static async execPipelineExt(static_bot_answer, directivesPlug) {
|
|
18
|
+
static async execPipelineExt(request, static_bot_answer, directivesPlug, tdcache, log) {
|
|
18
19
|
const messagePipeline = new MessagePipeline(static_bot_answer, null);
|
|
19
20
|
//const webhookurl = bot.webhook_url;
|
|
20
21
|
//messagePipeline.addPlug(new WebhookChatbotPlug(message.request, webhookurl, token));
|
|
22
|
+
messagePipeline.addPlug(new FillParamsChatbotPlug(request, tdcache, log)); // in original message
|
|
21
23
|
messagePipeline.addPlug(directivesPlug);
|
|
22
|
-
messagePipeline.addPlug(new SplitsChatbotPlug(
|
|
23
|
-
messagePipeline.addPlug(new MarkbotChatbotPlug(
|
|
24
|
+
messagePipeline.addPlug(new SplitsChatbotPlug(log));
|
|
25
|
+
messagePipeline.addPlug(new MarkbotChatbotPlug(log));
|
|
26
|
+
messagePipeline.addPlug(new FillParamsChatbotPlug(request, tdcache, log)); // in splits
|
|
24
27
|
const bot_answer = await messagePipeline.exec();
|
|
25
28
|
if (this.log) {console.log("End pipeline ext, bot_answer:", JSON.stringify(bot_answer));}
|
|
26
29
|
return bot_answer;
|
package/TdCache.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
console.log('Redis connection error', err);
|
|
23
|
+
reject(err);
|
|
24
|
+
if (callback) {
|
|
25
|
+
callback(err);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
// this.client.on('connect', function() {
|
|
29
|
+
// console.log('Redis Connected!');
|
|
30
|
+
// });
|
|
31
|
+
this.client.on('ready',function() {
|
|
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
|
+
return new Promise( async (resolve, reject) => {
|
|
44
|
+
if (options && options.EX) {
|
|
45
|
+
//console.log("expires:", options.EX)
|
|
46
|
+
try {
|
|
47
|
+
await this.client.set(
|
|
48
|
+
key,
|
|
49
|
+
value,
|
|
50
|
+
'EX', options.EX);
|
|
51
|
+
}
|
|
52
|
+
catch(error) {
|
|
53
|
+
reject(error)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
try {
|
|
58
|
+
//console.log("setting here...key", key, value)
|
|
59
|
+
await this.client.set(
|
|
60
|
+
key,
|
|
61
|
+
value);
|
|
62
|
+
}
|
|
63
|
+
catch(error) {
|
|
64
|
+
console.error("Error", error);
|
|
65
|
+
reject(error)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (options && options.callback) {
|
|
69
|
+
options.callback();
|
|
70
|
+
}
|
|
71
|
+
//console.log("resolving...", key);
|
|
72
|
+
return resolve();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async hset(dict_key, key, value, options) {
|
|
77
|
+
//console.log("hsetting dict_key key value", dict_key, key, value)
|
|
78
|
+
return new Promise( async (resolve, reject) => {
|
|
79
|
+
if (options && options.EX) {
|
|
80
|
+
//console.log("expires:", options.EX)
|
|
81
|
+
try {
|
|
82
|
+
await this.client.hset(
|
|
83
|
+
dict_key,
|
|
84
|
+
key,
|
|
85
|
+
value,
|
|
86
|
+
'EX', options.EX);
|
|
87
|
+
}
|
|
88
|
+
catch(error) {
|
|
89
|
+
reject(error)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
try {
|
|
94
|
+
//console.log("setting here...key", key, value)
|
|
95
|
+
await this.client.hset(
|
|
96
|
+
dict_key,
|
|
97
|
+
key,
|
|
98
|
+
value);
|
|
99
|
+
}
|
|
100
|
+
catch(error) {
|
|
101
|
+
console.error("Error", error);
|
|
102
|
+
reject(error)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (options && options.callback) {
|
|
106
|
+
options.callback();
|
|
107
|
+
}
|
|
108
|
+
return resolve();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async setJSON(key, value, options) {
|
|
113
|
+
const _string = JSON.stringify(value);
|
|
114
|
+
return await this.set(key, _string, options);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async get(key, callback) {
|
|
118
|
+
//console.log("getting key", key)
|
|
119
|
+
return new Promise( async (resolve, reject) => {
|
|
120
|
+
this.client.get(key, (err, value) => {
|
|
121
|
+
if (err) {
|
|
122
|
+
reject(err);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
if (callback) {
|
|
126
|
+
callback(value);
|
|
127
|
+
}
|
|
128
|
+
return resolve(value);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async hgetall(dict_key, callback) {
|
|
135
|
+
//console.log("hgetting dics", dict_key);
|
|
136
|
+
return new Promise( async (resolve, reject) => {
|
|
137
|
+
this.client.hgetall(dict_key, (err, value) => {
|
|
138
|
+
if (err) {
|
|
139
|
+
reject(err);
|
|
140
|
+
if (callback) {
|
|
141
|
+
callback(err, null);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
if (callback) {
|
|
146
|
+
callback(null, value);
|
|
147
|
+
}
|
|
148
|
+
resolve(value);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async getJSON(key, callback) {
|
|
155
|
+
const value = await this.get(key);
|
|
156
|
+
return JSON.parse(value);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async del(key, callback) {
|
|
160
|
+
return new Promise( async (resolve, reject) => {
|
|
161
|
+
await this.client.del(key);
|
|
162
|
+
if (callback) {
|
|
163
|
+
callback();
|
|
164
|
+
}
|
|
165
|
+
return resolve();
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
module.exports = { TdCache };
|