@tiledesk/tiledesk-server 2.2.39 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/LICENSE +14 -657
  3. package/README.md +17 -3
  4. package/app.js +14 -2
  5. package/channels/chat21/chat21WebHook.js +12 -1
  6. package/event/botEvent.js +1 -1
  7. package/event/subscriptionEvent.js +11 -0
  8. package/fonts/Roboto-Italic.ttf +0 -0
  9. package/fonts/Roboto-Medium.ttf +0 -0
  10. package/fonts/Roboto-MediumItalic.ttf +0 -0
  11. package/fonts/Roboto-Regular.ttf +0 -0
  12. package/middleware/passport.js +4 -1
  13. package/models/lead.js +2 -0
  14. package/models/request.js +38 -11
  15. package/models/subscriptionLog.js +34 -0
  16. package/models/tagLibrary.js +42 -0
  17. package/package.json +4 -11
  18. package/pubmodules/activities/activityArchiver.js +295 -0
  19. package/pubmodules/activities/index.js +3 -0
  20. package/pubmodules/activities/models/activity.js +88 -0
  21. package/pubmodules/activities/routes/activity.js +710 -0
  22. package/pubmodules/activities/test/activityRoute.js +85 -0
  23. package/pubmodules/analytics/analytics.js +1719 -0
  24. package/pubmodules/analytics/index.js +3 -0
  25. package/pubmodules/canned/cannedResponse.js +51 -0
  26. package/pubmodules/canned/cannedResponseRoute.js +157 -0
  27. package/pubmodules/canned/index.js +3 -0
  28. package/pubmodules/emailNotification/requestNotification.js +184 -26
  29. package/pubmodules/messageActions/messageActionsInterceptor.js +4 -2
  30. package/pubmodules/pubModulesManager.js +104 -5
  31. package/pubmodules/scheduler/tasks/closeAgentUnresponsiveRequestTask.js +3 -1
  32. package/pubmodules/scheduler/tasks/closeBotUnresponsiveRequestTask.js +3 -1
  33. package/pubmodules/trigger/default.js +271 -0
  34. package/pubmodules/trigger/event/actionEventEmitter.js +10 -0
  35. package/pubmodules/trigger/event/flowEventEmitter.js +10 -0
  36. package/pubmodules/trigger/event/triggerEventEmitter.js +10 -0
  37. package/pubmodules/trigger/index.js +3 -0
  38. package/pubmodules/trigger/models/trigger.js +149 -0
  39. package/pubmodules/trigger/rulesTrigger.js +1181 -0
  40. package/pubmodules/trigger/start.js +114 -0
  41. package/pubmodules/trigger/triggerRoute.js +150 -0
  42. package/routes/department.js +51 -0
  43. package/routes/group.js +140 -0
  44. package/routes/lead.js +24 -1
  45. package/routes/message.js +6 -3
  46. package/routes/project.js +52 -0
  47. package/routes/public-request.js +265 -2
  48. package/routes/request.js +83 -11
  49. package/routes/subscription.js +140 -0
  50. package/routes/tag.js +138 -0
  51. package/routes/user-request.js +3 -2
  52. package/routes/widget.js +16 -1
  53. package/routes/widgetLoader.js +31 -0
  54. package/services/emailService.js +189 -11
  55. package/services/faqService.js +1 -1
  56. package/services/leadService.js +2 -0
  57. package/services/modulesManager.js +7 -188
  58. package/services/requestService.js +364 -6
  59. package/services/subscriptionNotifier.js +485 -0
  60. package/template/email/assignedEmailMessage.html +1 -1
  61. package/template/email/assignedRequest.html +1 -1
  62. package/template/email/newMessage.html +1 -1
  63. package/template/email/newMessageFollower.html +236 -0
  64. package/template/email/passwordChanged.html +1 -1
  65. package/template/email/pooledEmailMessage.html +1 -1
  66. package/template/email/pooledRequest.html +1 -1
  67. package/template/email/resetPassword.html +2 -2
  68. package/template/email/ticket.html +1 -1
  69. package/test/messageRoute.js +69 -0
  70. package/test/requestService.js +3 -1
  71. package/views/messages.jade +2 -2
package/README.md CHANGED
@@ -9,11 +9,23 @@
9
9
 
10
10
  # Introduction
11
11
 
12
- Tiledesk-server is the server engine of Tiledesk. Tiledesk is an Open Source Live Chat platform with integrated ChatBot written in NodeJs and Express. Build your own customer support with a multi-channel platform for Web, Android and iOS. More info here https://www.tiledesk.com.
12
+ Tiledesk-server is the server engine of Tiledesk. Tiledesk is an Open Source Live Chat platform with integrated Chatbots written in NodeJs and Express. Build your own customer support with a multi-channel platform for Web, Android and iOS.
13
13
 
14
- You can find more info here: https://developer.tiledesk.com
14
+ Designed to be open source since the beginning, we actively worked on it to create a totally new, first class customer service platform based on instant messaging.
15
15
 
16
- # Prerequisites
16
+ What is Tiledesk today? It became the open source “conversational app development” platform that everyone needs 😌
17
+
18
+ You can use Tiledesk to increase sales for your website or for post-sales customer service. Every conversation can be automated using our first class native chatbot technology.
19
+ You can also connect your own applications using our APIs or Webhooks.
20
+ Moreover you can deploy entire visual applications inside a conversation. And your applications can converse with your chatbots or your end-users! We know this is cool 😎
21
+
22
+ Tiledesk is multichannel in a totally new way. You can write your chatbot scripts with images, buttons and other cool elements that your channels support. But you will configureyour chatbot replies only once. They will run on every channel, auto-adapting the responses to the target channel whatever it is, Whatsapp, Facebook Messenger, Telegram etc.
23
+
24
+ More info on Tiledesk website: https://www.tiledesk.com.
25
+
26
+ You can find technical documentation here: https://developer.tiledesk.com
27
+
28
+ # Prerequisites for Installation
17
29
 
18
30
  * [Nodejs](https://www.npmjs.com/) and npm installed. Suggested versions are NodeJS 12.20.2 and NPM 6.14.11
19
31
  * [MongoDb](https://www.mongodb.com) installed
@@ -80,6 +92,8 @@ Deploy with button:
80
92
 
81
93
  [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/Tiledesk/tiledesk-server)
82
94
 
95
+ # Community? Questions? Support ?
96
+ If you need help or just want to hang out, come, say hi on our [<img width="15" alt="Tiledesk discord" src="https://seeklogo.com/images/D/discord-color-logo-E5E6DFEF80-seeklogo.com.png"> Discord](https://discord.gg/nERZEZ7SmG) server.
83
97
 
84
98
  # REST API
85
99
 
package/app.js CHANGED
@@ -87,6 +87,9 @@ var lead = require('./routes/lead');
87
87
  var message = require('./routes/message');
88
88
  var messagesRootRoute = require('./routes/messagesRoot');
89
89
  var department = require('./routes/department');
90
+ var group = require('./routes/group');
91
+ var resthook = require('./routes/subscription');
92
+ var tag = require('./routes/tag');
90
93
  var faq = require('./routes/faq');
91
94
  var faq_kb = require('./routes/faq_kb');
92
95
  var project = require('./routes/project');
@@ -124,6 +127,9 @@ var RouterLogger = require('./models/routerLogger');
124
127
 
125
128
  require('./services/mongoose-cache-fn')(mongoose);
126
129
 
130
+ var subscriptionNotifier = require('./services/subscriptionNotifier');
131
+ subscriptionNotifier.start();
132
+
127
133
  var botSubscriptionNotifier = require('./services/BotSubscriptionNotifier');
128
134
  botSubscriptionNotifier.start();
129
135
 
@@ -169,8 +175,6 @@ if (process.env.CREATE_INITIAL_DATA !== "false") {
169
175
 
170
176
 
171
177
 
172
-
173
-
174
178
  var app = express();
175
179
 
176
180
 
@@ -398,6 +402,8 @@ app.use('/auth', auth);
398
402
  app.use('/testauth', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], authtest);
399
403
 
400
404
  app.use('/widgets', widgetsLoader);
405
+ app.use('/w', widgetsLoader);
406
+
401
407
  app.use('/images', images);
402
408
  app.use('/files', files);
403
409
  app.use('/urls', urls);
@@ -441,8 +447,14 @@ app.use('/:projectid/departments', department);
441
447
 
442
448
 
443
449
 
450
+
451
+
444
452
  channelManager.useUnderProjects(app);
445
453
 
454
+ app.use('/:projectid/groups', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('admin')], group);
455
+ app.use('/:projectid/tags', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('agent')], tag);
456
+ app.use('/:projectid/subscriptions', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('admin')], resthook);
457
+
446
458
  //deprecated
447
459
  app.use('/:projectid/faq', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('agent')], faq);
448
460
  app.use('/:projectid/intents', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('agent')], faq);
@@ -201,12 +201,21 @@ router.post('/', function (req, res) {
201
201
  return winston.error("project_user not found with query: ", queryProjectUser);
202
202
  }
203
203
 
204
+
205
+ // var auto_close;
206
+
207
+ // // qui projecy nn c'è devi leggerlo
208
+ // if (req.project.attributes.auto_close === false) {
209
+ // auto_close = 10;
210
+ // }
211
+
204
212
 
205
213
  var new_request = {
206
214
  request_id: message.recipient, project_user_id:project_user_id, lead_id:createdLead._id, id_project:projectid, first_text:message.text,
207
215
  departmentid:departmentid, sourcePage:sourcePage, language:language, userAgent:client, status:requestStatus, createdBy: undefined,
208
216
  attributes:rAttributes, subject:undefined, preflight:false, channel:undefined, location:undefined,
209
217
  lead:createdLead, requester:project_user
218
+ // , auto_close: auto_close
210
219
  };
211
220
 
212
221
  winston.debug("new_request", new_request);
@@ -398,7 +407,9 @@ router.post('/', function (req, res) {
398
407
  // winston.debug('updatedParticipantsRequest', updatedParticipantsRequest);
399
408
  // manca id
400
409
 
401
- return requestService.closeRequestByRequestId(recipient_id, projectId).then(function(updatedStatusRequest) {
410
+ // closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
411
+ const closed_by = user_id;
412
+ return requestService.closeRequestByRequestId(recipient_id, projectId, false, true,closed_by ).then(function(updatedStatusRequest) {
402
413
 
403
414
  winston.debug('updatedStatusRequest', updatedStatusRequest.toObject());
404
415
  return res.json(updatedStatusRequest);
package/event/botEvent.js CHANGED
@@ -123,7 +123,7 @@ messageEvent.on('message.create', function(message) {
123
123
  if (bot.type==="internal") {
124
124
  botEvent.emit('bot.message.received.notify.internal', message);
125
125
 
126
- }else {
126
+ }else { //external
127
127
  if (bot.url) {
128
128
  var botNotification = {bot: bot, message: message};
129
129
  botEvent.emit('bot.message.received.notify.external', botNotification);
@@ -0,0 +1,11 @@
1
+ const EventEmitter = require('events');
2
+
3
+ class SubscriptionEvent extends EventEmitter {}
4
+ var winston = require('../config/winston');
5
+
6
+
7
+ const subscriptionEvent = new SubscriptionEvent();
8
+
9
+
10
+
11
+ module.exports = subscriptionEvent;
Binary file
Binary file
Binary file
Binary file
@@ -83,9 +83,12 @@ module.exports = function(passport) {
83
83
  // qui arriva questo
84
84
  // decoded: {"_id":"5ce3ee855c520200176c189e","updatedAt":"2019-05-31T09:50:22.949Z","createdAt":"2019-05-21T12:26:45.192Z","name":"botext","url":"https://tiledesk-v2-simple--andrealeo83.repl.co","id_project":"5ce3d1ceb25ad30017274bc5","trashed":false,"createdBy":"5ce3d1c7b25ad30017274bc2","__v":0,"external":true,"iat":1559297130,"aud":"https://tiledesk.com","iss":"https://tiledesk.com","sub":"5ce3ee855c520200176c189e@tiledesk.com/bot"}
85
85
 
86
- winston.debug("decoded.aud: "+ decoded.aud );
87
86
 
88
87
  if (decoded && decoded.aud) {
88
+
89
+ winston.debug("decoded.aud: "+ decoded.aud );
90
+
91
+
89
92
  const audUrl = new URL(decoded.aud);
90
93
  winston.debug("audUrl: "+ audUrl );
91
94
  const path = audUrl.pathname;
package/models/lead.js CHANGED
@@ -96,6 +96,8 @@ var LeadSchema = new Schema({
96
96
  LeadSchema.index({fullname: 'text', email: 'text'},
97
97
  {"name":"lead_fulltext","default_language": defaultFullTextLanguage,"language_override": "dummy"}); // schema level
98
98
 
99
+ // suggested by atlas
100
+ LeadSchema.index({status: 1, id_project: 1, createdAt: -1});
99
101
 
100
102
  var lead = mongoose.model('lead', LeadSchema);
101
103
 
package/models/request.js CHANGED
@@ -58,7 +58,7 @@ var RequestSchema = new Schema({
58
58
  type: Schema.Types.ObjectId,
59
59
  ref: 'project_user',
60
60
  required: false, //ENABLEIT,
61
- index: true
61
+ // index: true //unused
62
62
  },
63
63
 
64
64
 
@@ -100,7 +100,7 @@ var RequestSchema = new Schema({
100
100
  type: Number,
101
101
  required: false,
102
102
  default: RequestConstants.UNASSIGNED,
103
- index: true
103
+ // index: true //unused
104
104
  },
105
105
 
106
106
 
@@ -134,17 +134,20 @@ var RequestSchema = new Schema({
134
134
  index: true,
135
135
  default: "medium" //translate on client side
136
136
  },
137
-
137
+
138
+ followers: [{
139
+ type: Schema.Types.ObjectId,
140
+ ref: 'project_user' }],
138
141
 
139
142
  participantsAgents: {
140
143
  type: Array,
141
144
  required: false,
142
- index: true,
145
+ // index: true, //i think unused
143
146
  },
144
147
  participantsBots: {
145
148
  type: Array,
146
149
  required: false,
147
- index: true,
150
+ // index: true, //i think unused
148
151
  },
149
152
  department: {
150
153
  type: Schema.Types.ObjectId,
@@ -161,20 +164,20 @@ var RequestSchema = new Schema({
161
164
  // First reply time is the time between ticket creation and the first public comment from an agent, displayed in minutes. Some qualifications include:
162
165
  first_response_at: {
163
166
  type: Date,
164
- index: true
167
+ // index: true // unused
165
168
  },
166
169
 
167
170
  //timestamp when the agent reply the first time to a visitor
168
171
  assigned_at: {
169
172
  type: Date,
170
- index: true
173
+ // index: true //unused
171
174
  },
172
175
 
173
176
  // Wait Time (Average and Longest): The average and longest times visitors have been waiting for their chats to be served.
174
177
  // Wait time is calculated as duration between the first visitor message in the chat and the first agent message. Wait time will be 0 for agent initiated or trigger initiated chats.
175
178
  waiting_time: {
176
179
  type: Number,
177
- index: true
180
+ // index: true // why?
178
181
  },
179
182
 
180
183
 
@@ -187,9 +190,12 @@ var RequestSchema = new Schema({
187
190
  // default: 0
188
191
  // },
189
192
 
190
- closed_at: {
193
+ closed_at: {
191
194
  type: Date
192
195
  },
196
+ closed_by: {
197
+ type: String
198
+ },
193
199
 
194
200
  tags: [TagSchema],
195
201
 
@@ -205,7 +211,11 @@ var RequestSchema = new Schema({
205
211
  },
206
212
  snapshot: {
207
213
  type: RequestSnapshotSchema,
208
- select: true
214
+ select: true,
215
+ //index: false,
216
+ // includeIndices: false,
217
+ excludeIndexes: true //testa bene
218
+
209
219
  // select: false
210
220
  },
211
221
 
@@ -254,7 +264,10 @@ var RequestSchema = new Schema({
254
264
  required: false
255
265
  },
256
266
  location: LocationSchema,
257
-
267
+ auto_close: {
268
+ type: Number,
269
+ index: true
270
+ },
258
271
  id_project: {
259
272
  type: String,
260
273
  required: true,
@@ -434,8 +447,22 @@ RequestSchema.index({ id_project: 1, preflight:1, updatedAt: -1 }); // used quer
434
447
 
435
448
  RequestSchema.index({ hasBot: 1, createdAt: 1 }); // suggested by atlas
436
449
 
450
+ // suggested by atlas
451
+ RequestSchema.index({ lead: 1, id_project: 1, participants: 1, preflight: 1, createdAt: -1 });
452
+ // suggested by atlas
453
+ RequestSchema.index({ lead: 1, id_project: 1, preflight: 1, createdAt: -1 });
454
+
455
+ // suggested by atlas
456
+ RequestSchema.index({ lead: 1, "snapshot.agents.id_user": 1, id_project: 1, preflight: 1, createdAt: -1 });
457
+
458
+ // suggested by atlas
437
459
  RequestSchema.index({ id_project: 1, ticket_id: 1 });
438
460
 
461
+ // suggested by atlas
462
+ RequestSchema.index({ id_project: 1, createdAt: 1, preflight: 1});
463
+
464
+ //suggested by atlas profiler. Used by auto closing requests
465
+ RequestSchema.index({ hasBot: 1, status: 1, createdAt: 1});
439
466
 
440
467
 
441
468
  // cannot index parallel arrays [agents] [participants] {"driv
@@ -0,0 +1,34 @@
1
+ var mongoose = require('mongoose');
2
+ var Schema = mongoose.Schema;
3
+
4
+
5
+
6
+ var SubscriptionLogSchema = new Schema({
7
+ event: {
8
+ type: String,
9
+ required: true
10
+ },
11
+ target: {
12
+ type: String,
13
+ required: true
14
+ },
15
+ response: {
16
+ type: String,
17
+ },
18
+ body: {
19
+ type: String,
20
+ },
21
+ err: {
22
+ type: String,
23
+ },
24
+ id_project: {
25
+ type: String,
26
+ required: true,
27
+ index:true
28
+ }
29
+ }, {
30
+ timestamps: true
31
+ }
32
+ );
33
+
34
+ module.exports = mongoose.model('subscriptionLog', SubscriptionLogSchema);
@@ -0,0 +1,42 @@
1
+ var mongoose = require('mongoose');
2
+ var Schema = mongoose.Schema;
3
+ var TagSchema = require('./tag');
4
+
5
+
6
+
7
+ var TagLibrarySchema = new Schema({
8
+ ...TagSchema.obj,
9
+ // tag: {
10
+ // type: String,
11
+ // required: true,
12
+ // index: true
13
+ // },
14
+ // color: {
15
+ // type: String,
16
+ // required: false,
17
+ // index: false
18
+ // },
19
+ // attributes: {
20
+ // type: Object,
21
+ // },
22
+ id_project: {
23
+ type: String,
24
+ required: true,
25
+ index: true
26
+ },
27
+ createdBy: {
28
+ type: String,
29
+ required: true
30
+ }
31
+ },{
32
+ timestamps: true
33
+ }
34
+ );
35
+
36
+ TagLibrarySchema.index({ id_project: 1, tag: 1 }, { unique: true });
37
+
38
+
39
+ var Tag = mongoose.model('tag', TagLibrarySchema);
40
+
41
+
42
+ module.exports = Tag;
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.2.39",
4
+ "version": "2.3.3",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -29,29 +29,21 @@
29
29
  "tiledesk-server": "./bin/www"
30
30
  },
31
31
  "optionalDependencies": {
32
- "@tiledesk-ent/tiledesk-server-activities": "^1.1.18",
33
- "@tiledesk-ent/tiledesk-server-analytics": "^1.1.12",
34
32
  "@tiledesk-ent/tiledesk-server-cache": "^1.1.10",
35
- "@tiledesk-ent/tiledesk-server-canned": "^1.1.2",
36
- "@tiledesk-ent/tiledesk-server-departments": "^1.1.3",
37
33
  "@tiledesk-ent/tiledesk-server-dialogflow": "^1.1.6",
38
- "@tiledesk-ent/tiledesk-server-groups": "^1.1.3",
39
34
  "@tiledesk-ent/tiledesk-server-jwthistory": "^1.1.9",
40
- "@tiledesk-ent/tiledesk-server-mt": "^1.1.8",
41
35
  "@tiledesk-ent/tiledesk-server-payments": "^1.1.6",
42
36
  "@tiledesk-ent/tiledesk-server-queue": "^1.1.11",
43
37
  "@tiledesk-ent/tiledesk-server-request-history": "^1.1.5",
44
- "@tiledesk-ent/tiledesk-server-resthook": "^1.1.53",
45
38
  "@tiledesk-ent/tiledesk-server-routing-queue": "^1.1.11",
46
- "@tiledesk-ent/tiledesk-server-tags": "^1.1.2",
47
- "@tiledesk-ent/tiledesk-server-triggers": "^1.1.82",
48
39
  "@tiledesk-ent/tiledesk-server-visitorcounter": "^1.1.1",
49
40
  "@tiledesk-ent/tiledesk-server-enterprise": "^1.0.0"
50
41
  },
51
42
  "dependencies": {
52
43
  "@tiledesk/tiledesk-chat21-app": "^1.1.4",
53
44
  "@tiledesk/tiledesk-chatbot-util": "^0.8.33",
54
- "@tiledesk/tiledesk-rasa-connector": "^1.0.5",
45
+ "@tiledesk/tiledesk-json-rules-engine": "^4.0.3",
46
+ "@tiledesk/tiledesk-rasa-connector": "^1.0.7",
55
47
  "app-root-path": "^3.0.0",
56
48
  "bcrypt-nodejs": "0.0.3",
57
49
  "body-parser": "^1.20.0",
@@ -94,6 +86,7 @@
94
86
  "passport": "^0.4.1",
95
87
  "passport-http": "^0.3.0",
96
88
  "passport-jwt": "^4.0.0",
89
+ "pdfmake": "^0.2.5",
97
90
  "promise-events": "^0.2.4",
98
91
  "request": "^2.88.2",
99
92
  "request-promise": "^4.2.6",