@tiledesk/tiledesk-server 2.3.79 → 2.3.81

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -6,7 +6,25 @@
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
8
 
9
- # 2.3.77 -> PROD v3
9
+
10
+ # 2.3.81 -> PROD v3
11
+ - Added publish method to the chatbot endpoint and fix for SubscriptionNotifier
12
+ - Added request_status and preflight body parameters to send (post) message endpoint
13
+
14
+ # 2.3.80
15
+ - Updated dep tiledesk/tiledesk-whatsapp-connector to 0.1.31
16
+
17
+ # 2.3.79
18
+ - Env fix
19
+
20
+ # 2.3.78
21
+ - Updated dep tiledesk/tiledesk-whatsapp-connector to 0.1.30
22
+ - Added FaqSchema.index({ id_project: 1, id_faq_kb: 1, intent_id: 1 }, { unique: true });
23
+ - Added filter by public and certified to the bot endpoint
24
+ - Added cache invalidation for intent edit and delete
25
+ - Added score field to the bot model
26
+
27
+ # 2.3.77
10
28
  - Updated tiledesk/tiledesk-whatsapp-connector dependency to 0.1.24
11
29
  - Added KALEYRA_API_URL environment variable
12
30
  - Now GRAPH_URL environment variable is optional
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.79",
4
+ "version": "2.3.81",
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.30",
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",
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.' });
package/routes/message.js CHANGED
@@ -169,11 +169,11 @@ async (req, res) => {
169
169
  sourcePage:req.body.sourcePage,
170
170
  language: req.body.language,
171
171
  userAgent:req.body.userAgent,
172
- status:null,
172
+ status:req.body.request_status,
173
173
  createdBy: req.user._id,
174
174
  attributes: req.body.attributes,
175
175
  subject: req.body.subject,
176
- preflight:undefined,
176
+ preflight:req.body.preflight,
177
177
  channel: req.body.channel,
178
178
  location: req.body.location,
179
179
  participants: req.body.participants,
@@ -19,10 +19,17 @@ class BotSubscriptionNotifier {
19
19
 
20
20
  notify(bot,botWithSecret, payload) {
21
21
 
22
- winston.verbose("BotSubscriptionNotifier bot", bot.toObject(), 'payload', payload );
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("&draft=true")>-1) {
28
+ url = url.substr(0,url.lastIndexOf("/")+1)+bot.id;
29
+ // url = url + "?forced_bot_id="+bot.id;
30
+ winston.verbose("BotSubscriptionNotifier it is a tilebot test page. Switch to current chabot id: "+ url);
31
+ }
32
+
26
33
  // if (url.startsWith("$ext_url")) {
27
34
  // // url = url.replace ("$res_bot_url", prendi da env)
28
35
  // }
@@ -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