@tiledesk/tiledesk-server 2.10.20 → 2.10.22
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +6 -0
- package/channels/chat21/chat21WebHook.js +140 -137
- package/package.json +1 -1
- package/pubmodules/messageActions/messageActionsInterceptor.js +2 -0
- package/pubmodules/rules/conciergeBot.js +3 -1
- package/pubmodules/trigger/rulesTrigger.js +3 -1
- package/routes/files.js +1 -2
- package/routes/request.js +12 -1
package/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@
|
|
5
5
|
🚀 IN PRODUCTION 🚀
|
6
6
|
(https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
|
7
7
|
|
8
|
+
# 2.10.22
|
9
|
+
- Test versione (Alert)
|
10
|
+
|
11
|
+
# 2.10.21
|
12
|
+
- Added catch blocks where necessary (improves error management)
|
13
|
+
|
8
14
|
# 2.10.20
|
9
15
|
- updated whatsapp-connector to 0.1.75
|
10
16
|
|
@@ -95,171 +95,174 @@ router.post('/', function (req, res) {
|
|
95
95
|
|
96
96
|
if (!request) { //the request doen't exists create it
|
97
97
|
|
98
|
-
|
99
|
-
|
100
|
-
var departmentid = "default";
|
98
|
+
winston.debug("request not exists with request_id: " + message.recipient);
|
101
99
|
|
100
|
+
var departmentid = "default";
|
102
101
|
|
103
|
-
var language = message.language;
|
104
|
-
winston.debug("chat21 language", language);
|
105
|
-
|
106
|
-
var sourcePage;
|
107
|
-
var client;
|
108
|
-
var userEmail;
|
109
|
-
var userFullname;
|
110
|
-
var projectid; // before request_id id_project unique - commented
|
111
|
-
|
112
|
-
var requestStatus = undefined;
|
113
102
|
|
114
|
-
|
115
|
-
|
116
|
-
// before request_id id_project unique - commented
|
117
|
-
projectid = message.attributes.projectId;
|
118
|
-
winston.debug("chat21 projectid", projectid);
|
119
|
-
|
120
|
-
departmentid = message.attributes.departmentId;
|
121
|
-
winston.debug("chat21 departmentid", departmentid);
|
122
|
-
|
123
|
-
sourcePage = message.attributes.sourcePage;
|
124
|
-
winston.debug("chat21 sourcePage", sourcePage);
|
125
|
-
|
126
|
-
client = message.attributes.client;
|
127
|
-
winston.debug("chat21 client", client);
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
userEmail = message.attributes.userEmail;
|
132
|
-
winston.debug("chat21 userEmail", userEmail);
|
133
|
-
|
134
|
-
userFullname = message.attributes.userFullname;
|
135
|
-
winston.debug("chat21 userFullname", userFullname);
|
103
|
+
var language = message.language;
|
104
|
+
winston.debug("chat21 language", language);
|
136
105
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
winston.debug("requestStatus "+ requestStatus);
|
144
|
-
|
145
|
-
// before request_id id_project unique - commented
|
146
|
-
if (!projectid) {
|
147
|
-
winston.verbose("projectid is null. Not a support message");
|
148
|
-
return res.status(400).send({success: false, msg: 'projectid is null. Not a support message'});
|
149
|
-
}
|
106
|
+
var sourcePage;
|
107
|
+
var client;
|
108
|
+
var userEmail;
|
109
|
+
var userFullname;
|
110
|
+
var projectid; // before request_id id_project unique - commented
|
150
111
|
|
151
|
-
|
152
|
-
if (!message.recipient.startsWith("support-group")) {
|
153
|
-
winston.verbose("recipient not starts wiht support-group. Not a support message");
|
154
|
-
return res.status(400).send({success: false, msg: "recipient not starts wiht support-group. Not a support message"});
|
155
|
-
}
|
156
|
-
|
157
|
-
|
158
|
-
if (!userFullname) {
|
159
|
-
userFullname = message.sender_fullname;
|
160
|
-
}
|
112
|
+
var requestStatus = undefined;
|
161
113
|
|
162
|
-
|
163
|
-
|
114
|
+
if (message.attributes) {
|
164
115
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
// winston.debug("userEmail is defined");
|
169
|
-
// createIfNotExistsWithLeadId(lead_id, fullname, email, id_project, createdBy)
|
170
|
-
return leadService.createIfNotExistsWithLeadId(message.sender, userFullname, userEmail, projectid, null, leadAttributes)
|
171
|
-
.then(function(createdLead) {
|
116
|
+
// before request_id id_project unique - commented
|
117
|
+
projectid = message.attributes.projectId;
|
118
|
+
winston.debug("chat21 projectid", projectid);
|
172
119
|
|
173
|
-
|
174
|
-
|
175
|
-
winston.debug("rAttributes", rAttributes);
|
120
|
+
departmentid = message.attributes.departmentId;
|
121
|
+
winston.debug("chat21 departmentid", departmentid);
|
176
122
|
|
123
|
+
sourcePage = message.attributes.sourcePage;
|
124
|
+
winston.debug("chat21 sourcePage", sourcePage);
|
177
125
|
|
126
|
+
client = message.attributes.client;
|
127
|
+
winston.debug("chat21 client", client);
|
178
128
|
|
179
129
|
|
180
|
-
// message.sender is the project_user id created with firebase custom auth
|
181
130
|
|
182
|
-
|
183
|
-
|
131
|
+
userEmail = message.attributes.userEmail;
|
132
|
+
winston.debug("chat21 userEmail", userEmail);
|
184
133
|
|
185
|
-
|
134
|
+
userFullname = message.attributes.userFullname;
|
135
|
+
winston.debug("chat21 userFullname", userFullname);
|
186
136
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
winston.debug("queryProjectUser", queryProjectUser);
|
193
|
-
|
137
|
+
// TODO proactive status
|
138
|
+
// if (message.attributes.subtype === "info") {
|
139
|
+
// requestStatus = 50;
|
140
|
+
// }
|
141
|
+
}
|
194
142
|
|
195
|
-
|
196
|
-
// .cache(cacheUtil.defaultTTL, projectid+":project_users:request_id:"+requestid)
|
197
|
-
.exec(function (err, project_user) {
|
143
|
+
winston.debug("requestStatus " + requestStatus);
|
198
144
|
|
199
|
-
|
145
|
+
// before request_id id_project unique - commented
|
146
|
+
if (!projectid) {
|
147
|
+
winston.verbose("projectid is null. Not a support message");
|
148
|
+
return res.status(400).send({ success: false, msg: 'projectid is null. Not a support message' });
|
149
|
+
}
|
200
150
|
|
201
|
-
if (err) {
|
202
|
-
winston.error("Error getting the project_user_id", err);
|
203
|
-
}
|
204
151
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
// error->utente bloccato oppure non autenticator request.requester sarà nulll...⁄
|
211
|
-
return winston.error("project_user not found with query: ", queryProjectUser);
|
212
|
-
}
|
152
|
+
if (!message.recipient.startsWith("support-group")) {
|
153
|
+
winston.verbose("recipient not starts wiht support-group. Not a support message");
|
154
|
+
return res.status(400).send({ success: false, msg: "recipient not starts wiht support-group. Not a support message" });
|
155
|
+
}
|
156
|
+
|
213
157
|
|
158
|
+
if (!userFullname) {
|
159
|
+
userFullname = message.sender_fullname;
|
160
|
+
}
|
214
161
|
|
215
|
-
// var auto_close;
|
216
162
|
|
217
|
-
// // qui projecy nn c'è devi leggerlo
|
218
|
-
// // if (req.project.attributes.auto_close === false) {
|
219
|
-
// // auto_close = 10;
|
220
|
-
// // }
|
221
163
|
|
222
|
-
|
223
|
-
var new_request = {
|
224
|
-
request_id: message.recipient, project_user_id:project_user_id, lead_id:createdLead._id, id_project:projectid, first_text:message.text,
|
225
|
-
departmentid:departmentid, sourcePage:sourcePage, language:language, userAgent:client, status:requestStatus, createdBy: undefined,
|
226
|
-
attributes:rAttributes, subject:undefined, preflight:false, channel:undefined, location:undefined,
|
227
|
-
lead:createdLead, requester:project_user
|
228
|
-
// , auto_close: auto_close
|
229
|
-
};
|
230
|
-
|
231
|
-
winston.debug("new_request", new_request);
|
232
|
-
|
233
|
-
return requestService.create(new_request).then(function (savedRequest) {
|
234
164
|
|
235
|
-
|
165
|
+
var leadAttributes = message.attributes;
|
166
|
+
leadAttributes["senderAuthInfo"] = message.senderAuthInfo;
|
167
|
+
|
168
|
+
// winston.debug("userEmail is defined");
|
169
|
+
// createIfNotExistsWithLeadId(lead_id, fullname, email, id_project, createdBy)
|
170
|
+
return leadService.createIfNotExistsWithLeadId(message.sender, userFullname, userEmail, projectid, null, leadAttributes)
|
171
|
+
.then(function (createdLead) {
|
172
|
+
|
173
|
+
var rAttributes = message.attributes;
|
174
|
+
rAttributes["senderAuthInfo"] = message.senderAuthInfo;
|
175
|
+
winston.debug("rAttributes", rAttributes);
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
// message.sender is the project_user id created with firebase custom auth
|
181
|
+
|
182
|
+
var isObjectId = mongoose.Types.ObjectId.isValid(message.sender);
|
183
|
+
winston.debug("isObjectId:" + isObjectId);
|
184
|
+
|
185
|
+
var queryProjectUser = { id_project: projectid, status: "active" };
|
186
|
+
|
187
|
+
if (isObjectId) {
|
188
|
+
queryProjectUser.id_user = message.sender;
|
189
|
+
} else {
|
190
|
+
queryProjectUser.uuid_user = message.sender;
|
191
|
+
}
|
192
|
+
winston.debug("queryProjectUser", queryProjectUser);
|
193
|
+
|
194
|
+
|
195
|
+
return Project_user.findOne(queryProjectUser)
|
196
|
+
// .cache(cacheUtil.defaultTTL, projectid+":project_users:request_id:"+requestid)
|
197
|
+
.exec(function (err, project_user) {
|
198
|
+
|
199
|
+
var project_user_id = null;
|
200
|
+
|
201
|
+
if (err) {
|
202
|
+
winston.error("Error getting the project_user_id", err);
|
203
|
+
}
|
204
|
+
|
205
|
+
if (project_user) {
|
206
|
+
winston.debug("project_user", project_user);
|
207
|
+
project_user_id = project_user.id;
|
208
|
+
winston.debug("project_user_id: " + project_user_id);
|
209
|
+
} else {
|
210
|
+
// error->utente bloccato oppure non autenticator request.requester sarà nulll...⁄
|
211
|
+
return winston.error("project_user not found with query: ", queryProjectUser);
|
212
|
+
}
|
213
|
+
|
214
|
+
|
215
|
+
// var auto_close;
|
216
|
+
|
217
|
+
// // qui projecy nn c'è devi leggerlo
|
218
|
+
// // if (req.project.attributes.auto_close === false) {
|
219
|
+
// // auto_close = 10;
|
220
|
+
// // }
|
221
|
+
|
222
|
+
|
223
|
+
var new_request = {
|
224
|
+
request_id: message.recipient, project_user_id: project_user_id, lead_id: createdLead._id, id_project: projectid, first_text: message.text,
|
225
|
+
departmentid: departmentid, sourcePage: sourcePage, language: language, userAgent: client, status: requestStatus, createdBy: undefined,
|
226
|
+
attributes: rAttributes, subject: undefined, preflight: false, channel: undefined, location: undefined,
|
227
|
+
lead: createdLead, requester: project_user
|
228
|
+
// , auto_close: auto_close
|
229
|
+
};
|
230
|
+
|
231
|
+
winston.debug("new_request", new_request);
|
232
|
+
|
233
|
+
return requestService.create(new_request).then(function (savedRequest) {
|
234
|
+
|
235
|
+
|
236
236
|
//return requestService.createWithIdAndRequester(message.recipient, project_user_id, createdLead._id, projectid, message.text,
|
237
237
|
// departmentid, sourcePage, language, client, requestStatus, null, rAttributes).then(function (savedRequest) {
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
238
|
+
|
239
|
+
|
240
|
+
var messageId = undefined;
|
241
|
+
if (message.attributes && message.attributes.tiledesk_message_id) {
|
242
|
+
messageId = message.attributes.tiledesk_message_id;
|
243
|
+
}
|
244
|
+
|
245
|
+
// upsert(id, sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language)
|
246
|
+
return messageService.upsert(messageId, message.sender, message.sender_fullname, message.recipient, message.text,
|
247
|
+
projectid, null, MessageConstants.CHAT_MESSAGE_STATUS.RECEIVED, message.attributes, message.type, message.metadata, language).then(function (savedMessage) {
|
248
|
+
return res.json(savedRequest);
|
249
|
+
// return requestService.incrementMessagesCountByRequestId(savedRequest.request_id, savedRequest.id_project).then(function(savedRequestWithIncrement) {
|
250
|
+
// return res.json(savedRequestWithIncrement);
|
251
|
+
// });
|
252
|
+
|
253
|
+
|
254
|
+
}).catch(function (err) {
|
255
|
+
winston.error('Error creating the request object.', err);
|
256
|
+
return res.status(500).send({ success: false, msg: 'Error creating the request object.', err: err });
|
257
|
+
});
|
258
|
+
}).catch((err) => {
|
259
|
+
winston.error('(Chat21Webhook) Error creating the request object ', err);
|
260
|
+
return res.status(500).send({ success: false, msg: 'Error creating the request object.', err: err });
|
261
|
+
});
|
258
262
|
});
|
259
|
-
|
260
|
-
|
263
|
+
|
261
264
|
});
|
262
|
-
|
265
|
+
|
263
266
|
|
264
267
|
|
265
268
|
} else {
|
package/package.json
CHANGED
@@ -111,6 +111,8 @@ class MessageActionsInterceptor {
|
|
111
111
|
// {"updateconversation" : false, messagelabel: {key: "TOUCHING_OPERATOR"}}
|
112
112
|
// );
|
113
113
|
|
114
|
+
}).catch((err) => {
|
115
|
+
winston.error("(MessageActionsInterceptor) route request error ", err)
|
114
116
|
});
|
115
117
|
// });
|
116
118
|
} else {
|
@@ -135,7 +135,9 @@ devi mandare un messaggio welcome tu altrimenti il bot inserito successivamente
|
|
135
135
|
|
136
136
|
// botprefix
|
137
137
|
// removeParticipantByRequestId(request_id, id_project, member)
|
138
|
-
requestService.removeParticipantByRequestId(request.request_id, request.id_project,"bot_"+botId )
|
138
|
+
requestService.removeParticipantByRequestId(request.request_id, request.id_project,"bot_"+botId ).catch((err) => {
|
139
|
+
winston.error("(ConciergeBot) removeParticipantByRequestId error", err)
|
140
|
+
});
|
139
141
|
}
|
140
142
|
}
|
141
143
|
|
@@ -877,7 +877,9 @@ class RulesTrigger {
|
|
877
877
|
winston.debug('runAction action id_project: ' + id_project);
|
878
878
|
|
879
879
|
// removeParticipantByRequestId(request_id, id_project, member) {
|
880
|
-
requestService.removeParticipantByRequestId(request_id, id_project, member)
|
880
|
+
requestService.removeParticipantByRequestId(request_id, id_project, member).catch((err) => {
|
881
|
+
winston.error("(RulesTrigger) removeParticipantByRequestId error", err)
|
882
|
+
});
|
881
883
|
|
882
884
|
} catch(e) {
|
883
885
|
winston.error("Error runAction", e);
|
package/routes/files.js
CHANGED
@@ -31,8 +31,7 @@ curl -u andrea.leo@f21.it:123456 \
|
|
31
31
|
|
32
32
|
router.post('/users', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], upload.single('file'), (req, res, next) => {
|
33
33
|
|
34
|
-
|
35
|
-
winston.info("files/users")
|
34
|
+
winston.verbose("files/users")
|
36
35
|
return res.status(201).json({
|
37
36
|
message: 'File uploded successfully',
|
38
37
|
filename: req.file.filename
|
package/routes/request.js
CHANGED
@@ -187,6 +187,9 @@ router.post('/',
|
|
187
187
|
return res.json(savedRequest);
|
188
188
|
// });
|
189
189
|
// });
|
190
|
+
}).catch((err) => {
|
191
|
+
winston.error("(Request) create request error ", err)
|
192
|
+
return res.status(500).send({ success: false, message: "Unable to create request", err: err })
|
190
193
|
});
|
191
194
|
|
192
195
|
|
@@ -417,13 +420,21 @@ router.put('/:requestid/participants', function (req, res) {
|
|
417
420
|
// TODO make a synchronous chat21 version (with query parameter?) with request.support_group.created
|
418
421
|
router.delete('/:requestid/participants/:participantid', function (req, res) {
|
419
422
|
winston.debug(req.body);
|
420
|
-
|
423
|
+
console.log("\n/:requestid/participants/:participantid");
|
424
|
+
console.log("Body:", req.body);
|
425
|
+
console.log("Headers:", req.headers);
|
426
|
+
console.log("Full URL:", `${req.protocol}://${req.get('host')}${req.originalUrl}`);
|
427
|
+
console.log("Requestid:", req.params.requestid);
|
428
|
+
console.log("Participantid:", req.params.participantid);
|
421
429
|
//removeParticipantByRequestId(request_id, id_project, member)
|
422
430
|
return requestService.removeParticipantByRequestId(req.params.requestid, req.projectid, req.params.participantid).then(function (updatedRequest) {
|
423
431
|
|
424
432
|
winston.verbose("participant removed", updatedRequest);
|
425
433
|
|
426
434
|
return res.json(updatedRequest);
|
435
|
+
}).catch((err) => {
|
436
|
+
winston.error("(Request) removeParticipantByRequestId error", err)
|
437
|
+
return res.status(400).send({ success: false, error: "Unable to removed the participant " + req.params.participantid + " from the request " + req.params.requestid})
|
427
438
|
});
|
428
439
|
|
429
440
|
|