@tiledesk/tiledesk-tybot-connector 2.0.12-rc5 → 2.0.12-rc7
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/ExtApi.js +1 -8
- package/ExtUtil.js +5 -6
- package/engine/IntentForm.js +0 -1
- package/engine/IntentsMachineFactory.js +4 -4
- package/engine/MongodbBotsDataSource.js +0 -1
- package/engine/MongodbIntentsMachine.js +0 -1
- package/engine/TiledeskChatbot.js +11 -16
- package/engine/TiledeskIntentsMachine.js +1 -2
- package/index.js +11 -23
- package/package.json +1 -1
- package/services/AIService.js +1 -1
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +11 -10
- package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +1 -2
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +1 -3
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +1 -3
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +7 -9
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfNotOpenHours.js +3 -10
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +2 -9
- package/tiledeskChatbotPlugs/directives/DirAddKbContent.js +333 -0
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirFlowLog.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +36 -54
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +1 -2
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +7 -9
- package/tiledeskChatbotPlugs/directives/DirIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMake.js +1 -15
- package/tiledeskChatbotPlugs/directives/DirMessage.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirReply.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -10
- package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +1 -3
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +1 -15
- package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
- package/utils/TiledeskChatbotUtil.js +14 -28
package/ExtApi.js
CHANGED
|
@@ -10,12 +10,6 @@ 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
|
-
}
|
|
19
13
|
this.TILEBOT_ENDPOINT = options.TILEBOT_ENDPOINT;
|
|
20
14
|
}
|
|
21
15
|
|
|
@@ -63,8 +57,7 @@ class ExtApi {
|
|
|
63
57
|
callback(null, resbody);
|
|
64
58
|
}
|
|
65
59
|
}
|
|
66
|
-
}
|
|
67
|
-
);
|
|
60
|
+
});
|
|
68
61
|
}
|
|
69
62
|
|
|
70
63
|
}
|
package/ExtUtil.js
CHANGED
|
@@ -8,20 +8,19 @@ 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');
|
|
12
11
|
const { SplitsChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/SplitsChatbotPlug');
|
|
13
12
|
const { MarkbotChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/MarkbotChatbotPlug');
|
|
14
13
|
const { WebhookChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/WebhookChatbotPlug');*/
|
|
15
14
|
|
|
16
15
|
class ExtUtil {
|
|
17
16
|
|
|
18
|
-
static async execPipelineExt(request, static_bot_answer, directivesPlug, tdcache
|
|
17
|
+
static async execPipelineExt(request, static_bot_answer, directivesPlug, tdcache) {
|
|
19
18
|
const messagePipeline = new MessagePipeline(static_bot_answer, null);
|
|
20
19
|
messagePipeline.addPlug(directivesPlug);
|
|
21
|
-
messagePipeline.addPlug(new FillParamsChatbotPlug(request, tdcache
|
|
22
|
-
messagePipeline.addPlug(new SplitsChatbotPlug(
|
|
23
|
-
messagePipeline.addPlug(new MarkbotChatbotPlug(
|
|
24
|
-
messagePipeline.addPlug(new FillParamsChatbotPlug(request, tdcache
|
|
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
|
|
25
24
|
const bot_answer = await messagePipeline.exec();
|
|
26
25
|
return bot_answer;
|
|
27
26
|
}
|
package/engine/IntentForm.js
CHANGED
|
@@ -11,7 +11,6 @@ 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;
|
|
15
14
|
this.requestParameters = options.requestParameters;
|
|
16
15
|
}
|
|
17
16
|
|
|
@@ -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) {
|
|
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});
|
|
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) {
|
|
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});
|
|
30
30
|
return machine;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// let Faq = require('./faq');
|
|
2
2
|
// let Faq_kb = require('./faq_kb');
|
|
3
|
-
// const { DirectivesChatbotPlug } = require('../tiledeskChatbotPlugs/DirectivesChatbotPlug');
|
|
4
3
|
const { MessagePipeline } = require('../tiledeskChatbotPlugs/MessagePipeline');
|
|
5
4
|
const { WebhookChatbotPlug } = require('../tiledeskChatbotPlugs/WebhookChatbotPlug');
|
|
6
5
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
@@ -41,7 +40,6 @@ class TiledeskChatbot {
|
|
|
41
40
|
this.projectId = config.projectId;
|
|
42
41
|
this.MAX_STEPS = config.MAX_STEPS;
|
|
43
42
|
this.MAX_EXECUTION_TIME = config.MAX_EXECUTION_TIME;
|
|
44
|
-
this.log = config.log;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
async replyToMessage(message, callback) {
|
|
@@ -72,13 +70,13 @@ class TiledeskChatbot {
|
|
|
72
70
|
winston.verbose("(TiledeskChatbot) Resetting current step by request message: " + message.text);
|
|
73
71
|
await TiledeskChatbot.resetStep(this.tdcache, this.requestId);
|
|
74
72
|
await TiledeskChatbot.resetStarted(this.tdcache, this.requestId);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
73
|
+
|
|
74
|
+
if (this.tdcache) {
|
|
75
|
+
let currentStep =
|
|
76
|
+
await TiledeskChatbot.currentStep(this.tdcache, this.requestId);
|
|
77
|
+
winston.verbose("(TiledeskChatbot) After reset currentStep:" + currentStep);
|
|
81
78
|
}
|
|
79
|
+
|
|
82
80
|
}
|
|
83
81
|
} catch(error) {
|
|
84
82
|
winston.error("(TiledeskChatbot) Error resetting locked intent: ", error);
|
|
@@ -93,8 +91,7 @@ class TiledeskChatbot {
|
|
|
93
91
|
// projectId: this.projectId,
|
|
94
92
|
// token: this.token,
|
|
95
93
|
// APIURL: this.APIURL,
|
|
96
|
-
// APIKEY: this.APIKEY
|
|
97
|
-
// log: false
|
|
94
|
+
// APIKEY: this.APIKEY
|
|
98
95
|
// });
|
|
99
96
|
// it only gets the locked_intent
|
|
100
97
|
// const faq = await this.botsDataSource.getByIntentDisplayName(this.botId, locked_intent);
|
|
@@ -506,7 +503,7 @@ class TiledeskChatbot {
|
|
|
506
503
|
TiledeskChatbot.requestCacheKey(requestId) + ":parameters", paramName);
|
|
507
504
|
}
|
|
508
505
|
|
|
509
|
-
static async checkStep(_tdcache, requestId, max_steps, max_execution_time
|
|
506
|
+
static async checkStep(_tdcache, requestId, max_steps, max_execution_time) {
|
|
510
507
|
winston.verbose("(TiledeskChatbot) Checking on MAX_STEPS: " + max_steps);
|
|
511
508
|
// let go_on = true; // continue
|
|
512
509
|
const parameter_key = TiledeskChatbot.requestCacheKey(requestId) + ":step";
|
|
@@ -579,7 +576,7 @@ class TiledeskChatbot {
|
|
|
579
576
|
}
|
|
580
577
|
const messagePipeline = new MessagePipeline(static_bot_answer, context);
|
|
581
578
|
const webhookurl = bot.webhook_url;
|
|
582
|
-
messagePipeline.addPlug(new WebhookChatbotPlug(userMessage.request, webhookurl, this.token
|
|
579
|
+
messagePipeline.addPlug(new WebhookChatbotPlug(userMessage.request, webhookurl, this.token));
|
|
583
580
|
const bot_answer = await messagePipeline.exec();
|
|
584
581
|
return bot_answer;
|
|
585
582
|
}
|
|
@@ -592,8 +589,7 @@ class TiledeskChatbot {
|
|
|
592
589
|
form: form,
|
|
593
590
|
requestId: this.requestId,
|
|
594
591
|
chatbot: this,
|
|
595
|
-
requestParameters: all_parameters
|
|
596
|
-
log: this.log
|
|
592
|
+
requestParameters: all_parameters
|
|
597
593
|
});
|
|
598
594
|
let message = await intentForm.getMessage(userInputReply);
|
|
599
595
|
return message;
|
|
@@ -610,8 +606,7 @@ class TiledeskChatbot {
|
|
|
610
606
|
projectId: this.projectId,
|
|
611
607
|
token: this.token,
|
|
612
608
|
APIURL: this.APIURL,
|
|
613
|
-
APIKEY: this.APIKEY
|
|
614
|
-
log: this.log
|
|
609
|
+
APIKEY: this.APIKEY
|
|
615
610
|
});
|
|
616
611
|
// const parameters_key = "tilebot:requests:" + requestId + ":parameters";
|
|
617
612
|
const all_parameters = await this.allParameters();//this.tdcache.hgetall(parameters_key);
|
|
@@ -12,7 +12,6 @@ class TiledeskIntentsMachine {
|
|
|
12
12
|
else {
|
|
13
13
|
this.API_ENDPOINT = config.API_ENDPOINT;
|
|
14
14
|
}
|
|
15
|
-
this.log = config.log;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
/**
|
|
@@ -93,7 +92,7 @@ class TiledeskIntentsMachine {
|
|
|
93
92
|
return tiledesk_intents;
|
|
94
93
|
}
|
|
95
94
|
|
|
96
|
-
myrequest(options, callback
|
|
95
|
+
myrequest(options, callback) {
|
|
97
96
|
axios(
|
|
98
97
|
{
|
|
99
98
|
url: options.url,
|
package/index.js
CHANGED
|
@@ -18,7 +18,6 @@ let axios = require('axios');
|
|
|
18
18
|
router.use(bodyParser.json({limit: '50mb'}));
|
|
19
19
|
router.use(bodyParser.urlencoded({ extended: true , limit: '50mb'}));
|
|
20
20
|
|
|
21
|
-
let log = false;
|
|
22
21
|
/** @type {TdCache} */
|
|
23
22
|
let tdcache = null;
|
|
24
23
|
let MAX_STEPS = 1000;
|
|
@@ -87,7 +86,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
87
86
|
|
|
88
87
|
let botsDS;
|
|
89
88
|
if (!staticBots) {
|
|
90
|
-
botsDS = new MongodbBotsDataSource({projectId: projectId, botId: botId
|
|
89
|
+
botsDS = new MongodbBotsDataSource({projectId: projectId, botId: botId});
|
|
91
90
|
winston.verbose("(tybotRoute) botsDS created with Mongo");
|
|
92
91
|
}
|
|
93
92
|
else {
|
|
@@ -103,8 +102,8 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
103
102
|
let intentsMachine;
|
|
104
103
|
let backupMachine;
|
|
105
104
|
if (!staticBots) {
|
|
106
|
-
intentsMachine = IntentsMachineFactory.getMachine(bot, botId, projectId
|
|
107
|
-
backupMachine = IntentsMachineFactory.getBackupMachine(bot, botId, projectId
|
|
105
|
+
intentsMachine = IntentsMachineFactory.getMachine(bot, botId, projectId);
|
|
106
|
+
backupMachine = IntentsMachineFactory.getBackupMachine(bot, botId, projectId);
|
|
108
107
|
winston.debug("(tybotRoute) Created backupMachine:", backupMachine)
|
|
109
108
|
}
|
|
110
109
|
else {
|
|
@@ -124,8 +123,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
124
123
|
requestId: requestId,
|
|
125
124
|
projectId: projectId,
|
|
126
125
|
MAX_STEPS: MAX_STEPS,
|
|
127
|
-
MAX_EXECUTION_TIME: MAX_EXECUTION_TIME
|
|
128
|
-
log: log
|
|
126
|
+
MAX_EXECUTION_TIME: MAX_EXECUTION_TIME
|
|
129
127
|
});
|
|
130
128
|
winston.verbose("(tybotRoute) Message text: " + message.text)
|
|
131
129
|
|
|
@@ -162,7 +160,6 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
162
160
|
API_ENDPOINT: API_ENDPOINT,
|
|
163
161
|
TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
164
162
|
token: token,
|
|
165
|
-
log: log,
|
|
166
163
|
// HELP_CENTER_API_ENDPOINT: process.env.HELP_CENTER_API_ENDPOINT,
|
|
167
164
|
cache: tdcache
|
|
168
165
|
}
|
|
@@ -187,8 +184,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
187
184
|
reply.attributes.fillParams = true;
|
|
188
185
|
|
|
189
186
|
const apiext = new ExtApi({
|
|
190
|
-
TILEBOT_ENDPOINT: TILEBOT_ENDPOINT
|
|
191
|
-
log: false
|
|
187
|
+
TILEBOT_ENDPOINT: TILEBOT_ENDPOINT
|
|
192
188
|
});
|
|
193
189
|
apiext.sendSupportMessageExt(reply, projectId, requestId, token, () => {
|
|
194
190
|
winston.verbose("(tybotRoute) sendSupportMessageExt reply sent: ", reply)
|
|
@@ -215,8 +211,7 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
|
|
|
215
211
|
projectId: projectId,
|
|
216
212
|
token: token,
|
|
217
213
|
APIURL: API_ENDPOINT,
|
|
218
|
-
APIKEY: "___"
|
|
219
|
-
log: false
|
|
214
|
+
APIKEY: "___"
|
|
220
215
|
});
|
|
221
216
|
|
|
222
217
|
let request;
|
|
@@ -242,10 +237,10 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
|
|
|
242
237
|
winston.debug("(tybotRoute) API_ENDPOINT: " + API_ENDPOINT);
|
|
243
238
|
winston.debug("(tybotRoute) request: " + TILEBOT_ENDPOINT);
|
|
244
239
|
|
|
245
|
-
let directivesPlug = new DirectivesChatbotPlug({supportRequest: request, API_ENDPOINT: API_ENDPOINT, TILEBOT_ENDPOINT: TILEBOT_ENDPOINT, token: token,
|
|
240
|
+
let directivesPlug = new DirectivesChatbotPlug({supportRequest: request, API_ENDPOINT: API_ENDPOINT, TILEBOT_ENDPOINT: TILEBOT_ENDPOINT, token: token, HELP_CENTER_API_ENDPOINT: process.env.HELP_CENTER_API_ENDPOINT, cache: tdcache});
|
|
246
241
|
|
|
247
242
|
const original_answer_text = answer.text;
|
|
248
|
-
const bot_answer = await ExtUtil.execPipelineExt(request, answer, directivesPlug, tdcache
|
|
243
|
+
const bot_answer = await ExtUtil.execPipelineExt(request, answer, directivesPlug, tdcache);
|
|
249
244
|
winston.debug("(tybotRoute) bot_answer: ", bot_answer);
|
|
250
245
|
|
|
251
246
|
if (bot_answer) {
|
|
@@ -368,8 +363,7 @@ router.post('/echobot', (req, res) => {
|
|
|
368
363
|
projectId: projectId,
|
|
369
364
|
token: token,
|
|
370
365
|
APIURL: API_ENDPOINT,
|
|
371
|
-
APIKEY: "___"
|
|
372
|
-
log: false
|
|
366
|
+
APIKEY: "___"
|
|
373
367
|
});
|
|
374
368
|
|
|
375
369
|
// instantly reply "success" to TILEDESK
|
|
@@ -503,13 +497,7 @@ async function startApp(settings, completionCallback) {
|
|
|
503
497
|
});
|
|
504
498
|
}
|
|
505
499
|
|
|
506
|
-
|
|
507
|
-
log = false;
|
|
508
|
-
}
|
|
509
|
-
else {
|
|
510
|
-
log = true;
|
|
511
|
-
}
|
|
512
|
-
winston.info("(Tilebot) Log: " + log);
|
|
500
|
+
winston.info("(Tilebot) Log Level: " + process.env.LOG_LEVEL);
|
|
513
501
|
|
|
514
502
|
if (process.env.CHATBOT_MAX_STEPS) {
|
|
515
503
|
MAX_STEPS = Number(process.env.CHATBOT_MAX_STEPS);
|
|
@@ -588,7 +576,7 @@ async function checkRequest(request_id, id_project) {
|
|
|
588
576
|
// WARNING! Move this function in models/TiledeskChatbotUtil.js
|
|
589
577
|
}
|
|
590
578
|
|
|
591
|
-
function myrequest(options, callback
|
|
579
|
+
function myrequest(options, callback) {
|
|
592
580
|
winston.verbose("(tybotRoute) myrequest API URL:" + options.url);
|
|
593
581
|
winston.debug("(tybotRoute) myrequest Options:", options);
|
|
594
582
|
|
package/package.json
CHANGED
package/services/AIService.js
CHANGED
|
@@ -60,6 +60,7 @@ const { DirConnectBlock } = require('./directives/DirConnectBlock');
|
|
|
60
60
|
|
|
61
61
|
const winston = require('../utils/winston');
|
|
62
62
|
const { DirFlowLog } = require('./directives/DirFlowLog');
|
|
63
|
+
const { DirAddKbContent } = require('./directives/DirAddKbContent');
|
|
63
64
|
|
|
64
65
|
class DirectivesChatbotPlug {
|
|
65
66
|
|
|
@@ -74,7 +75,6 @@ class DirectivesChatbotPlug {
|
|
|
74
75
|
this.API_ENDPOINT = config.API_ENDPOINT;
|
|
75
76
|
this.TILEBOT_ENDPOINT = config.TILEBOT_ENDPOINT;
|
|
76
77
|
this.token = config.token;
|
|
77
|
-
this.log = config.log;
|
|
78
78
|
this.HELP_CENTER_API_ENDPOINT = config.HELP_CENTER_API_ENDPOINT;
|
|
79
79
|
this.tdcache = config.cache;
|
|
80
80
|
this.directives = config.directives;
|
|
@@ -143,8 +143,7 @@ class DirectivesChatbotPlug {
|
|
|
143
143
|
projectId: projectId,
|
|
144
144
|
token: token,
|
|
145
145
|
APIURL: API_ENDPOINT,
|
|
146
|
-
APIKEY: "___"
|
|
147
|
-
log: this.log
|
|
146
|
+
APIKEY: "___"
|
|
148
147
|
});
|
|
149
148
|
}
|
|
150
149
|
catch(err) {
|
|
@@ -163,8 +162,7 @@ class DirectivesChatbotPlug {
|
|
|
163
162
|
TILEBOT_ENDPOINT: TILEBOT_ENDPOINT,
|
|
164
163
|
departmentId: depId,
|
|
165
164
|
tdcache: tdcache,
|
|
166
|
-
HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT
|
|
167
|
-
log: this.log
|
|
165
|
+
HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT
|
|
168
166
|
}
|
|
169
167
|
winston.debug("(DirectivesChatbotPlug) this.context.departmentId: " + this.context.departmentId);
|
|
170
168
|
|
|
@@ -178,9 +176,7 @@ class DirectivesChatbotPlug {
|
|
|
178
176
|
|
|
179
177
|
async nextDirective(directives) {
|
|
180
178
|
winston.debug("(DirectivesChatbotPlug) ....nextDirective() checkStep()");
|
|
181
|
-
const go_on = await TiledeskChatbot.checkStep(
|
|
182
|
-
this.context.tdcache, this.context.requestId, this.chatbot?.MAX_STEPS, this.chatbot?.MAX_EXECUTION_TIME, this.log
|
|
183
|
-
);
|
|
179
|
+
const go_on = await TiledeskChatbot.checkStep(this.context.tdcache, this.context.requestId, this.chatbot?.MAX_STEPS, this.chatbot?.MAX_EXECUTION_TIME);
|
|
184
180
|
|
|
185
181
|
if (go_on.error) {
|
|
186
182
|
winston.debug("(DirectivesChatbotPlug) go_on == false! nextDirective() Stopped!");
|
|
@@ -566,6 +562,12 @@ class DirectivesChatbotPlug {
|
|
|
566
562
|
}
|
|
567
563
|
});
|
|
568
564
|
}
|
|
565
|
+
else if (directive_name === Directives.ADD_KB_CONTENT) {
|
|
566
|
+
new DirAddKbContent(context).execute(directive, async () => {
|
|
567
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
568
|
+
this.process(next_dir);
|
|
569
|
+
});
|
|
570
|
+
}
|
|
569
571
|
else if (directive_name === Directives.GPT_TASK) {
|
|
570
572
|
new DirGptTask(context).execute(directive, async (stop) => {
|
|
571
573
|
if (stop == true) {
|
|
@@ -740,8 +742,7 @@ class DirectivesChatbotPlug {
|
|
|
740
742
|
projectId: projectId,
|
|
741
743
|
token: token,
|
|
742
744
|
APIURL: API_ENDPOINT,
|
|
743
|
-
APIKEY: "___"
|
|
744
|
-
log: false
|
|
745
|
+
APIKEY: "___"
|
|
745
746
|
});
|
|
746
747
|
let i = -1;
|
|
747
748
|
winston.debug("(DirectivesChatbotPlug) processing Inline directives: ", directives);
|
|
@@ -3,11 +3,10 @@ const winston = require('../utils/winston');
|
|
|
3
3
|
|
|
4
4
|
class WebhookChatbotPlug {
|
|
5
5
|
|
|
6
|
-
constructor(supportRequest, webhookurl, token
|
|
6
|
+
constructor(supportRequest, webhookurl, token) {
|
|
7
7
|
this.supportRequest = supportRequest;
|
|
8
8
|
this.webhookurl = webhookurl;
|
|
9
9
|
this.token = token;
|
|
10
|
-
this.log = log;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
exec(pipeline) {
|
|
@@ -101,19 +100,18 @@ class WebhookChatbotPlug {
|
|
|
101
100
|
callback(null, res.data);
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
|
-
}
|
|
105
|
-
);
|
|
103
|
+
});
|
|
106
104
|
}
|
|
107
105
|
|
|
108
106
|
// ************************************************
|
|
109
107
|
// ****************** HTTP REQUEST ****************
|
|
110
108
|
// ************************************************
|
|
111
109
|
|
|
112
|
-
static myrequest(options, callback
|
|
113
|
-
|
|
110
|
+
static myrequest(options, callback) {
|
|
111
|
+
|
|
114
112
|
winston.debug("(WebhookChatbotPlug) myrequest API URL:" + options.url);
|
|
115
113
|
winston.debug("(WebhookChatbotPlug) myrequest Options:", options);
|
|
116
|
-
|
|
114
|
+
|
|
117
115
|
axios(
|
|
118
116
|
{
|
|
119
117
|
url: options.url,
|
|
@@ -122,11 +120,11 @@ class WebhookChatbotPlug {
|
|
|
122
120
|
headers: options.headers
|
|
123
121
|
})
|
|
124
122
|
.then(function (res) {
|
|
125
|
-
|
|
123
|
+
|
|
126
124
|
winston.debug("(WebhookChatbotPlug) myrequest Response for url:", options.url);
|
|
127
125
|
winston.debug("(WebhookChatbotPlug) myrequest Response headers:\n", res.headers);
|
|
128
126
|
winston.debug("(WebhookChatbotPlug) myrequest Response body:\n", res.data);
|
|
129
|
-
|
|
127
|
+
|
|
130
128
|
if (callback) {
|
|
131
129
|
callback(null, res);
|
|
132
130
|
}
|
|
@@ -12,8 +12,7 @@ class DirIfNotOpenHours {
|
|
|
12
12
|
projectId: context.projectId,
|
|
13
13
|
token: context.token,
|
|
14
14
|
APIURL: context.TILEDESK_APIURL,
|
|
15
|
-
APIKEY: "___"
|
|
16
|
-
log: context.log
|
|
15
|
+
APIKEY: "___"
|
|
17
16
|
});
|
|
18
17
|
// this.intentDir = config.intentDir;
|
|
19
18
|
// let context = {
|
|
@@ -22,19 +21,16 @@ class DirIfNotOpenHours {
|
|
|
22
21
|
// requestId: supportRequest,
|
|
23
22
|
// APIURL: API_URL,
|
|
24
23
|
// TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
25
|
-
// departmentId: depId
|
|
26
|
-
// log: false
|
|
24
|
+
// departmentId: depId
|
|
27
25
|
// }
|
|
28
26
|
this.intentDir = new DirIntent(
|
|
29
27
|
{
|
|
30
28
|
API_ENDPOINT: context.TILEDESK_APIURL,
|
|
31
29
|
TILEBOT_ENDPOINT: context.TILEBOT_ENDPOINT,
|
|
32
30
|
supportRequest: context.supportRequest,
|
|
33
|
-
token: context.token
|
|
34
|
-
log: context.log
|
|
31
|
+
token: context.token
|
|
35
32
|
}
|
|
36
33
|
);
|
|
37
|
-
this.log = context.log;
|
|
38
34
|
}
|
|
39
35
|
|
|
40
36
|
execute(directive, callback) {
|
|
@@ -58,7 +54,6 @@ class DirIfNotOpenHours {
|
|
|
58
54
|
go(action, callback) {
|
|
59
55
|
const intentName = action.body.intentName;
|
|
60
56
|
if (!intentName) {
|
|
61
|
-
if (this.log) {console.log("Invalid intent name for If-open-hours");}
|
|
62
57
|
callback();
|
|
63
58
|
}
|
|
64
59
|
let intentDirective = {
|
|
@@ -69,13 +64,11 @@ class DirIfNotOpenHours {
|
|
|
69
64
|
}
|
|
70
65
|
}
|
|
71
66
|
this.tdclient.openNow((err, result) => {
|
|
72
|
-
if (this.log) {console.log("openNow():", result);}
|
|
73
67
|
if (err) {
|
|
74
68
|
console.error("DirIfNotOpenHours Error:", err);
|
|
75
69
|
callback();
|
|
76
70
|
}
|
|
77
71
|
else if (result && !result.isopen) {
|
|
78
|
-
if (this.log) {console.log("executing the action on 'closed'");}
|
|
79
72
|
this.intentDir.execute(intentDirective, () => {
|
|
80
73
|
callback();
|
|
81
74
|
});
|
|
@@ -12,8 +12,7 @@ class DirIfOpenHours {
|
|
|
12
12
|
projectId: context.projectId,
|
|
13
13
|
token: context.token,
|
|
14
14
|
APIURL: context.TILEDESK_APIURL,
|
|
15
|
-
APIKEY: "___"
|
|
16
|
-
log: context.log
|
|
15
|
+
APIKEY: "___"
|
|
17
16
|
});
|
|
18
17
|
// let context = {
|
|
19
18
|
// projectId: projectId,
|
|
@@ -22,7 +21,6 @@ class DirIfOpenHours {
|
|
|
22
21
|
// APIURL: API_URL,
|
|
23
22
|
// TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
|
|
24
23
|
// departmentId: depId,
|
|
25
|
-
// log: false
|
|
26
24
|
// }
|
|
27
25
|
this.intentDir = new DirIntent(
|
|
28
26
|
{
|
|
@@ -30,10 +28,8 @@ class DirIfOpenHours {
|
|
|
30
28
|
TILEBOT_ENDPOINT: context.TILEBOT_ENDPOINT,
|
|
31
29
|
supportRequest: context.supportRequest,
|
|
32
30
|
token: context.token,
|
|
33
|
-
log: context.log
|
|
34
31
|
}
|
|
35
|
-
)
|
|
36
|
-
this.log = context.log;
|
|
32
|
+
)
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
execute(directive, callback) {
|
|
@@ -56,7 +52,6 @@ class DirIfOpenHours {
|
|
|
56
52
|
go(action, callback) {
|
|
57
53
|
const intentName = action.body.intentName;
|
|
58
54
|
if (!intentName) {
|
|
59
|
-
if (this.log) {console.log("Invalid intent name for If-open-hours");}
|
|
60
55
|
callback();
|
|
61
56
|
}
|
|
62
57
|
let intentDirective = {
|
|
@@ -67,13 +62,11 @@ class DirIfOpenHours {
|
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
64
|
this.tdclient.openNow((err, result) => {
|
|
70
|
-
if (this.log) {console.log("openNow():", result);}
|
|
71
65
|
if (err) {
|
|
72
66
|
console.error("DirIfOpenHours Error:", err);
|
|
73
67
|
callback();
|
|
74
68
|
}
|
|
75
69
|
else if (result && result.isopen) {
|
|
76
|
-
if (this.log) {console.log("executing the action on 'open'");}
|
|
77
70
|
this.intentDir.execute(intentDirective, () => {
|
|
78
71
|
callback();
|
|
79
72
|
});
|