@tiledesk/tiledesk-tybot-connector 0.1.0 → 0.1.3
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 +9 -0
- package/index.js +63 -39
- package/package.json +3 -5
- package/tiledeskChatbotPlugs/CHANGELOG.md +7 -0
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +161 -38
- package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +21 -4
- package/tiledeskChatbotPlugs/MessagePipeline.js +1 -1
- package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +5 -3
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +26 -4
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +67 -0
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +52 -0
- package/tiledeskChatbotPlugs/directives/DirNoAvailableAgents.js +61 -0
- package/tiledeskChatbotPlugs/directives/DirOfflineHours.js +85 -0
- package/tiledeskChatbotPlugs/directives/Directives.js +19 -0
- package/tiledeskChatbotPlugs/directives/HelpCenter.js +82 -0
- package/tiledeskChatbotPlugs/package-lock.json +273 -0
- package/tiledeskChatbotPlugs/package.json +4 -3
package/CHANGELOG.md
ADDED
package/index.js
CHANGED
|
@@ -8,11 +8,12 @@ router.use(bodyParser.json({limit: '50mb'}));
|
|
|
8
8
|
router.use(bodyParser.urlencoded({ extended: true , limit: '50mb'}));
|
|
9
9
|
|
|
10
10
|
// DEV
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
/*const { MessagePipeline } = require('./tiledeskChatbotPlugs/MessagePipeline');
|
|
12
|
+
const { DirectivesChatbotPlug } = require('./tiledeskChatbotPlugs/DirectivesChatbotPlug');
|
|
13
|
+
const { SplitsChatbotPlug } = require('./tiledeskChatbotPlugs/SplitsChatbotPlug');
|
|
14
|
+
const { MarkbotChatbotPlug } = require('./tiledeskChatbotPlugs/MarkbotChatbotPlug');
|
|
15
|
+
const { WebhookChatbotPlug } = require('./tiledeskChatbotPlugs/WebhookChatbotPlug');
|
|
16
|
+
*/
|
|
16
17
|
|
|
17
18
|
// PROD
|
|
18
19
|
const { MessagePipeline } = require('@tiledesk/tiledesk-chatbot-plugs/MessagePipeline');
|
|
@@ -21,21 +22,22 @@ const { SplitsChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/SplitsCh
|
|
|
21
22
|
const { MarkbotChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/MarkbotChatbotPlug');
|
|
22
23
|
const { WebhookChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/WebhookChatbotPlug');
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
let path = require("path");
|
|
26
|
+
let fs = require('fs');
|
|
26
27
|
|
|
27
28
|
const { TiledeskChatbotClient } = require('@tiledesk/tiledesk-chatbot-client');
|
|
28
29
|
const jwt = require('jsonwebtoken');
|
|
29
30
|
const { v4: uuidv4 } = require('uuid');
|
|
30
31
|
|
|
31
32
|
// THE IMPORT
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
let mongoose = require('mongoose');
|
|
34
|
+
let Faq = require('./models/faq');
|
|
35
|
+
let Faq_kb = require('./models/faq_kb');
|
|
35
36
|
let connection;
|
|
37
|
+
let APIURL = null;
|
|
36
38
|
|
|
37
39
|
router.post('/ext/:botid', async (req, res) => {
|
|
38
|
-
console.log("
|
|
40
|
+
console.log("REQUEST BODY:", JSON.stringify(req.body));
|
|
39
41
|
res.status(200).send({"success":true});
|
|
40
42
|
|
|
41
43
|
const botId = req.params.botid;
|
|
@@ -51,12 +53,14 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
51
53
|
// CREATE TOKEN
|
|
52
54
|
//var botWithSecret = await Faq_kb.findById(bot._id).select('+secret').exec();
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
let signOptions = {
|
|
55
57
|
issuer: 'https://tiledesk.com',
|
|
56
58
|
subject: 'bot',
|
|
57
59
|
audience: 'https://tiledesk.com/bots/'+bot._id,
|
|
58
60
|
jwtid: uuidv4()
|
|
59
61
|
};
|
|
62
|
+
|
|
63
|
+
// DEPRECATED, REMOVE
|
|
60
64
|
const bot_token = jwt.sign(bot.toObject(), bot.secret, signOptions);
|
|
61
65
|
console.log("bot_token:", bot_token);
|
|
62
66
|
//
|
|
@@ -88,7 +92,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
88
92
|
}
|
|
89
93
|
if (faqs && faqs.length > 0 && faqs[0].answer) { // EXACT MATCH!
|
|
90
94
|
console.log("FAQ:", faqs[0]);
|
|
91
|
-
execFaq(req, res, faqs, botId, message,
|
|
95
|
+
execFaq(req, res, faqs, botId, message, token, bot); // bot_token
|
|
92
96
|
}
|
|
93
97
|
else { // FULL TEXT
|
|
94
98
|
console.log("Go fulltext...");
|
|
@@ -112,15 +116,14 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
112
116
|
console.erro("Error:", err);
|
|
113
117
|
return console.error('Error getting fulltext objects.', err);
|
|
114
118
|
}
|
|
115
|
-
console.debug("faqs:", faqs);
|
|
116
119
|
if (faqs && faqs.length > 0 && faqs[0].answer) {
|
|
117
|
-
execFaq(req, res, faqs, botId, message,
|
|
120
|
+
execFaq(req, res, faqs, botId, message, token, bot); // bot_token
|
|
118
121
|
}
|
|
119
122
|
else {
|
|
120
123
|
// fallback
|
|
121
124
|
const fallbackIntent = await getIntentByDisplayName("defaultFallback", bot);
|
|
122
125
|
const faqs = [fallbackIntent];
|
|
123
|
-
execFaq(req, res, faqs, botId, message,
|
|
126
|
+
execFaq(req, res, faqs, botId, message, token, bot); // bot_token
|
|
124
127
|
}
|
|
125
128
|
});
|
|
126
129
|
}
|
|
@@ -138,7 +141,7 @@ async function execFaq(req, res, faqs, botId, message, token, bot) {
|
|
|
138
141
|
|
|
139
142
|
const context = {
|
|
140
143
|
payload: {
|
|
141
|
-
|
|
144
|
+
botId: botId,
|
|
142
145
|
bot: bot,
|
|
143
146
|
message: message, // USER MESSAGE (JSON)
|
|
144
147
|
intent: answerObj
|
|
@@ -157,25 +160,16 @@ async function execFaq(req, res, faqs, botId, message, token, bot) {
|
|
|
157
160
|
static_bot_answer.attributes = {}
|
|
158
161
|
}
|
|
159
162
|
static_bot_answer.attributes.directives = true;
|
|
160
|
-
static_bot_answer.attributes.splits =
|
|
163
|
+
static_bot_answer.attributes.splits = true;
|
|
161
164
|
static_bot_answer.attributes.markbot = true;
|
|
162
165
|
|
|
163
166
|
static_bot_answer.attributes.webhook = answerObj.webhook_enabled;
|
|
164
|
-
console.log("static_bot_answer.attributes", static_bot_answer.attributes)
|
|
165
167
|
|
|
166
168
|
// faq[0] => PIPELINE => bot_answer
|
|
167
|
-
|
|
168
|
-
const messagePipeline = new MessagePipeline(static_bot_answer, context);
|
|
169
|
-
const webhookurl = bot.webhook_url;
|
|
170
|
-
messagePipeline.addPlug(new WebhookChatbotPlug(message.request, webhookurl, token));
|
|
171
|
-
let directivesPlug = new DirectivesChatbotPlug(message.request, APIURL, token);
|
|
172
|
-
messagePipeline.addPlug(directivesPlug);
|
|
173
|
-
messagePipeline.addPlug(new SplitsChatbotPlug());
|
|
174
|
-
messagePipeline.addPlug(new MarkbotChatbotPlug());
|
|
175
|
-
const bot_answer = await messagePipeline.exec();
|
|
176
|
-
console.log("End pipeline, bot_answer:", JSON.stringify(bot_answer));
|
|
169
|
+
// execPipeline() was here Placeholder
|
|
177
170
|
|
|
178
|
-
|
|
171
|
+
//let attr = bot_answer.attributes;
|
|
172
|
+
let attr = static_bot_answer.attributes;
|
|
179
173
|
if (!attr) {
|
|
180
174
|
attr = {};
|
|
181
175
|
}
|
|
@@ -199,8 +193,10 @@ async function execFaq(req, res, faqs, botId, message, token, bot) {
|
|
|
199
193
|
question_payload: question_payload,
|
|
200
194
|
others: clonedfaqs
|
|
201
195
|
}
|
|
202
|
-
console.debug("intent_info", intent_info);
|
|
196
|
+
//console.debug("intent_info", intent_info);
|
|
203
197
|
attr.intent_info = intent_info;
|
|
198
|
+
let directivesPlug = new DirectivesChatbotPlug(message.request, APIURL, token);
|
|
199
|
+
const bot_answer = await execPipeline(static_bot_answer, message, bot, context, directivesPlug, token);
|
|
204
200
|
const tdclient = new TiledeskChatbotClient(
|
|
205
201
|
{
|
|
206
202
|
request: req,
|
|
@@ -216,6 +212,19 @@ async function execFaq(req, res, faqs, botId, message, token, bot) {
|
|
|
216
212
|
});
|
|
217
213
|
}
|
|
218
214
|
|
|
215
|
+
async function execPipeline(static_bot_answer, message, bot, context, directivesPlug, token) {
|
|
216
|
+
const messagePipeline = new MessagePipeline(static_bot_answer, context);
|
|
217
|
+
const webhookurl = bot.webhook_url;
|
|
218
|
+
messagePipeline.addPlug(new WebhookChatbotPlug(message.request, webhookurl, token));
|
|
219
|
+
//let directivesPlug = new DirectivesChatbotPlug(message.request, APIURL, token);
|
|
220
|
+
messagePipeline.addPlug(directivesPlug);
|
|
221
|
+
messagePipeline.addPlug(new SplitsChatbotPlug());
|
|
222
|
+
messagePipeline.addPlug(new MarkbotChatbotPlug());
|
|
223
|
+
const bot_answer = await messagePipeline.exec();
|
|
224
|
+
console.log("End pipeline, bot_answer:", JSON.stringify(bot_answer));
|
|
225
|
+
return bot_answer;
|
|
226
|
+
}
|
|
227
|
+
|
|
219
228
|
function getIntentByDisplayName(name, bot) {
|
|
220
229
|
return new Promise(function(resolve, reject) {
|
|
221
230
|
var query = { "id_project": bot.id_project, "id_faq_kb": bot._id, "intent_display_name": name};
|
|
@@ -303,6 +312,7 @@ function getIntentByDisplayName(name, bot) {
|
|
|
303
312
|
|
|
304
313
|
|
|
305
314
|
|
|
315
|
+
/*
|
|
306
316
|
function apiurl() {
|
|
307
317
|
const server = "pre";
|
|
308
318
|
//const server = "prod";
|
|
@@ -315,13 +325,14 @@ function apiurl() {
|
|
|
315
325
|
}
|
|
316
326
|
return API_URL;
|
|
317
327
|
}
|
|
328
|
+
*/
|
|
318
329
|
|
|
319
330
|
|
|
320
331
|
router.get('/', (req, res) => {
|
|
321
332
|
res.send('Hello Tybot!');
|
|
322
333
|
});
|
|
323
334
|
|
|
324
|
-
function
|
|
335
|
+
function startApp(settings, completionCallback) {
|
|
325
336
|
console.log("Starting Tybot with Settings:", settings);
|
|
326
337
|
|
|
327
338
|
if (!settings.MONGODB_URI) {
|
|
@@ -331,23 +342,36 @@ function startTybot(settings, completionCallback) {
|
|
|
331
342
|
throw new Error("settings.API_ENDPOINT is mandatory.");
|
|
332
343
|
}
|
|
333
344
|
else {
|
|
334
|
-
|
|
335
|
-
console.log("(Tybot) settings.API_ENDPOINT:",
|
|
345
|
+
APIURL = settings.API_ENDPOINT;
|
|
346
|
+
console.log("(Tybot) settings.API_ENDPOINT:", APIURL);
|
|
336
347
|
}
|
|
337
348
|
if (!settings.log) {
|
|
338
349
|
log = false;
|
|
339
350
|
}
|
|
351
|
+
/*
|
|
352
|
+
if (!process.env.MONGODB_URI) {
|
|
353
|
+
throw new Error("process.env.MONGODB_URI is mandatory.");
|
|
354
|
+
}
|
|
355
|
+
if (!process.env.API_ENDPOINT) {
|
|
356
|
+
throw new Error("settings.API_ENDPOINT is mandatory.");
|
|
357
|
+
}
|
|
358
|
+
if (!process.env.TILEBOT_LOG) {
|
|
359
|
+
log = false;
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
log = true;
|
|
363
|
+
}*/
|
|
340
364
|
|
|
341
|
-
console.log("Starting
|
|
342
|
-
console.log("(
|
|
365
|
+
console.log("Starting Tilebot connector...");
|
|
366
|
+
console.log("(Tilebot) Connecting to mongodb...");
|
|
343
367
|
|
|
344
|
-
connection = mongoose.connect(
|
|
368
|
+
connection = mongoose.connect(settings.MONGODB_URI, { "useNewUrlParser": true, "autoIndex": false }, function(err) {
|
|
345
369
|
if (err) {
|
|
346
370
|
console.error('Failed to connect to MongoDB on ' + settings.MONGODB_URI + " ", err);
|
|
347
371
|
//process.exit(1); // add => exitOnFail: true
|
|
348
372
|
}
|
|
349
373
|
else {
|
|
350
|
-
console.info("
|
|
374
|
+
console.info("Tilebot start.");
|
|
351
375
|
if (completionCallback) {
|
|
352
376
|
completionCallback();
|
|
353
377
|
}
|
|
@@ -373,4 +397,4 @@ var connection = mongoose.connect(process.env.mongoUrl, { "useNewUrlParser": tru
|
|
|
373
397
|
});
|
|
374
398
|
*/
|
|
375
399
|
|
|
376
|
-
module.exports = { router: router,
|
|
400
|
+
module.exports = { router: router, startApp: startApp};
|
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.3",
|
|
4
4
|
"description": "Tiledesk Tybot connector",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,17 +12,15 @@
|
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@tiledesk/tiledesk-chatbot-client": "^0.5.30",
|
|
15
|
-
"@tiledesk/tiledesk-chatbot-util": "^0.8.
|
|
15
|
+
"@tiledesk/tiledesk-chatbot-util": "^0.8.37",
|
|
16
16
|
"@tiledesk/tiledesk-client": "^0.8.28",
|
|
17
|
-
"@tiledesk/tiledesk-chatbot-plugs": "^0.1.
|
|
17
|
+
"@tiledesk/tiledesk-chatbot-plugs": "^0.1.7",
|
|
18
18
|
"axios": "^0.27.2",
|
|
19
19
|
"body-parser": "^1.19.0",
|
|
20
20
|
"express": "^4.17.1",
|
|
21
21
|
"jsonwebtoken": "^8.5.1",
|
|
22
22
|
"mongoose": "^6.3.5",
|
|
23
23
|
"nanoid": "^3.1.25",
|
|
24
|
-
"request": "^2.88.2",
|
|
25
|
-
"uuid": "^3.3.3",
|
|
26
24
|
"cors": "^2.8.5"
|
|
27
25
|
}
|
|
28
26
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Tiledesk Plugs
|
|
2
|
+
|
|
3
|
+
### 0.1.7 added \_tdDeflectToHelpCenter
|
|
4
|
+
|
|
5
|
+
### 0.1.6 bugfix
|
|
6
|
+
|
|
7
|
+
### 0.1.5 updated MarckbotPlugs.js & DirectivesPlug.js coming from RASA. Now Markbot supports native buttons and images already available in the message. Original Buttons are preserved if found. Original image is preserved if found.
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
const { TiledeskChatbotUtil } = require('@tiledesk/tiledesk-chatbot-util');
|
|
2
2
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
3
|
+
const { DirDeflectToHelpCenter } = require('./directives/DirDeflectToHelpCenter');
|
|
4
|
+
const { DirOfflineHours } = require('./directives/DirOfflineHours');
|
|
5
|
+
const { DirMoveToAgent } = require('./directives/DirMoveToAgent');
|
|
6
|
+
const { Directives } = require('./directives/Directives');
|
|
3
7
|
|
|
4
8
|
class DirectivesChatbotPlug {
|
|
5
|
-
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
11
|
* @example
|
|
8
12
|
* const { DirectivesChatbotPlug } = require('./DirectivesChatbotPlug');
|
|
@@ -17,35 +21,32 @@ class DirectivesChatbotPlug {
|
|
|
17
21
|
|
|
18
22
|
exec(pipeline) {
|
|
19
23
|
let message = pipeline.message;
|
|
20
|
-
if (message.attributes && message.attributes.directives
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
if (message.attributes && (message.attributes.directives == undefined || message.attributes.directives == false)) { // defaults to disabled
|
|
25
|
+
pipeline.nextplug();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const message_text = message.text;
|
|
29
|
+
console.log("processing message:", message_text);
|
|
30
|
+
let parsed_result = TiledeskChatbotUtil.parseDirectives(message_text);
|
|
31
|
+
console.log("Message directives:", parsed_result);
|
|
32
|
+
console.log("Message text ripped from directives:", parsed_result.text);
|
|
33
|
+
if (parsed_result && parsed_result.directives && parsed_result.directives.length > 0) {
|
|
34
|
+
// do not process more intents. Process directives and return
|
|
35
|
+
const text = parsed_result.text;
|
|
36
|
+
message.text = text;
|
|
37
|
+
this.directives = parsed_result.directives;
|
|
38
|
+
this.processInlineDirectives(pipeline, () => {
|
|
39
|
+
console.log("End process directives.");
|
|
36
40
|
pipeline.nextplug();
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
41
|
+
});
|
|
42
|
+
//pipeline.nextplug();
|
|
43
|
+
/*this.processDirectives( () => {
|
|
44
|
+
console.log("End process directives.");
|
|
43
45
|
pipeline.nextplug();
|
|
44
|
-
}
|
|
46
|
+
});*/
|
|
45
47
|
}
|
|
46
48
|
else {
|
|
47
49
|
pipeline.nextplug();
|
|
48
|
-
return;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
}
|
|
@@ -87,12 +88,13 @@ JUST WAIT A MOMENT
|
|
|
87
88
|
const directives = this.directives;
|
|
88
89
|
if (!directives || directives.length === 0) {
|
|
89
90
|
console.log("No directives to process.");
|
|
91
|
+
theend();
|
|
90
92
|
return;
|
|
91
93
|
}
|
|
92
94
|
const supportRequest = this.supportRequest;
|
|
93
95
|
const token = this.token;
|
|
94
96
|
const API_URL = this.API_URL;
|
|
95
|
-
|
|
97
|
+
|
|
96
98
|
const requestId = supportRequest.request_id
|
|
97
99
|
const depId = supportRequest.department._id;
|
|
98
100
|
const projectId = supportRequest.id_project;
|
|
@@ -118,7 +120,7 @@ JUST WAIT A MOMENT
|
|
|
118
120
|
if (directive == null) {
|
|
119
121
|
theend();
|
|
120
122
|
}
|
|
121
|
-
else if (directive_name ===
|
|
123
|
+
else if (directive_name === Directives.DEPARTMENT) {
|
|
122
124
|
let dep_name = "default department";
|
|
123
125
|
if (directive.parameter) {
|
|
124
126
|
dep_name = directive.parameter;
|
|
@@ -129,10 +131,12 @@ JUST WAIT A MOMENT
|
|
|
129
131
|
process(nextDirective());
|
|
130
132
|
});
|
|
131
133
|
}
|
|
132
|
-
else if (directive_name ===
|
|
134
|
+
else if (directive_name === Directives.HMESSAGE) {
|
|
135
|
+
//tdclient.log = true;
|
|
133
136
|
if (directive.parameter) {
|
|
134
137
|
let text = directive.parameter.trim();
|
|
135
138
|
let message = {
|
|
139
|
+
sender: "system22", // bot doesn't reply to himself
|
|
136
140
|
text: text,
|
|
137
141
|
attributes: {
|
|
138
142
|
subtype: "info"
|
|
@@ -144,7 +148,7 @@ JUST WAIT A MOMENT
|
|
|
144
148
|
});
|
|
145
149
|
}
|
|
146
150
|
}
|
|
147
|
-
else if (directive_name ===
|
|
151
|
+
else if (directive_name === Directives.MESSAGE) {
|
|
148
152
|
if (directive.parameter) {
|
|
149
153
|
let text = directive.parameter.trim();
|
|
150
154
|
let message = {text: text};
|
|
@@ -162,12 +166,14 @@ JUST WAIT A MOMENT
|
|
|
162
166
|
});
|
|
163
167
|
}
|
|
164
168
|
}
|
|
165
|
-
else if (directive_name ===
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
else if (directive_name === Directives.AGENT) {
|
|
170
|
+
tdclient.log = false;
|
|
171
|
+
const agentDir = new DirMoveToAgent(tdclient);
|
|
172
|
+
directive.whenOnlineOnly = false;
|
|
173
|
+
agentDir.execute(directive, requestId, depId, () => {
|
|
174
|
+
process(nextDirective());
|
|
175
|
+
});
|
|
176
|
+
/*tdclient.agent(requestId, depId, (err) => {
|
|
171
177
|
if (err) {
|
|
172
178
|
console.error("Error moving to agent:", err);
|
|
173
179
|
}
|
|
@@ -175,9 +181,17 @@ JUST WAIT A MOMENT
|
|
|
175
181
|
console.log("Successfully moved to agent");
|
|
176
182
|
}
|
|
177
183
|
process(nextDirective());
|
|
184
|
+
});*/
|
|
185
|
+
}
|
|
186
|
+
else if (directive_name === Directives.WHEN_ONLINE_MOVE_TO_AGENT) {
|
|
187
|
+
tdclient.log = false;
|
|
188
|
+
const agentDir = new DirMoveToAgent(tdclient);
|
|
189
|
+
directive.whenOnlineOnly = true;
|
|
190
|
+
agentDir.execute(directive, requestId, depId, () => {
|
|
191
|
+
process(nextDirective());
|
|
178
192
|
});
|
|
179
193
|
}
|
|
180
|
-
else if (directive_name ===
|
|
194
|
+
else if (directive_name === Directives.REMOVE_CURRENT_BOT) {
|
|
181
195
|
console.log("assign to request:", requestId);
|
|
182
196
|
console.log("assign to dep:", depId);
|
|
183
197
|
console.log("assign to dep name:", request.department.name);
|
|
@@ -192,8 +206,41 @@ JUST WAIT A MOMENT
|
|
|
192
206
|
process(nextDirective());
|
|
193
207
|
});
|
|
194
208
|
}
|
|
209
|
+
else if (directive_name === Directives.CHANGE_BOT) {
|
|
210
|
+
console.log("changebot, requestId:", requestId);
|
|
211
|
+
if (directive.parameter) {
|
|
212
|
+
let botId = directive.parameter.trim();
|
|
213
|
+
tdclient.log = true;
|
|
214
|
+
tdclient.changeBot(requestId, botId, (err) => {
|
|
215
|
+
if (err) {
|
|
216
|
+
console.error("Error removeCurrentBot():", err);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
console.log("Successfully removeCurrentBot()");
|
|
220
|
+
}
|
|
221
|
+
process(nextDirective());
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
console.error("changeBot no parameter error");
|
|
226
|
+
process(nextDirective());
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else if (directive_name === Directives.WAIT) {
|
|
230
|
+
let millis = 1000;
|
|
231
|
+
if (directive.parameter) {
|
|
232
|
+
const _millis = parseInt(directive.parameter.trim());
|
|
233
|
+
if (!Number.isNaN(millis)) {
|
|
234
|
+
millis = _millis;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
console.log("Wait millis:", millis);
|
|
238
|
+
setTimeout( () => {
|
|
239
|
+
process(nextDirective());
|
|
240
|
+
}, millis);
|
|
241
|
+
}
|
|
195
242
|
else {
|
|
196
|
-
console.log("
|
|
243
|
+
console.log("Unhandled Post-message Directive:", directive_name);
|
|
197
244
|
process(nextDirective());
|
|
198
245
|
}
|
|
199
246
|
}
|
|
@@ -201,7 +248,6 @@ JUST WAIT A MOMENT
|
|
|
201
248
|
|
|
202
249
|
function nextDirective() {
|
|
203
250
|
i += 1;
|
|
204
|
-
console.log("i:", i);
|
|
205
251
|
if (i < directives.length) {
|
|
206
252
|
let nextd = directives[i];
|
|
207
253
|
console.log("next:", nextd);
|
|
@@ -212,6 +258,83 @@ JUST WAIT A MOMENT
|
|
|
212
258
|
}
|
|
213
259
|
}
|
|
214
260
|
}
|
|
261
|
+
|
|
262
|
+
processInlineDirectives(pipeline, theend) {
|
|
263
|
+
const directives = this.directives;
|
|
264
|
+
if (!directives || directives.length === 0) {
|
|
265
|
+
console.log("No directives to process.");
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const supportRequest = this.supportRequest;
|
|
269
|
+
const token = this.token;
|
|
270
|
+
const API_URL = this.API_URL;
|
|
271
|
+
|
|
272
|
+
const requestId = supportRequest.request_id
|
|
273
|
+
const depId = supportRequest.department._id;
|
|
274
|
+
const projectId = supportRequest.id_project;
|
|
275
|
+
const tdclient = new TiledeskClient({
|
|
276
|
+
projectId: projectId,
|
|
277
|
+
token: token,
|
|
278
|
+
APIURL: API_URL,
|
|
279
|
+
APIKEY: "___",
|
|
280
|
+
log:false
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
let i = -1;
|
|
284
|
+
console.log("processing Inline directives:", directives);
|
|
285
|
+
function process(directive) {
|
|
286
|
+
if (directive) {
|
|
287
|
+
console.log("directive:", directive);
|
|
288
|
+
console.log("directive.name:", directive.name);
|
|
289
|
+
}
|
|
290
|
+
let directive_name = null;
|
|
291
|
+
if (directive && directive.name) {
|
|
292
|
+
directive_name = directive.name.toLowerCase();
|
|
293
|
+
}
|
|
294
|
+
if (directive == null) {
|
|
295
|
+
theend();
|
|
296
|
+
}
|
|
297
|
+
else if (directive_name === Directives.WHEN_OFFLINE_HOURS) {
|
|
298
|
+
tdclient.log = false;
|
|
299
|
+
const offlineHoursDir = new DirOfflineHours(tdclient);
|
|
300
|
+
offlineHoursDir.execute(directive, pipeline, () => {
|
|
301
|
+
process(nextDirective());
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
else if (directive_name === Directives.WHEN_OFFLINE_HOURS_REPLACE_MESSAGE) {
|
|
305
|
+
directive.replaceMessage = true;
|
|
306
|
+
tdclient.log = false;
|
|
307
|
+
const offlineHoursDir = new DirOfflineHours(tdclient);
|
|
308
|
+
offlineHoursDir.execute(directive, pipeline, () => {
|
|
309
|
+
process(nextDirective());
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
else if (directive_name === Directives.DEFLECT_TO_HELP_CENTER) {
|
|
313
|
+
console.log("deflecttohelpcenter dir");
|
|
314
|
+
const helpcenter_api_endpoint = "https://tiledesk-cms-server-prod.herokuapp.com";
|
|
315
|
+
const helpDir = new DirDeflectToHelpCenter(helpcenter_api_endpoint, projectId);
|
|
316
|
+
helpDir.execute(directive, pipeline, 3, () => {
|
|
317
|
+
process(nextDirective());
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
console.log("Unhandled Inline Directive:", directive_name);
|
|
322
|
+
process(nextDirective());
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
process(nextDirective());
|
|
326
|
+
|
|
327
|
+
function nextDirective() {
|
|
328
|
+
i += 1;
|
|
329
|
+
if (i < directives.length) {
|
|
330
|
+
let nextd = directives[i];
|
|
331
|
+
return nextd;
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
215
338
|
|
|
216
339
|
}
|
|
217
340
|
|
|
@@ -14,8 +14,8 @@ class MarkbotChatbotPlug {
|
|
|
14
14
|
|
|
15
15
|
exec(pipeline) {
|
|
16
16
|
let message = pipeline.message;
|
|
17
|
-
console.log("markbot, message.attributes", message.attributes)
|
|
18
|
-
if (message.attributes && message.attributes.markbot
|
|
17
|
+
//console.log("markbot, message.attributes", message.attributes)
|
|
18
|
+
if (message.attributes && (message.attributes.markbot == undefined || message.attributes.markbot == false)) { // defaults to disabled
|
|
19
19
|
console.log("markbot disabled")
|
|
20
20
|
pipeline.nextplug();
|
|
21
21
|
return;
|
|
@@ -37,9 +37,16 @@ class MarkbotChatbotPlug {
|
|
|
37
37
|
console.log("parsed", JSON.stringify(parsed_reply));
|
|
38
38
|
if (parsed_reply) {
|
|
39
39
|
message.text = parsed_reply.message.text;
|
|
40
|
-
message.type
|
|
41
|
-
|
|
40
|
+
if (!message.type || message.type === "text") {
|
|
41
|
+
// if message type != text the message already provided his own type (i.e. "image"). Only messages of type == text can be modified by markbot to change their type.
|
|
42
|
+
message.type = parsed_reply.message.type;
|
|
43
|
+
}
|
|
44
|
+
if (!message.metadata) {
|
|
45
|
+
// if already present, do not modify metadata
|
|
46
|
+
message.metadata = parsed_reply.message.metadata;
|
|
47
|
+
}
|
|
42
48
|
console.log("parsed_reply.message.attributes", parsed_reply.message.attributes);
|
|
49
|
+
//this.mergeCurrentMessageButtons(message, parsed_reply);
|
|
43
50
|
if (parsed_reply.message.attributes) {
|
|
44
51
|
for(const [key, value] of Object.entries(parsed_reply.message.attributes)) {
|
|
45
52
|
console.log("key:", key)
|
|
@@ -69,6 +76,16 @@ class MarkbotChatbotPlug {
|
|
|
69
76
|
pipeline.nextplug(pipeline);
|
|
70
77
|
|
|
71
78
|
}
|
|
79
|
+
|
|
80
|
+
/*mergeCurrentMessageButtons(message, parsed_reply) {
|
|
81
|
+
if (message && message.attributes && message.attributes.attachment && message.attributes.attachment.buttons) {
|
|
82
|
+
if (parsed_reply && parsed_reply.attributes && parsed_reply.attributes.attachment && parsed_reply.attributes.attachment.buttons) {
|
|
83
|
+
message.attributes.attachment.buttons.forEach(b => {
|
|
84
|
+
parsed_reply.attributes.attachment.buttons.push(b);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}*/
|
|
72
89
|
|
|
73
90
|
/*
|
|
74
91
|
next(pipeline, completionCallback) {
|
|
@@ -14,8 +14,9 @@ class SplitsChatbotPlug {
|
|
|
14
14
|
|
|
15
15
|
exec(pipeline) {
|
|
16
16
|
let message = pipeline.message;
|
|
17
|
-
if (message.attributes && message.attributes.splits
|
|
18
|
-
|
|
17
|
+
if (message.attributes && (message.attributes.splits == undefined || message.attributes.splits == false)) { // defaults to disabled
|
|
18
|
+
console.log("Splits disabled.")
|
|
19
|
+
pipeline.nextplug();
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
22
|
console.log("Splitting...")
|
|
@@ -34,6 +35,7 @@ class SplitsChatbotPlug {
|
|
|
34
35
|
//next(pipeline, completionCallback);
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
/*
|
|
37
39
|
next(pipeline, completionCallback) {
|
|
38
40
|
const plug = pipeline.nextplug();
|
|
39
41
|
if (!plug) {
|
|
@@ -42,7 +44,7 @@ class SplitsChatbotPlug {
|
|
|
42
44
|
else {
|
|
43
45
|
plug.exec(pipeline);
|
|
44
46
|
}
|
|
45
|
-
}
|
|
47
|
+
}*/
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
module.exports = { SplitsChatbotPlug };
|