@tiledesk/tiledesk-server 2.3.78 → 2.3.80
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tiledesk/tiledesk-server",
|
3
3
|
"description": "The Tiledesk server module",
|
4
|
-
"version": "2.3.
|
4
|
+
"version": "2.3.80",
|
5
5
|
"scripts": {
|
6
6
|
"start": "node ./bin/www",
|
7
7
|
"pretest": "mongodb-runner start",
|
@@ -44,7 +44,7 @@
|
|
44
44
|
"@tiledesk/tiledesk-kaleyra-proxy": "^0.1.6",
|
45
45
|
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
|
46
46
|
"@tiledesk/tiledesk-tybot-connector": "^0.1.55",
|
47
|
-
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.
|
47
|
+
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.31",
|
48
48
|
"amqplib": "^0.5.5",
|
49
49
|
"app-root-path": "^3.0.0",
|
50
50
|
"bcrypt-nodejs": "0.0.3",
|
@@ -14,13 +14,13 @@ class Listener {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
var port = process.env.CACHE_REDIS_PORT || 6379;
|
17
|
-
winston.debug("
|
17
|
+
winston.debug("Redis port: "+ port);
|
18
18
|
|
19
19
|
var host = process.env.CACHE_REDIS_HOST || "127.0.0.1"
|
20
|
-
winston.debug("
|
20
|
+
winston.debug("Redis host: "+ host);
|
21
21
|
|
22
|
-
var password = process.env.
|
23
|
-
winston.debug("
|
22
|
+
var password = process.env.CACHE_REDIS_PASSWORD;
|
23
|
+
winston.debug("Redis password: "+ password);
|
24
24
|
|
25
25
|
|
26
26
|
let graph_url = process.env.META_GRAPH_URL || config.graphUrl || "https://graph.facebook.com/v14.0/"
|
package/routes/faq_kb.js
CHANGED
@@ -212,6 +212,60 @@ router.post('/askbot', function (req, res) {
|
|
212
212
|
|
213
213
|
|
214
214
|
|
215
|
+
router.put('/:faq_kbid/publish', async (req, res) => {
|
216
|
+
|
217
|
+
let id_faq_kb = req.params.faq_kbid;
|
218
|
+
winston.debug('id_faq_kb: ' + id_faq_kb);
|
219
|
+
|
220
|
+
const api_url = process.env.API_URL || configGlobal.apiUrl;
|
221
|
+
winston.debug("fork --> base_url: " + api_url); // check if correct
|
222
|
+
|
223
|
+
let current_project_id = req.projectid;
|
224
|
+
winston.debug("current project id: " + current_project_id);
|
225
|
+
|
226
|
+
let token = req.headers.authorization;
|
227
|
+
|
228
|
+
let cs = req.app.get('chatbot_service')
|
229
|
+
|
230
|
+
try {
|
231
|
+
// fork(id_faq_kb, api_url, token, project_id)
|
232
|
+
let forked = await cs.fork(id_faq_kb, api_url, token, current_project_id);
|
233
|
+
// winston.debug("forked: ", forked)
|
234
|
+
|
235
|
+
let forkedChatBotId = forked.bot_id;
|
236
|
+
winston.debug("forkedChatBotId: "+forkedChatBotId);
|
237
|
+
|
238
|
+
|
239
|
+
let updatedForkedChabot = await Faq_kb.findByIdAndUpdate(forkedChatBotId, {trashed: true}, { new: true, upsert: true }).exec();
|
240
|
+
winston.debug("updatedForkedChabot: ",updatedForkedChabot);
|
241
|
+
botEvent.emit('faqbot.update', updatedForkedChabot);
|
242
|
+
|
243
|
+
|
244
|
+
const port = process.env.PORT || '3000';
|
245
|
+
const TILEBOT_ENDPOINT = process.env.TILEBOT_ENDPOINT || "http://localhost:" + port+ "/modules/tilebot/ext/";
|
246
|
+
winston.debug("TILEBOT_ENDPOINT: " + TILEBOT_ENDPOINT);
|
247
|
+
|
248
|
+
let updatedOriginalChabot = await Faq_kb.findByIdAndUpdate(id_faq_kb, {url:TILEBOT_ENDPOINT+forkedChatBotId}, { new: true, upsert: true }).exec();
|
249
|
+
winston.debug("updatedOriginalChabot: ",updatedOriginalChabot);
|
250
|
+
|
251
|
+
botEvent.emit('faqbot.update', updatedOriginalChabot);
|
252
|
+
|
253
|
+
|
254
|
+
return res.status(200).send({ message: "Chatbot published successfully", bot_id: forkedChatBotId });
|
255
|
+
|
256
|
+
} catch(e) {
|
257
|
+
winston.error("Error Unable publish chatbot: ", e);
|
258
|
+
return res.status(500).send({ success: false, message: "Unable publish chatbot" });
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
});
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
215
269
|
router.put('/:faq_kbid', function (req, res) {
|
216
270
|
|
217
271
|
winston.debug(req.body);
|
@@ -255,7 +309,7 @@ router.put('/:faq_kbid', function (req, res) {
|
|
255
309
|
update.tags = req.body.tags;
|
256
310
|
}
|
257
311
|
|
258
|
-
|
312
|
+
|
259
313
|
Faq_kb.findByIdAndUpdate(req.params.faq_kbid, update, { new: true, upsert: true }, function (err, updatedFaq_kb) {
|
260
314
|
if (err) {
|
261
315
|
return res.status(500).send({ success: false, msg: 'Error updating object.' });
|
@@ -267,8 +321,6 @@ router.put('/:faq_kbid', function (req, res) {
|
|
267
321
|
});
|
268
322
|
|
269
323
|
|
270
|
-
|
271
|
-
|
272
324
|
router.patch('/:faq_kbid/attributes', function (req, res) {
|
273
325
|
var data = req.body;
|
274
326
|
|
@@ -320,7 +372,7 @@ router.delete('/:faq_kbid', function (req, res) {
|
|
320
372
|
|
321
373
|
winston.debug(req.body);
|
322
374
|
|
323
|
-
|
375
|
+
|
324
376
|
Faq_kb.remove({ _id: req.params.faq_kbid }, function (err, faq_kb) {
|
325
377
|
if (err) {
|
326
378
|
return res.status(500).send({ success: false, msg: 'Error deleting object.' });
|
@@ -19,10 +19,16 @@ class BotSubscriptionNotifier {
|
|
19
19
|
|
20
20
|
notify(bot,botWithSecret, payload) {
|
21
21
|
|
22
|
-
winston.verbose("BotSubscriptionNotifier bot", bot.toObject()
|
22
|
+
winston.verbose("BotSubscriptionNotifier bot", bot.toObject());
|
23
|
+
winston.debug("BotSubscriptionNotifier payload", payload );
|
23
24
|
|
24
25
|
var url = bot.url;
|
25
26
|
|
27
|
+
if (bot.type == "tilebot" && payload.request && payload.request.attributes && payload.request.attributes.sourcePage && payload.request.attributes.sourcePage.indexOf("/assets/twp/index.html")>-1) {
|
28
|
+
url = url + "?forced_bot_id="+bot.id;
|
29
|
+
winston.verbose("BotSubscriptionNotifier it is a tilebot test page. Switch to current chabot id: "+ url);
|
30
|
+
}
|
31
|
+
|
26
32
|
// if (url.startsWith("$ext_url")) {
|
27
33
|
// // url = url.replace ("$res_bot_url", prendi da env)
|
28
34
|
// }
|
@@ -8,6 +8,26 @@ class ChatbotService {
|
|
8
8
|
|
9
9
|
}
|
10
10
|
|
11
|
+
async fork(id_faq_kb, api_url, token, project_id) {
|
12
|
+
winston.debug("[CHATBOT SERVICE] fork");
|
13
|
+
|
14
|
+
return await axios({
|
15
|
+
url: api_url + '/' + project_id + '/faq_kb/fork/'+id_faq_kb+"?projectid="+project_id+"&public=false",
|
16
|
+
headers: {
|
17
|
+
'Content-Type': 'application/json',
|
18
|
+
'Authorization': token
|
19
|
+
},
|
20
|
+
// data: chatbot,
|
21
|
+
method: 'POST'
|
22
|
+
}).then((resbody) => {
|
23
|
+
winston.debug("(CHATBOT SERVICE) fork resbody: ", resbody.data);
|
24
|
+
return resbody.data;
|
25
|
+
}).catch((err) => {
|
26
|
+
winston.error("(CHATBOT SERVICE) fork error " + err);
|
27
|
+
return err;
|
28
|
+
})
|
29
|
+
|
30
|
+
}
|
11
31
|
|
12
32
|
async getBotById(id_faq_kb, published, api_url, chatbot_templates_api_url, token, project_id) {
|
13
33
|
|