@tiledesk/tiledesk-server 2.2.38 → 2.3.2
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 +12 -0
- package/LICENSE +14 -657
- package/README.md +36 -21
- package/app.js +29 -5
- package/channels/chat21/chat21WebHook.js +12 -1
- package/config/labels/widget.json +320 -0
- package/event/botEvent.js +1 -1
- package/event/subscriptionEvent.js +11 -0
- package/fonts/Roboto-Italic.ttf +0 -0
- package/fonts/Roboto-Medium.ttf +0 -0
- package/fonts/Roboto-MediumItalic.ttf +0 -0
- package/fonts/Roboto-Regular.ttf +0 -0
- package/middleware/passport.js +4 -1
- package/models/lead.js +2 -0
- package/models/request.js +38 -11
- package/models/subscriptionLog.js +34 -0
- package/models/tagLibrary.js +42 -0
- package/package.json +4 -10
- package/pubmodules/activities/activityArchiver.js +295 -0
- package/pubmodules/activities/index.js +3 -0
- package/pubmodules/activities/models/activity.js +88 -0
- package/pubmodules/activities/routes/activity.js +710 -0
- package/pubmodules/activities/test/activityRoute.js +85 -0
- package/pubmodules/analytics/analytics.js +1719 -0
- package/pubmodules/analytics/index.js +3 -0
- package/pubmodules/canned/cannedResponse.js +51 -0
- package/pubmodules/canned/cannedResponseRoute.js +157 -0
- package/pubmodules/canned/index.js +3 -0
- package/pubmodules/messageActions/messageActionsInterceptor.js +4 -2
- package/pubmodules/pubModulesManager.js +115 -7
- package/pubmodules/rasa/index.js +8 -1
- package/pubmodules/rasa/listener.js +28 -7
- package/pubmodules/scheduler/tasks/closeAgentUnresponsiveRequestTask.js +3 -1
- package/pubmodules/scheduler/tasks/closeBotUnresponsiveRequestTask.js +5 -3
- package/pubmodules/trigger/default.js +271 -0
- package/pubmodules/trigger/event/actionEventEmitter.js +10 -0
- package/pubmodules/trigger/event/flowEventEmitter.js +10 -0
- package/pubmodules/trigger/event/triggerEventEmitter.js +10 -0
- package/pubmodules/trigger/index.js +3 -0
- package/pubmodules/trigger/models/trigger.js +149 -0
- package/pubmodules/trigger/rulesTrigger.js +1181 -0
- package/pubmodules/trigger/start.js +114 -0
- package/pubmodules/trigger/triggerRoute.js +150 -0
- package/routes/department.js +51 -0
- package/routes/group.js +140 -0
- package/routes/lead.js +24 -1
- package/routes/message.js +6 -3
- package/routes/project.js +52 -0
- package/routes/public-request.js +265 -2
- package/routes/request.js +86 -13
- package/routes/subscription.js +140 -0
- package/routes/tag.js +138 -0
- package/routes/user-request.js +3 -2
- package/routes/widget.js +16 -1
- package/routes/widgetLoader.js +31 -0
- package/services/faqBotHandler.js +2 -2
- package/services/faqBotSupport.js +0 -1
- package/services/faqService.js +1 -1
- package/services/modulesManager.js +16 -182
- package/services/requestService.js +364 -6
- package/services/subscriptionNotifier.js +485 -0
- package/template/email/assignedEmailMessage.html +1 -1
- package/template/email/assignedRequest.html +1 -1
- package/template/email/newMessage.html +1 -1
- package/template/email/passwordChanged.html +1 -1
- package/template/email/pooledEmailMessage.html +1 -1
- package/template/email/pooledRequest.html +1 -1
- package/template/email/resetPassword.html +2 -2
- package/template/email/ticket.html +1 -1
- package/test/messageRoute.js +69 -0
- package/test/requestService.js +3 -1
- package/views/messages.jade +1 -1
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
|
|
4
|
+
"version": "2.3.2",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "node ./bin/www",
|
|
7
7
|
"pretest": "mongodb-runner start",
|
|
@@ -29,28 +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",
|
|
45
|
+
"@tiledesk/tiledesk-json-rules-engine": "^4.0.3",
|
|
46
|
+
"@tiledesk/tiledesk-rasa-connector": "^1.0.7",
|
|
54
47
|
"app-root-path": "^3.0.0",
|
|
55
48
|
"bcrypt-nodejs": "0.0.3",
|
|
56
49
|
"body-parser": "^1.20.0",
|
|
@@ -93,6 +86,7 @@
|
|
|
93
86
|
"passport": "^0.4.1",
|
|
94
87
|
"passport-http": "^0.3.0",
|
|
95
88
|
"passport-jwt": "^4.0.0",
|
|
89
|
+
"pdfmake": "^0.2.5",
|
|
96
90
|
"promise-events": "^0.2.4",
|
|
97
91
|
"request": "^2.88.2",
|
|
98
92
|
"request-promise": "^4.2.6",
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
const authEvent = require('../../event/authEvent');
|
|
2
|
+
const requestEvent = require('../../event/requestEvent');
|
|
3
|
+
var Activity = require('./models/activity');
|
|
4
|
+
var winston = require('../../config/winston');
|
|
5
|
+
|
|
6
|
+
class ActivityArchiver {
|
|
7
|
+
|
|
8
|
+
listen() {
|
|
9
|
+
|
|
10
|
+
winston.debug('ActivityArchiver listen');
|
|
11
|
+
|
|
12
|
+
var enabled = process.env.ACTIVITY_HISTORY_ENABLED || "false";
|
|
13
|
+
winston.debug('ActivityArchiver enabled:'+enabled);
|
|
14
|
+
|
|
15
|
+
if (enabled==="true") {
|
|
16
|
+
winston.debug('ActivityArchiver enabled');
|
|
17
|
+
}else {
|
|
18
|
+
winston.info('ActivityArchiver disabled');
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (process.env.MONGOOSE_SYNCINDEX) {
|
|
23
|
+
Activity.syncIndexes();
|
|
24
|
+
winston.info("Activity.syncIndexes called");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var that = this;
|
|
28
|
+
|
|
29
|
+
//modify all to async
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
activityEvent.on('user.verify.email', this.save);
|
|
34
|
+
|
|
35
|
+
activityEvent.on('group.create', this.save);
|
|
36
|
+
activityEvent.on('group.update', this.save);
|
|
37
|
+
activityEvent.on('group.delete', this.save);
|
|
38
|
+
|
|
39
|
+
// activityEvent.on('lead.create', this.save);
|
|
40
|
+
activityEvent.on('lead.update', this.save);
|
|
41
|
+
activityEvent.on('lead.delete', this.save);
|
|
42
|
+
activityEvent.on('lead.download.csv', this.save);
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
authEvent.on('project_user.invite.pending', function(event) {
|
|
46
|
+
setImmediate(() => {
|
|
47
|
+
if (event.skipArchive) {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
var activity = new Activity({actor: {type:"user", id: event.req.user.id, name: event.req.user.fullName },
|
|
51
|
+
verb: "PROJECT_USER_INVITE", actionObj: event.req.body,
|
|
52
|
+
target: {type:"pendinginvitation", id:event.savedPendingInvitation._id.toString(), object: event.savedPendingInvitation },
|
|
53
|
+
id_project: event.req.projectid });
|
|
54
|
+
that.save(activity);
|
|
55
|
+
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
authEvent.on('project_user.invite', function(event) {
|
|
61
|
+
setImmediate(() => {
|
|
62
|
+
if (event.skipArchive) {
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
var activity = new Activity({actor: {type:"user", id: event.req.user.id, name: event.req.user.fullName },
|
|
68
|
+
verb: "PROJECT_USER_INVITE", actionObj: event.req.body,
|
|
69
|
+
target: {type:"project_user", id: event.savedProject_userPopulated._id.toString(), object: event.savedProject_userPopulated },
|
|
70
|
+
id_project: event.req.projectid });
|
|
71
|
+
that.save(activity);
|
|
72
|
+
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
authEvent.on('project_user.update', function(event) {
|
|
78
|
+
setImmediate(() => {
|
|
79
|
+
console.log("project_user.update");
|
|
80
|
+
/*
|
|
81
|
+
2019-11-20T10:40:52.686991+00:00 app[web.1]: TypeError: Cannot read property '_id' of undefined
|
|
82
|
+
*/
|
|
83
|
+
if (event.skipArchive) {
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
var project_user = undefined;
|
|
88
|
+
if (event.updatedProject_userPopulated.toObject) {
|
|
89
|
+
project_user = event.updatedProject_userPopulated.toObject()
|
|
90
|
+
}else {
|
|
91
|
+
project_user = event.updatedProject_userPopulated;
|
|
92
|
+
}
|
|
93
|
+
var activity = new Activity({actor: {type:"user", id: event.req.user.id, name: event.req.user.fullName },
|
|
94
|
+
verb: "PROJECT_USER_UPDATE", actionObj: event.req.body,
|
|
95
|
+
target: {type:"project_user", id: event.updatedProject_userPopulated._id.toString(), object: project_user},
|
|
96
|
+
id_project: event.req.projectid });
|
|
97
|
+
that.save(activity);
|
|
98
|
+
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
authEvent.on('project_user.delete', function(event) {
|
|
104
|
+
setImmediate(() => {
|
|
105
|
+
if (event.skipArchive) {
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var activity = new Activity({actor: {type:"user", id: event.req.user.id, name: event.req.user.fullName },
|
|
110
|
+
verb: "PROJECT_USER_DELETE", actionObj: event.req.body,
|
|
111
|
+
target: {type:"project_user", id:event.req.params.project_userid, object: event.project_userPopulated.toObject() }, //Error saving activity Maximum call stack size exceeded
|
|
112
|
+
id_project: event.req.projectid });
|
|
113
|
+
that.save(activity);
|
|
114
|
+
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
authEvent.on('user.signin', function(event) {
|
|
120
|
+
winston.debug('ActivityArchiver user.login');
|
|
121
|
+
setImmediate(() => {
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
if (event.skipArchive) {
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
var activity = new Activity({actor: {type:"user", id: event.user._id, name: event.user.fullName },
|
|
129
|
+
verb: "USER_SIGNIN", actionObj: event.req.body,
|
|
130
|
+
target: {type:"user", id:event.user._id.toString(), object: null },
|
|
131
|
+
id_project: '*' });
|
|
132
|
+
that.save(activity);
|
|
133
|
+
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
authEvent.on('user.login.error', function(event) {
|
|
137
|
+
setImmediate(() => {
|
|
138
|
+
|
|
139
|
+
if (event.skipArchive) {
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
var activity = new Activity({actor: {type:"user"},
|
|
144
|
+
verb: "USER_SIGNIN_ERROR", actionObj: event.req.body,
|
|
145
|
+
target: {type:"user", id:null, object: null },
|
|
146
|
+
id_project: '*' });
|
|
147
|
+
that.save(activity);
|
|
148
|
+
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
authEvent.on('user.requestresetpassword', function(event) {
|
|
153
|
+
setImmediate(() => {
|
|
154
|
+
|
|
155
|
+
if (event.skipArchive) {
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
var activity = new Activity({actor: {type:"user", id: event.updatedUser._id, name: event.updatedUser.fullName },
|
|
160
|
+
verb: "USER_REQUEST_RESETPASSWORD", actionObj: event.req.body,
|
|
161
|
+
target: {type:"user", id:event.updatedUser._id.toString(), object: null },
|
|
162
|
+
id_project: '*' });
|
|
163
|
+
that.save(activity);
|
|
164
|
+
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
authEvent.on('user.resetpassword', function(event) {
|
|
169
|
+
setImmediate(() => {
|
|
170
|
+
|
|
171
|
+
if (event.skipArchive) {
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
var activity = new Activity({actor: {type:"user", id: event.saveUser._id, name: event.saveUser.fullName },
|
|
176
|
+
verb: "USER_RESETPASSWORD", actionObj: null, //req.body otherwise print password
|
|
177
|
+
target: {type:"user", id:event.saveUser._id.toString(), object: null },
|
|
178
|
+
id_project: '*' });
|
|
179
|
+
that.save(activity);
|
|
180
|
+
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
authEvent.on('user.signup', function(event) {
|
|
186
|
+
setImmediate(() => {
|
|
187
|
+
if (event.skipArchive) {
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
var activity = new Activity({actor: {type:"user", id: event.savedUser._id, name: event.savedUser.fullName },
|
|
192
|
+
verb: "USER_SIGNUP", actionObj: event.req.body,
|
|
193
|
+
target: {type:"user", id: event.savedUser._id.toString(), object: null },
|
|
194
|
+
id_project: '*' });
|
|
195
|
+
that.save(activity);
|
|
196
|
+
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
authEvent.on('user.signup.error', function(event) {
|
|
201
|
+
setImmediate(() => {
|
|
202
|
+
if (event.skipArchive) {
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
var activity = new Activity({actor: {type:"user"},
|
|
208
|
+
verb: "USER_SIGNUP_ERROR", actionObj: event.req.body,
|
|
209
|
+
target: {type:"user", id:null, object: null },
|
|
210
|
+
id_project: '*' });
|
|
211
|
+
that.save(activity);
|
|
212
|
+
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
requestEvent.on('request.create', function(request) {
|
|
217
|
+
setImmediate(() => {
|
|
218
|
+
// problema requester_id
|
|
219
|
+
|
|
220
|
+
// Error saving activity {"_id":"5e06189c6e226d358896d733","actor":{"_id":"5e06189c6e226d358896d734","type":"user","id":null},"verb":"REQUEST_CREATE","actionObj":{"status":200,"participants":["5e06189c6e226d358896d728"],"messages_count":0,"tags":[],"_id":"5e06189c6e226d358896d72e","request_id":"request_id-closeRequest","first_text":"first_text","department":{"routing":"assigned","default":true,"status":1,"_id":"5e06189c6e226d358896d72b","name":"Default Department","id_project":"5e06189c6e226d358896d729","createdBy":"5e06189c6e226d358896d728","createdAt":"2019-12-27T14:43:40.327Z","updatedAt":"2019-12-27T14:43:40.327Z","__v":0},"agents":[{"_id":"5e06189c6e226d358896d72a","id_project":"5e06189c6e226d358896d729","id_user":"5e06189c6e226d358896d728","role":"owner","user_available":true,"createdBy":"5e06189c6e226d358896d728","createdAt":"2019-12-27T14:43:40.324Z","updatedAt":"2019-12-27T14:43:40.324Z","__v":0}],"id_project":"5e06189c6e226d358896d729","createdBy":"requester_id1","channel":{"name":"chat21"},"createdAt":"2019-12-27T14:43:40.586Z","updatedAt":"2019-12-27T14:43:40.586Z","__v":0},"target":{"type":"request","id":"5e06189c6e226d358896d72e","object":{"status":200,"participants":["5e06189c6e226d358896d728"],"messages_count":0,"tags":[],"_id":"5e06189c6e226d358896d72e","request_id":"request_id-closeRequest","first_text":"first_text","department":{"routing":"assigned","default":true,"status":1,"_id":"5e06189c6e226d358896d72b","name":"Default Department","id_project":"5e06189c6e226d358896d729","createdBy":"5e06189c6e226d358896d728","createdAt":"2019-12-27T14:43:40.327Z","updatedAt":"2019-12-27T14:43:40.327Z","__v":0},"agents":[{"_id":"5e06189c6e226d358896d72a","id_project":"5e06189c6e226d358896d729","id_user":"5e06189c6e226d358896d728","role":"owner","user_available":true,"createdBy":"5e06189c6e226d358896d728","createdAt":"2019-12-27T14:43:40.324Z","updatedAt":"2019-12-27T14:43:40.324Z","__v":0}],"id_project":"5e06189c6e226d358896d729","createdBy":"requester_id1","channel":{"name":"chat21"},"createdAt":"2019-12-27T14:43:40.586Z","updatedAt":"2019-12-27T14:43:40.586Z","__v":0}},"id_project":"5e06189c6e226d358896d729"}
|
|
221
|
+
|
|
222
|
+
// TODO error: Error saving activity {"activity":{"_id":"5e273b31f13e801703d52515","actor":{"_id":"5e273b31f13e801703d52516","type":"user","id":null},"verb":"REQUEST_CREATE","actionObj":{"status":200,"participants":["5e273b30f13e801703d52508"],"messages_count":0,"tags":[],"_id":"5e273b31f13e801703d52511","request_id":"request_id1","first_text":"first_text","department":{"routing":"assigned","default":false,"status":1,"_id":"5e273b31f13e801703d5250f","name":"PooledDepartment-for-createWithIdWith","id_project":"5e273b31f13e801703d5250a","createdBy":"5e273b30f13e801703d52507","createdAt":"2020-01-21T17:56:01.471Z","updatedAt":"2020-01-21T17:56:01.471Z","__v":0},"agents":[{"_id":"5e273b31f13e801703d5250b","id_project":"5e273b31f13e801703d5250a","id_user":"5e273b30f13e801703d52507","role":"owner","user_available":true,"createdBy":"5e273b30f13e801703d52507","createdAt":"2020-01-21T17:56:01.465Z","updatedAt":"2020-01-21T17:56:01.465Z","__v":0},{"_id":"5e273b31f13e801703d5250e","id_project":"5e273b31f13e801703d5250a","id_user":"5e273b30f13e801703d52508","role":"agent","user_available":true,"createdBy":"5e273b30f13e801703d52508","createdAt":"2020-01-21T17:56:01.469Z","updatedAt":"2020-01-21T17:56:01.469Z","__v":0}],"id_project":"5e273b31f13e801703d5250a","createdBy":"requester_id1","channel":{"name":"chat21"},"createdAt":"2020-01-21T17:56:01.480Z","updatedAt":"2020-01-21T17:56:01.480Z","__v":0},"target":{"type":"request","id":"5e273b31f13e801703d52511","object":{"status":200,"participants":["5e273b30f13e801703d52508"],"messages_count":0,"tags":[],"_id":"5e273b31f13e801703d52511","request_id":"request_id1","first_text":"first_text","department":{"routing":"assigned","default":false,"status":1,"_id":"5e273b31f13e801703d5250f","name":"PooledDepartment-for-createWithIdWith","id_project":"5e273b31f13e801703d5250a","createdBy":"5e273b30f13e801703d52507","createdAt":"2020-01-21T17:56:01.471Z","updatedAt":"2020-01-21T17:56:01.471Z","__v":0},"agents":[{"_id":"5e273b31f13e801703d5250b","id_project":"5e273b31f13e801703d5250a","id_user":"5e273b30f13e801703d52507","role":"owner","user_available":true,"createdBy":"5e273b30f13e801703d52507","createdAt":"2020-01-21T17:56:01.465Z","updatedAt":"2020-01-21T17:56:01.465Z","__v":0},{"_id":"5e273b31f13e801703d5250e","id_project":"5e273b31f13e801703d5250a","id_user":"5e273b30f13e801703d52508","role":"agent","user_available":true,"createdBy":"5e273b30f13e801703d52508","createdAt":"2020-01-21T17:56:01.469Z","updatedAt":"2020-01-21T17:56:01.469Z","__v":0}],"id_project":"5e273b31f13e801703d5250a","createdBy":"requester_id1","channel":{"name":"chat21"},"createdAt":"2020-01-21T17:56:01.480Z","updatedAt":"2020-01-21T17:56:01.480Z","__v":0}},"id_project":"5e273b31f13e801703d5250a"},"err":{"errors":{"actor.id":{"message":"Path `id` is required.","name":"ValidatorError","properties":{"message":"Path `id` is required.","type":"required","path":"id","value":null},"kind":"required","path":"id","value":null},"actor":{"errors":{"id":{"message":"Path `id` is required.","name":"ValidatorError","properties":{"message":"Path `id` is required.","type":"required","path":"id","value":null},"kind":"required","path":"id","value":null}},"_message":"Validation failed","message":"Validation failed: id: Path `id` is required.","name":"ValidationError"}},"_message":"activity validation failed","message":"activity validation failed: actor.id: Path `id` is required., actor: Validation failed: id: Path `id` is required.","name":"ValidationError"}}
|
|
223
|
+
|
|
224
|
+
// request is plain object must be mongoose object oto populate
|
|
225
|
+
|
|
226
|
+
// if (event.skipArchive) {
|
|
227
|
+
// return 0;
|
|
228
|
+
// }
|
|
229
|
+
|
|
230
|
+
//TODO remove preflight
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
|
|
234
|
+
if (request.preflight === true) {
|
|
235
|
+
winston.debug("preflight request disable archiver")
|
|
236
|
+
return 0;
|
|
237
|
+
}
|
|
238
|
+
var activity = new Activity({actor: {type:"user", id: request.requester_id},
|
|
239
|
+
verb: "REQUEST_CREATE", actionObj: request,
|
|
240
|
+
target: {type:"request", id:request._id, object: request },
|
|
241
|
+
id_project: request.id_project });
|
|
242
|
+
that.save(activity);
|
|
243
|
+
} catch(e) {
|
|
244
|
+
winston.error('ActivityArchiver error saving activity',e);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
requestEvent.on('request.update.preflight', function(request) {
|
|
253
|
+
setImmediate(() => {
|
|
254
|
+
|
|
255
|
+
try {
|
|
256
|
+
|
|
257
|
+
if (request.preflight === true) {
|
|
258
|
+
winston.debug("preflight request disable archiver")
|
|
259
|
+
return 0;
|
|
260
|
+
}
|
|
261
|
+
var activity = new Activity({actor: {type:"user", id: request.requester_id},
|
|
262
|
+
verb: "REQUEST_CREATE", actionObj: request,
|
|
263
|
+
target: {type:"request", id:request._id, object: request },
|
|
264
|
+
id_project: request.id_project });
|
|
265
|
+
that.save(activity);
|
|
266
|
+
} catch(e) {
|
|
267
|
+
winston.error('ActivityArchiver error saving activity',e);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
winston.info('ActivityArchiver listening');
|
|
278
|
+
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
save(activity) {
|
|
282
|
+
activity.save(function(err, savedActivity) {
|
|
283
|
+
if (err) {
|
|
284
|
+
winston.error('Error saving activity ', {activity: activity.toObject(), err:err});
|
|
285
|
+
}else {
|
|
286
|
+
winston.debug('Activity saved', savedActivity.toObject());
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
var activityArchiver = new ActivityArchiver();
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
module.exports = activityArchiver;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
var mongoose = require('mongoose');
|
|
2
|
+
var Schema = mongoose.Schema;
|
|
3
|
+
|
|
4
|
+
// https://getstream.io/blog/designing-activity-stream-newsfeed-w3c-spec/
|
|
5
|
+
// {
|
|
6
|
+
// "@context": "http://www.w3.org/ns/activitystreams",
|
|
7
|
+
// "type": "added",
|
|
8
|
+
// "published": "2015-02-10T15:04:55Z",
|
|
9
|
+
// "actor": {
|
|
10
|
+
// "type": "Person",
|
|
11
|
+
// "id": "http://www.test.example/jack",
|
|
12
|
+
// "name": "Jack Hill",
|
|
13
|
+
// "url": "http://example.org/jack",
|
|
14
|
+
// "image": {
|
|
15
|
+
// "type": "Link",
|
|
16
|
+
// "href": "http://example.org/jack/profile.jpg",
|
|
17
|
+
// "mediaType": "image/jpeg"
|
|
18
|
+
// }
|
|
19
|
+
// },
|
|
20
|
+
// "object" : {
|
|
21
|
+
// "id": "http://www.test.example/jack/hill_photos/the_hill1.jpg",
|
|
22
|
+
// "type": "Photo",
|
|
23
|
+
// "label": "Great Photo of The Hill"
|
|
24
|
+
// },
|
|
25
|
+
// "target" : {
|
|
26
|
+
// "id": "http://example.org/jack/albums/great_hill_pics",
|
|
27
|
+
// "type": "OrderedCollection",
|
|
28
|
+
// "name": "Great Hill Pics"
|
|
29
|
+
// }
|
|
30
|
+
// }
|
|
31
|
+
|
|
32
|
+
//actor: {type:"user", id: event.req.user.id, name: event.req.user.fullName },
|
|
33
|
+
var ActorActivitySchema = new Schema({
|
|
34
|
+
type: {
|
|
35
|
+
type: String,
|
|
36
|
+
required: true,
|
|
37
|
+
index:true
|
|
38
|
+
},
|
|
39
|
+
id: {
|
|
40
|
+
type: String,
|
|
41
|
+
required: true,
|
|
42
|
+
index:true
|
|
43
|
+
},
|
|
44
|
+
name: {
|
|
45
|
+
type: String,
|
|
46
|
+
required: false
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
var ActivitySchema = new Schema({
|
|
51
|
+
|
|
52
|
+
actor: {
|
|
53
|
+
// type: String,
|
|
54
|
+
type: ActorActivitySchema,
|
|
55
|
+
required: true,
|
|
56
|
+
//index: true //error saving activity Btree::insert: key too large to index, failing heroku_hwhg3xtx.activities.$target_1 2359 { : { object: { __v: 0, updatedAt: new Date(1555407053615), createdAt: new Date(1555407053615), request_id: "support-group-Lc_Tz_hoCZ9REHC9FbY", requester_id: "5c8a38012d8e6d0017bce22a", first_text: "test 81", department: ObjectId('5b8eb48b5ca4d300141fb2cb'), sourcePage: "https://www.tiledesk.com/", language: "it",
|
|
57
|
+
},
|
|
58
|
+
verb: {
|
|
59
|
+
type: String,
|
|
60
|
+
required: true,
|
|
61
|
+
index: true
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
actionObj: {
|
|
65
|
+
type: Object,
|
|
66
|
+
required: false
|
|
67
|
+
},
|
|
68
|
+
target: {
|
|
69
|
+
// type: String,
|
|
70
|
+
type: Object,
|
|
71
|
+
required: true,
|
|
72
|
+
// index: true
|
|
73
|
+
},
|
|
74
|
+
// summary A natural language summarization of the object encoded as HTML. Multiple language tagged summaries may be provided.
|
|
75
|
+
// summaryMap https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary
|
|
76
|
+
id_project: {
|
|
77
|
+
type: String,
|
|
78
|
+
required: true,
|
|
79
|
+
index: true
|
|
80
|
+
}
|
|
81
|
+
},{
|
|
82
|
+
timestamps: true
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// TODO metti indice per query è lentina
|
|
87
|
+
|
|
88
|
+
module.exports = mongoose.model('activity', ActivitySchema);
|