@tiledesk/tiledesk-tybot-connector 2.0.8-rc2 → 2.0.8
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 +5 -31
- package/ExtApi.js +8 -1
- package/ExtUtil.js +6 -5
- package/Logger.js +13 -30
- package/TdCache copy.js +242 -0
- package/engine/IntentForm.js +1 -0
- package/engine/IntentsMachineFactory.js +4 -4
- package/engine/MongodbBotsDataSource.js +1 -0
- package/engine/MongodbIntentsMachine.js +1 -0
- package/engine/TiledeskChatbot.js +16 -11
- package/engine/TiledeskIntentsMachine.js +2 -1
- package/engine/mock/MockBotsDataSource.js +2 -1
- package/index.js +25 -22
- package/logs/app1.log +1310 -0
- package/package.json +2 -3
- package/services/AIService.js +1 -1
- package/services/IntegrationService.js +1 -1
- package/services/TilebotService.js +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +18 -24
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +2 -1
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +3 -1
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +3 -1
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +9 -7
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfNotOpenHours.js +10 -3
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +9 -2
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirAssign.js +8 -5
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +6 -4
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirClose.js +2 -0
- package/tiledeskChatbotPlugs/directives/DirCode.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirCondition.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +5 -2
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirForm.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +55 -36
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +4 -1
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +4 -1
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +2 -0
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +12 -8
- package/tiledeskChatbotPlugs/directives/DirIntent.js +5 -6
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirMake.js +16 -1
- package/tiledeskChatbotPlugs/directives/DirMessage.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +3 -0
- package/tiledeskChatbotPlugs/directives/DirQapla.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +2 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirReply.js +18 -7
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +13 -8
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +4 -1
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +3 -1
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirWait.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +16 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +417 -0
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +39 -0
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +1 -0
- package/tiledeskChatbotPlugs/directives/Directives.js +0 -1
- package/utils/TiledeskChatbotUtil.js +57 -19
package/CHANGELOG.md
CHANGED
|
@@ -5,17 +5,16 @@
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
+
# 2.0.8
|
|
9
|
+
|
|
10
|
+
# 2.0.8-rc2
|
|
11
|
+
- added: check on preloaded_request_id in /block
|
|
12
|
+
|
|
8
13
|
# 2.0.8-rc1
|
|
9
14
|
- removed: TILEBOT_LOG var
|
|
10
15
|
|
|
11
|
-
# 0.5.1-rc1
|
|
12
|
-
- added json_buttons
|
|
13
|
-
- added winston log with code refactoring
|
|
14
|
-
|
|
15
16
|
# v0.5.0
|
|
16
17
|
- added: AI_ENDPOINT env var
|
|
17
|
-
|
|
18
|
-
# v0.5.0-rc1
|
|
19
18
|
- added: ability to get 'none' as bodytype in webresponse
|
|
20
19
|
|
|
21
20
|
# v0.4.2
|
|
@@ -30,19 +29,6 @@ available on:
|
|
|
30
29
|
- changed: refactoring of DIrWebRequestv2
|
|
31
30
|
- bug-fixed: erro while parsing webrequestv2 body
|
|
32
31
|
|
|
33
|
-
# v0.3.5-rc4
|
|
34
|
-
- added: webhook action (same as intent one)
|
|
35
|
-
|
|
36
|
-
# v0.3.5-rc3
|
|
37
|
-
- bug-fixed: jsonBody parse error in web-request-v2
|
|
38
|
-
|
|
39
|
-
# v0.3.5-rc2
|
|
40
|
-
- bug-fixed: cannot set status of undefined reading res.status in DirAssistant
|
|
41
|
-
|
|
42
|
-
# v0.3.5-rc1
|
|
43
|
-
- changed: refactoring web-request-v2
|
|
44
|
-
- bug-fixed: jsonBody parse error in web-request-v2
|
|
45
|
-
|
|
46
32
|
# v0.3.4
|
|
47
33
|
-bug-fixed: slit is undefined in TiledeskChatbotUtils
|
|
48
34
|
|
|
@@ -52,18 +38,6 @@ available on:
|
|
|
52
38
|
# v0.3.2
|
|
53
39
|
- bug-fixed: minor improvement
|
|
54
40
|
|
|
55
|
-
# v0.2.153-rc9
|
|
56
|
-
- changed: updated tiledesk-multi-worker to 0.2.1-rc2
|
|
57
|
-
|
|
58
|
-
# v0.2.153-rc8
|
|
59
|
-
- added: fixToken function in TiledeskService utils class
|
|
60
|
-
|
|
61
|
-
# v0.2.153-rc4
|
|
62
|
-
- log added
|
|
63
|
-
|
|
64
|
-
# v0.2.153-rc3
|
|
65
|
-
- added: specchToText function to transcript audio file
|
|
66
|
-
|
|
67
41
|
# v0.2.153-rc1
|
|
68
42
|
- changed: context for gpt-40 and gpt-40-mini
|
|
69
43
|
|
package/ExtApi.js
CHANGED
|
@@ -10,6 +10,12 @@ class ExtApi {
|
|
|
10
10
|
throw new Error("options.TILEBOT_ENDPOINT is mandatory");
|
|
11
11
|
//this.extEndpoint = `${options.TILEBOT_ENDPOINT}/;
|
|
12
12
|
}
|
|
13
|
+
if (options.log) {
|
|
14
|
+
this.log = options.log;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this.log = false;
|
|
18
|
+
}
|
|
13
19
|
this.TILEBOT_ENDPOINT = options.TILEBOT_ENDPOINT;
|
|
14
20
|
}
|
|
15
21
|
|
|
@@ -57,7 +63,8 @@ class ExtApi {
|
|
|
57
63
|
callback(null, resbody);
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
|
-
}
|
|
66
|
+
}, this.log
|
|
67
|
+
);
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
}
|
package/ExtUtil.js
CHANGED
|
@@ -8,19 +8,20 @@ const { FillParamsChatbotPlug } = require('./tiledeskChatbotPlugs/FillParamsChat
|
|
|
8
8
|
|
|
9
9
|
// PROD
|
|
10
10
|
/*const { MessagePipeline } = require('@tiledesk/tiledesk-chatbot-plugs/MessagePipeline');
|
|
11
|
+
const { DirectivesChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/DirectivesChatbotPlug');
|
|
11
12
|
const { SplitsChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/SplitsChatbotPlug');
|
|
12
13
|
const { MarkbotChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/MarkbotChatbotPlug');
|
|
13
14
|
const { WebhookChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/WebhookChatbotPlug');*/
|
|
14
15
|
|
|
15
16
|
class ExtUtil {
|
|
16
17
|
|
|
17
|
-
static async execPipelineExt(request, static_bot_answer, directivesPlug, tdcache) {
|
|
18
|
+
static async execPipelineExt(request, static_bot_answer, directivesPlug, tdcache, log) {
|
|
18
19
|
const messagePipeline = new MessagePipeline(static_bot_answer, null);
|
|
19
20
|
messagePipeline.addPlug(directivesPlug);
|
|
20
|
-
messagePipeline.addPlug(new FillParamsChatbotPlug(request, tdcache)); // in original message
|
|
21
|
-
messagePipeline.addPlug(new SplitsChatbotPlug());
|
|
22
|
-
messagePipeline.addPlug(new MarkbotChatbotPlug());
|
|
23
|
-
messagePipeline.addPlug(new FillParamsChatbotPlug(request, tdcache)); // in splits
|
|
21
|
+
messagePipeline.addPlug(new FillParamsChatbotPlug(request, tdcache, log)); // in original message
|
|
22
|
+
messagePipeline.addPlug(new SplitsChatbotPlug(log));
|
|
23
|
+
messagePipeline.addPlug(new MarkbotChatbotPlug(log));
|
|
24
|
+
messagePipeline.addPlug(new FillParamsChatbotPlug(request, tdcache, log)); // in splits
|
|
24
25
|
const bot_answer = await messagePipeline.exec();
|
|
25
26
|
return bot_answer;
|
|
26
27
|
}
|
package/Logger.js
CHANGED
|
@@ -2,18 +2,13 @@ let { Publisher } = require("@tiledesk/tiledesk-multi-worker");
|
|
|
2
2
|
|
|
3
3
|
const FLOW_LOGS_ENABLED = process.env.FLOW_LOGS_ENABLED;
|
|
4
4
|
const AMQP_MANAGER_URL = process.env.AMQP_MANAGER_URL;
|
|
5
|
-
const LOGS_BASE_ROUTING_KEY = process.env.LOGS_BASE_ROUTING_KEY || "apps.tilechat.logs";
|
|
6
|
-
|
|
7
|
-
const levels = { error: 0, warn: 1, info: 2, debug: 3 };
|
|
8
|
-
|
|
9
5
|
let publisher = new Publisher(AMQP_MANAGER_URL, {
|
|
10
6
|
debug: false,
|
|
11
7
|
queueName: "logs_queue",
|
|
12
|
-
exchange: "
|
|
8
|
+
exchange: "tiledesk-multi",
|
|
9
|
+
topic: "logs",
|
|
13
10
|
})
|
|
14
11
|
|
|
15
|
-
console.log("LOGGER publisher: ", publisher);
|
|
16
|
-
|
|
17
12
|
class Logger {
|
|
18
13
|
|
|
19
14
|
constructor(config) {
|
|
@@ -38,15 +33,10 @@ class Logger {
|
|
|
38
33
|
}
|
|
39
34
|
|
|
40
35
|
this.request_id = config.request_id;
|
|
41
|
-
console.log("LOGGER for request ", this.request_id);
|
|
42
|
-
|
|
43
36
|
this.dev = false;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// } else {
|
|
48
|
-
// this._disableDebugMethods()
|
|
49
|
-
// }
|
|
37
|
+
if (config.dev && config.dev === true) {
|
|
38
|
+
this.dev = true;
|
|
39
|
+
}
|
|
50
40
|
|
|
51
41
|
// if (!AMQP_MANAGER_URL) {
|
|
52
42
|
// console.error('AMQP_MANAGER_URL is undefined. Logger not available...');
|
|
@@ -78,29 +68,27 @@ class Logger {
|
|
|
78
68
|
|
|
79
69
|
base(level, text) {
|
|
80
70
|
if (!this.request_id || !publisher) {
|
|
81
|
-
console.log("Return because request or publisher is undefined", this.request_id, publisher);
|
|
71
|
+
//console.log("Return because request or publisher is undefined", this.request_id, publisher);
|
|
82
72
|
return;
|
|
83
73
|
}
|
|
84
74
|
|
|
85
75
|
let data = {
|
|
86
76
|
request_id: this.request_id,
|
|
87
|
-
id_project: this.request_id.split("-")[2],
|
|
88
77
|
text: text,
|
|
89
78
|
level: level,
|
|
90
|
-
nlevel: levels[level],
|
|
91
79
|
timestamp: new Date(),
|
|
92
80
|
dev: this.dev
|
|
93
81
|
}
|
|
94
82
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
83
|
+
publisher.publish(data, (err, ok) => {
|
|
84
|
+
if (err) console.warn("publish log fail: ", err);
|
|
85
|
+
return;
|
|
86
|
+
})
|
|
99
87
|
}
|
|
100
88
|
|
|
101
89
|
formatLog(args) {
|
|
102
90
|
return args
|
|
103
|
-
.map(arg => (typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg))
|
|
91
|
+
.map(arg => (typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg ))
|
|
104
92
|
.join(" ")
|
|
105
93
|
}
|
|
106
94
|
|
|
@@ -108,14 +96,9 @@ class Logger {
|
|
|
108
96
|
_disableMethods() {
|
|
109
97
|
const methods = ['error', 'warn', 'info', 'debug'];
|
|
110
98
|
methods.forEach(method => {
|
|
111
|
-
|
|
99
|
+
this[method] = () => {};
|
|
112
100
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
_disableDebugMethods() {
|
|
116
|
-
const method = 'debug';
|
|
117
|
-
this[method] = () => { };
|
|
118
|
-
}
|
|
101
|
+
}
|
|
119
102
|
|
|
120
103
|
}
|
|
121
104
|
|
package/TdCache copy.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
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
|
+
reject(err);
|
|
23
|
+
if (callback) {
|
|
24
|
+
callback(err);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
// this.client.on('connect', function() {
|
|
28
|
+
// console.log('Redis Connected!');
|
|
29
|
+
// });
|
|
30
|
+
this.client.on('ready',function() {
|
|
31
|
+
console.log("connected")
|
|
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
|
+
if (!options) {
|
|
44
|
+
options = {EX: 86400}
|
|
45
|
+
}
|
|
46
|
+
return new Promise( async (resolve, reject) => {
|
|
47
|
+
if (options && options.EX) {
|
|
48
|
+
//console.log("expires:", options.EX)
|
|
49
|
+
try {
|
|
50
|
+
await this.client.set(
|
|
51
|
+
key,
|
|
52
|
+
value,
|
|
53
|
+
'EX', options.EX);
|
|
54
|
+
}
|
|
55
|
+
catch(error) {
|
|
56
|
+
reject(error)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
try {
|
|
61
|
+
//console.log("setting here...key", key, value)
|
|
62
|
+
await this.client.set(
|
|
63
|
+
key,
|
|
64
|
+
value);
|
|
65
|
+
}
|
|
66
|
+
catch(error) {
|
|
67
|
+
console.error("Error", error);
|
|
68
|
+
reject(error)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (options && options.callback) {
|
|
72
|
+
options.callback();
|
|
73
|
+
}
|
|
74
|
+
//console.log("resolving...", key);
|
|
75
|
+
return resolve();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async incr(key) {
|
|
80
|
+
// console.log("incr key:", key)
|
|
81
|
+
return new Promise( async (resolve, reject) => {
|
|
82
|
+
try {
|
|
83
|
+
// console.log("incr here...key", key)
|
|
84
|
+
await this.client.incr(key);
|
|
85
|
+
}
|
|
86
|
+
catch(error) {
|
|
87
|
+
console.error("Error on incr:", error);
|
|
88
|
+
reject(error)
|
|
89
|
+
}
|
|
90
|
+
return resolve();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async hset(dict_key, key, value, options) {
|
|
95
|
+
//console.log("hsetting dict_key key value", dict_key, key, value)
|
|
96
|
+
return new Promise( async (resolve, reject) => {
|
|
97
|
+
if (options && options.EX) {
|
|
98
|
+
//console.log("expires:", options.EX)
|
|
99
|
+
try {
|
|
100
|
+
await this.client.hset(
|
|
101
|
+
dict_key,
|
|
102
|
+
key,
|
|
103
|
+
value,
|
|
104
|
+
'EX', options.EX);
|
|
105
|
+
}
|
|
106
|
+
catch(error) {
|
|
107
|
+
reject(error)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
try {
|
|
112
|
+
//console.log("setting here...key", key, value)
|
|
113
|
+
await this.client.hset(
|
|
114
|
+
dict_key,
|
|
115
|
+
key,
|
|
116
|
+
value);
|
|
117
|
+
}
|
|
118
|
+
catch(error) {
|
|
119
|
+
console.error("Error", error);
|
|
120
|
+
reject(error)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (options && options.callback) {
|
|
124
|
+
options.callback();
|
|
125
|
+
}
|
|
126
|
+
return resolve();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async hdel(dict_key, key, options) {
|
|
131
|
+
//console.log("hsetting dict_key key value", dict_key, key, value)
|
|
132
|
+
return new Promise( async (resolve, reject) => {
|
|
133
|
+
if (options && options.EX) {
|
|
134
|
+
//console.log("expires:", options.EX)
|
|
135
|
+
try {
|
|
136
|
+
await this.client.hdel(
|
|
137
|
+
dict_key,
|
|
138
|
+
key,
|
|
139
|
+
'EX', options.EX);
|
|
140
|
+
}
|
|
141
|
+
catch(error) {
|
|
142
|
+
reject(error)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
try {
|
|
147
|
+
//console.log("setting here...key", key, value)
|
|
148
|
+
await this.client.hdel(
|
|
149
|
+
dict_key,
|
|
150
|
+
key);
|
|
151
|
+
}
|
|
152
|
+
catch(error) {
|
|
153
|
+
console.error("Error", error);
|
|
154
|
+
reject(error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (options && options.callback) {
|
|
158
|
+
options.callback();
|
|
159
|
+
}
|
|
160
|
+
return resolve();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async setJSON(key, value, options) {
|
|
165
|
+
const _string = JSON.stringify(value);
|
|
166
|
+
return await this.set(key, _string, options);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async get(key, callback) {
|
|
170
|
+
//console.log("getting key", key)
|
|
171
|
+
return new Promise( async (resolve, reject) => {
|
|
172
|
+
this.client.get(key, (err, value) => {
|
|
173
|
+
if (err) {
|
|
174
|
+
reject(err);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
if (callback) {
|
|
178
|
+
callback(value);
|
|
179
|
+
}
|
|
180
|
+
return resolve(value);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async hgetall(dict_key, callback) {
|
|
187
|
+
//console.log("hgetting dics", dict_key);
|
|
188
|
+
return new Promise( async (resolve, reject) => {
|
|
189
|
+
this.client.hgetall(dict_key, (err, value) => {
|
|
190
|
+
if (err) {
|
|
191
|
+
reject(err);
|
|
192
|
+
if (callback) {
|
|
193
|
+
callback(err, null);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
if (callback) {
|
|
198
|
+
callback(null, value);
|
|
199
|
+
}
|
|
200
|
+
resolve(value);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async hget(dict_key, key, callback) {
|
|
207
|
+
//console.log("hgetting dics", dict_key);
|
|
208
|
+
return new Promise( async (resolve, reject) => {
|
|
209
|
+
this.client.hget(dict_key, key, (err, value) => {
|
|
210
|
+
if (err) {
|
|
211
|
+
reject(err);
|
|
212
|
+
if (callback) {
|
|
213
|
+
callback(err, null);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
if (callback) {
|
|
218
|
+
callback(null, value);
|
|
219
|
+
}
|
|
220
|
+
resolve(value);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async getJSON(key, callback) {
|
|
227
|
+
const value = await this.get(key);
|
|
228
|
+
return JSON.parse(value);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async del(key, callback) {
|
|
232
|
+
return new Promise( async (resolve, reject) => {
|
|
233
|
+
await this.client.del(key);
|
|
234
|
+
if (callback) {
|
|
235
|
+
callback();
|
|
236
|
+
}
|
|
237
|
+
return resolve();
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
module.exports = { TdCache };
|
package/engine/IntentForm.js
CHANGED
|
@@ -11,6 +11,7 @@ class IntentForm {
|
|
|
11
11
|
this.form = options.form;
|
|
12
12
|
this.CURRENT_FIELD_INDEX_KEY = "tilebot:requests:" + this.requestId + ":currentFieldIndex"
|
|
13
13
|
this.CURRENT_FORM_KEY = "tilebot:requests:" + this.requestId + ":currentForm"
|
|
14
|
+
this.log = options.log;
|
|
14
15
|
this.requestParameters = options.requestParameters;
|
|
15
16
|
}
|
|
16
17
|
|
|
@@ -4,7 +4,7 @@ const winston = require('../utils/winston.js')
|
|
|
4
4
|
|
|
5
5
|
class IntentsMachineFactory {
|
|
6
6
|
|
|
7
|
-
static getMachine(bot, botId, projectId) {
|
|
7
|
+
static getMachine(bot, botId, projectId, log) {
|
|
8
8
|
let machine;
|
|
9
9
|
if (bot && bot.intentsEngine === "tiledesk-ai") {
|
|
10
10
|
winston.verbose("(IntentsMachineFactory) bot.intentsEngine is tiledesk-ai");
|
|
@@ -15,7 +15,7 @@ class IntentsMachineFactory {
|
|
|
15
15
|
}
|
|
16
16
|
else if (bot) {
|
|
17
17
|
winston.verbose("(IntentsMachineFactory) Setting MongodbIntentsMachine with bot:", JSON.stringify(bot));
|
|
18
|
-
machine = new MongodbIntentsMachine({projectId: projectId, language: bot.language});
|
|
18
|
+
machine = new MongodbIntentsMachine({projectId: projectId, language: bot.language, log});
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
21
|
winston.error("bot is null for: " + botId + " on projectId: " + projectId);
|
|
@@ -23,10 +23,10 @@ class IntentsMachineFactory {
|
|
|
23
23
|
return machine;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
static getBackupMachine(bot, botId, projectId) {
|
|
26
|
+
static getBackupMachine(bot, botId, projectId, log) {
|
|
27
27
|
let machine;
|
|
28
28
|
winston.verbose("(IntentsMachineFactory) Setting MongodbIntentsMachine as Backup Intents Machine on bot:", JSON.stringify(bot));
|
|
29
|
-
machine = new MongodbIntentsMachine({projectId: projectId, language: bot.language});
|
|
29
|
+
machine = new MongodbIntentsMachine({projectId: projectId, language: bot.language, log});
|
|
30
30
|
return machine;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// let Faq = require('./faq');
|
|
2
2
|
// let Faq_kb = require('./faq_kb');
|
|
3
|
+
// const { DirectivesChatbotPlug } = require('../tiledeskChatbotPlugs/DirectivesChatbotPlug');
|
|
3
4
|
const { MessagePipeline } = require('../tiledeskChatbotPlugs/MessagePipeline');
|
|
4
5
|
const { WebhookChatbotPlug } = require('../tiledeskChatbotPlugs/WebhookChatbotPlug');
|
|
5
6
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
@@ -40,6 +41,7 @@ class TiledeskChatbot {
|
|
|
40
41
|
this.projectId = config.projectId;
|
|
41
42
|
this.MAX_STEPS = config.MAX_STEPS;
|
|
42
43
|
this.MAX_EXECUTION_TIME = config.MAX_EXECUTION_TIME;
|
|
44
|
+
this.log = config.log;
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
async replyToMessage(message, callback) {
|
|
@@ -70,13 +72,13 @@ class TiledeskChatbot {
|
|
|
70
72
|
winston.verbose("(TiledeskChatbot) Resetting current step by request message: " + message.text);
|
|
71
73
|
await TiledeskChatbot.resetStep(this.tdcache, this.requestId);
|
|
72
74
|
await TiledeskChatbot.resetStarted(this.tdcache, this.requestId);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
if (this.log) {
|
|
76
|
+
if (this.tdcache) {
|
|
77
|
+
let currentStep =
|
|
78
|
+
await TiledeskChatbot.currentStep(this.tdcache, this.requestId);
|
|
79
|
+
winston.verbose("(TiledeskChatbot) After reset currentStep:" + currentStep);
|
|
80
|
+
}
|
|
78
81
|
}
|
|
79
|
-
|
|
80
82
|
}
|
|
81
83
|
} catch(error) {
|
|
82
84
|
winston.error("(TiledeskChatbot) Error resetting locked intent: ", error);
|
|
@@ -91,7 +93,8 @@ class TiledeskChatbot {
|
|
|
91
93
|
// projectId: this.projectId,
|
|
92
94
|
// token: this.token,
|
|
93
95
|
// APIURL: this.APIURL,
|
|
94
|
-
// APIKEY: this.APIKEY
|
|
96
|
+
// APIKEY: this.APIKEY,
|
|
97
|
+
// log: false
|
|
95
98
|
// });
|
|
96
99
|
// it only gets the locked_intent
|
|
97
100
|
// const faq = await this.botsDataSource.getByIntentDisplayName(this.botId, locked_intent);
|
|
@@ -503,7 +506,7 @@ class TiledeskChatbot {
|
|
|
503
506
|
TiledeskChatbot.requestCacheKey(requestId) + ":parameters", paramName);
|
|
504
507
|
}
|
|
505
508
|
|
|
506
|
-
static async checkStep(_tdcache, requestId, max_steps, max_execution_time) {
|
|
509
|
+
static async checkStep(_tdcache, requestId, max_steps, max_execution_time, log) {
|
|
507
510
|
winston.verbose("(TiledeskChatbot) Checking on MAX_STEPS: " + max_steps);
|
|
508
511
|
// let go_on = true; // continue
|
|
509
512
|
const parameter_key = TiledeskChatbot.requestCacheKey(requestId) + ":step";
|
|
@@ -576,7 +579,7 @@ class TiledeskChatbot {
|
|
|
576
579
|
}
|
|
577
580
|
const messagePipeline = new MessagePipeline(static_bot_answer, context);
|
|
578
581
|
const webhookurl = bot.webhook_url;
|
|
579
|
-
messagePipeline.addPlug(new WebhookChatbotPlug(userMessage.request, webhookurl, this.token));
|
|
582
|
+
messagePipeline.addPlug(new WebhookChatbotPlug(userMessage.request, webhookurl, this.token, this.log));
|
|
580
583
|
const bot_answer = await messagePipeline.exec();
|
|
581
584
|
return bot_answer;
|
|
582
585
|
}
|
|
@@ -589,7 +592,8 @@ class TiledeskChatbot {
|
|
|
589
592
|
form: form,
|
|
590
593
|
requestId: this.requestId,
|
|
591
594
|
chatbot: this,
|
|
592
|
-
requestParameters: all_parameters
|
|
595
|
+
requestParameters: all_parameters,
|
|
596
|
+
log: this.log
|
|
593
597
|
});
|
|
594
598
|
let message = await intentForm.getMessage(userInputReply);
|
|
595
599
|
return message;
|
|
@@ -606,7 +610,8 @@ class TiledeskChatbot {
|
|
|
606
610
|
projectId: this.projectId,
|
|
607
611
|
token: this.token,
|
|
608
612
|
APIURL: this.APIURL,
|
|
609
|
-
APIKEY: this.APIKEY
|
|
613
|
+
APIKEY: this.APIKEY,
|
|
614
|
+
log: this.log
|
|
610
615
|
});
|
|
611
616
|
// const parameters_key = "tilebot:requests:" + requestId + ":parameters";
|
|
612
617
|
const all_parameters = await this.allParameters();//this.tdcache.hgetall(parameters_key);
|
|
@@ -12,6 +12,7 @@ class TiledeskIntentsMachine {
|
|
|
12
12
|
else {
|
|
13
13
|
this.API_ENDPOINT = config.API_ENDPOINT;
|
|
14
14
|
}
|
|
15
|
+
this.log = config.log;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -92,7 +93,7 @@ class TiledeskIntentsMachine {
|
|
|
92
93
|
return tiledesk_intents;
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
myrequest(options, callback) {
|
|
96
|
+
myrequest(options, callback, log) {
|
|
96
97
|
axios(
|
|
97
98
|
{
|
|
98
99
|
url: options.url,
|