@tiledesk/tiledesk-server 2.3.6 → 2.3.7-1.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/.github/workflows/docker-community-worker-push-latest.yml +23 -0
- package/.github/workflows/docker-image-tag-worker-community-tag-push.yml +22 -0
- package/CHANGELOG.md +361 -3
- package/Dockerfile-jobs +31 -0
- package/app.js +62 -69
- package/channels/chat21/chat21Handler.js +37 -6
- package/channels/chat21/chat21WebHook.js +62 -34
- package/channels/chat21/package-lock.json +663 -706
- package/channels/chat21/package.json +2 -2
- package/config/labels/widget.json +337 -136
- package/deploy.sh +2 -0
- package/event/messageEvent.js +110 -9
- package/jobs.js +80 -0
- package/jobsManager.js +47 -0
- package/middleware/has-role.js +10 -3
- package/middleware/ipFilter.js +220 -0
- package/middleware/passport.js +8 -2
- package/models/department.js +1 -1
- package/models/faq.js +77 -25
- package/models/faq_kb.js +19 -0
- package/models/message.js +10 -8
- package/models/project.js +10 -0
- package/models/project_user.js +10 -0
- package/models/request.js +12 -1
- package/package.json +12 -11
- package/pubmodules/activities/activityArchiver.js +216 -90
- package/pubmodules/activities/routes/activity.js +1 -1
- package/pubmodules/apps/index.js +8 -0
- package/pubmodules/apps/listener.js +27 -0
- package/pubmodules/cache/index.js +2 -0
- package/pubmodules/cache/mongoose-cachegoose-fn.js +630 -0
- package/pubmodules/canned/cannedResponse.js +4 -0
- package/pubmodules/canned/cannedResponseRoute.js +10 -5
- package/pubmodules/dialogflow/index.js +10 -0
- package/pubmodules/dialogflow/listener.js +66 -0
- package/pubmodules/emailNotification/requestNotification.js +58 -28
- package/pubmodules/events/eventRoute.js +49 -24
- package/pubmodules/messageTransformer/messageHandlebarsTransformerInterceptor.js +6 -1
- package/pubmodules/messageTransformer/messageTransformerInterceptor.js +10 -4
- package/pubmodules/pubModulesManager.js +173 -7
- package/pubmodules/queue/index.js +4 -0
- package/pubmodules/queue/reconnect.js +331 -0
- package/pubmodules/queue/reconnectFanout.js +256 -0
- package/pubmodules/rasa/listener.js +5 -5
- package/pubmodules/routing-queue/index.js +3 -0
- package/pubmodules/routing-queue/listener.js +328 -0
- package/pubmodules/rules/conciergeBot.js +2 -2
- package/pubmodules/scheduler/tasks/closeAgentUnresponsiveRequestTask.js +6 -1
- package/pubmodules/scheduler/tasks/closeBotUnresponsiveRequestTask.js +7 -1
- package/pubmodules/tilebot/index.js +11 -0
- package/pubmodules/tilebot/listener.js +85 -0
- package/pubmodules/trigger/rulesTrigger.js +137 -14
- package/pubmodules/trigger/start.js +5 -1
- package/pubmodules/whatsapp/index.js +7 -0
- package/pubmodules/whatsapp/listener.js +32 -0
- package/routes/auth.js +7 -2
- package/routes/campaigns.js +3 -3
- package/routes/department.js +3 -2
- package/routes/email.js +32 -2
- package/routes/faq.js +37 -2
- package/routes/faq_kb.js +496 -133
- package/routes/faqpub.js +5 -0
- package/routes/lead.js +56 -0
- package/routes/message.js +196 -14
- package/routes/messagesRoot.js +39 -0
- package/routes/project.js +76 -4
- package/routes/project_user.js +11 -1
- package/routes/project_user_test.js +19 -0
- package/routes/request.js +134 -30
- package/routes/troubleshooting.js +12 -0
- package/routes/users-util.js +39 -0
- package/routes/users.js +1 -1
- package/routes/widget.js +64 -2
- package/services/BotSubscriptionNotifier.js +5 -0
- package/services/banUserNotifier.js +86 -0
- package/services/cacheEnabler.js +56 -0
- package/services/chatbotService.js +101 -0
- package/services/departmentService.js +25 -3
- package/services/emailService.js +170 -28
- package/services/faqBotHandler.js +2 -3
- package/services/faqService.js +28 -3
- package/services/geoService.js +36 -6
- package/services/labelService.js +1 -1
- package/services/leadService.js +3 -2
- package/services/messageService.js +4 -2
- package/services/modulesManager.js +23 -76
- package/services/operatingHoursService.js +9 -4
- package/services/requestService.js +75 -39
- package/services/subscriptionNotifier.js +9 -4
- package/services/trainingService.js +106 -0
- package/template/email/assignedEmailMessage.html +21 -11
- package/template/email/assignedRequest.html +21 -11
- package/template/email/beenInvitedExistingUser.html +16 -6
- package/template/email/beenInvitedNewUser.html +16 -6
- package/template/email/emailDirect.html +130 -0
- package/template/email/newMessage.html +18 -8
- package/template/email/newMessageFollower.html +22 -12
- package/template/email/passwordChanged.html +15 -5
- package/template/email/pooledEmailMessage.html +21 -11
- package/template/email/pooledRequest.html +20 -10
- package/template/email/resetPassword.html +15 -5
- package/template/email/sendTranscript.html +7 -4
- package/template/email/ticket.html +17 -7
- package/template/email/verify.html +15 -5
- package/test/cannedRoute.js +157 -0
- package/test/chatbot-mock.js +127 -0
- package/test/example-json-intents.txt +1 -0
- package/test/example-json.txt +1 -0
- package/test/example.json +1 -0
- package/test/faqRoute.js +353 -208
- package/test/faqkbRoute.js +669 -64
- package/test/imageRoute.js +1 -1
- package/test/messageRoute.js +387 -5
- package/test/requestRoute.js +6 -6
- package/test/requestService.js +55 -4
- package/test-int/cache-project.js +90 -0
- package/test-int/cache-project_user.js +88 -0
- package/utils/UIDGenerator.js +20 -0
- package/utils/cacheUtil.js +2 -2
- package/utils/orgUtil.js +3 -3
- package/utils/promiseUtil.js +31 -0
- package/utils/recipientEmailUtil.js +66 -0
- package/utils/sendEmailUtil.js +34 -0
- package/utils/sendMessageUtil.js +1 -1
- package/utils/stringUtil.js +12 -0
- package/websocket/webSocketServer.js +33 -10
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const botEvent = require('../../event/botEvent');
|
|
2
|
+
var Faq_kb = require("../../models/faq_kb");
|
|
3
|
+
var winston = require('../../config/winston');
|
|
4
|
+
var configGlobal = require('../../config/global');
|
|
5
|
+
|
|
6
|
+
var port = process.env.PORT || '3000';
|
|
7
|
+
|
|
8
|
+
const TILEBOT_ENDPOINT = process.env.TILEBOT_ENDPOINT || "http://localhost:" + port+ "/modules/tilebot/ext/";
|
|
9
|
+
winston.debug("TILEBOT_ENDPOINT: " + TILEBOT_ENDPOINT);
|
|
10
|
+
|
|
11
|
+
winston.info("Tilebot endpoint: " + TILEBOT_ENDPOINT);
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const apiUrl = process.env.API_URL || configGlobal.apiUrl;
|
|
15
|
+
winston.info('Rasa apiUrl: '+ apiUrl);
|
|
16
|
+
|
|
17
|
+
const tybot = require("@tiledesk/tiledesk-tybot-connector");
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Listener {
|
|
21
|
+
|
|
22
|
+
listen(config) {
|
|
23
|
+
|
|
24
|
+
winston.info('Tilebot Listener listen');
|
|
25
|
+
winston.debug("Tilebot config databaseUri: " + config.databaseUri);
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
var that = this;
|
|
29
|
+
|
|
30
|
+
var port = process.env.CACHE_REDIS_PORT || 6379;
|
|
31
|
+
winston.debug("Redis port: "+ port);
|
|
32
|
+
|
|
33
|
+
var host = process.env.CACHE_REDIS_HOST || "127.0.0.1"
|
|
34
|
+
winston.debug("Redis host: "+ host);
|
|
35
|
+
|
|
36
|
+
var password = process.env.CACHE_REDIS_PASSWORD;
|
|
37
|
+
winston.debug("Redis password: "+ password);
|
|
38
|
+
|
|
39
|
+
// console.log("Using: REDIS_HOST:", process.env.CACHE_REDIS_HOST);
|
|
40
|
+
// console.log("Using: REDIS_PORT", process.env.CACHE_REDIS_PORT);
|
|
41
|
+
// console.log("Using: REDIS_PASSWORD", process.env.CACHE_REDIS_PASSWORD);
|
|
42
|
+
tybot.startApp(
|
|
43
|
+
{
|
|
44
|
+
MONGODB_URI: config.databaseUri,
|
|
45
|
+
API_ENDPOINT: apiUrl,
|
|
46
|
+
REDIS_HOST: host,
|
|
47
|
+
REDIS_PORT: port,
|
|
48
|
+
REDIS_PASSWORD: password,
|
|
49
|
+
CACHE_ENABLED: process.env.CACHE_ENABLED,
|
|
50
|
+
log: process.env.TILEBOT_LOG
|
|
51
|
+
}, () => {
|
|
52
|
+
winston.info("TileBot proxy server successfully started.");
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
botEvent.on('faqbot.create', function(bot) {
|
|
58
|
+
if (TILEBOT_ENDPOINT) {
|
|
59
|
+
|
|
60
|
+
winston.debug('bot.type:'+bot.type);
|
|
61
|
+
if (bot.type==="tilebot") {
|
|
62
|
+
|
|
63
|
+
winston.debug('qui.type:'+bot.type);
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
Faq_kb.findByIdAndUpdate(bot.id, {"url":TILEBOT_ENDPOINT+bot.id}, { new: true, upsert: true }, function (err, savedFaq_kb) {
|
|
67
|
+
|
|
68
|
+
// bot.save(function (err, savedFaq_kb) {
|
|
69
|
+
if (err) {
|
|
70
|
+
return winston.error('error saving faqkb tilebot ', err)
|
|
71
|
+
}
|
|
72
|
+
winston.verbose('Saved faqkb tilebot', savedFaq_kb.toObject())
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var listener = new Listener();
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
module.exports = listener;
|
|
@@ -18,11 +18,11 @@ var leadService = require('../../services/leadService');
|
|
|
18
18
|
var LeadConstants = require('../../models/leadConstants');
|
|
19
19
|
var operatingHoursService = require("../../services/operatingHoursService");
|
|
20
20
|
var sendMessageUtil = require("../../utils/sendMessageUtil");
|
|
21
|
+
var sendEmailUtil = require("../../utils/sendEmailUtil");
|
|
21
22
|
var cacheUtil = require("../../utils/cacheUtil");
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const uuidv4 = require('uuid/v4');
|
|
23
|
+
var cacheEnabler = require("../../services/cacheEnabler");
|
|
24
|
+
var UIDGenerator = require("../../utils/UIDGenerator");
|
|
25
|
+
const RequestConstants = require('../../models/requestConstants');
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
class RulesTrigger {
|
|
@@ -54,6 +54,10 @@ class RulesTrigger {
|
|
|
54
54
|
setImmediate(() => {
|
|
55
55
|
|
|
56
56
|
requestEvent.on('request.support_group.created', function(request) {
|
|
57
|
+
|
|
58
|
+
// performance console log
|
|
59
|
+
// console.log("************* request.support_group.created: "+new Date().toISOString());
|
|
60
|
+
|
|
57
61
|
// requestEvent.on('request.create', function(request) {
|
|
58
62
|
var requestJson = request.toJSON();
|
|
59
63
|
operatingHoursService.projectIsOpenNow(request.id_project, function (isOpen, err) {
|
|
@@ -63,6 +67,9 @@ class RulesTrigger {
|
|
|
63
67
|
});
|
|
64
68
|
});
|
|
65
69
|
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// da aggiungere in dashboard
|
|
66
73
|
requestEvent.on('request.participants.join', function(data) {
|
|
67
74
|
let request = data.request;
|
|
68
75
|
let member = data.member;
|
|
@@ -80,10 +87,10 @@ class RulesTrigger {
|
|
|
80
87
|
// operatingHoursService.projectIsOpenNow(request.id_project, function (isOpen, err) {
|
|
81
88
|
that.exec(message, 'message.create.from.requester', success, error);
|
|
82
89
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
|
|
91
|
+
messageEvent.on('message.received', function(message) {
|
|
92
|
+
that.exec(message, 'message.received', success, error);
|
|
93
|
+
});
|
|
87
94
|
|
|
88
95
|
// event2Event.on('*', function(event){
|
|
89
96
|
// winston.verbose('event2Event this.event: ' + this.event);
|
|
@@ -174,6 +181,9 @@ class RulesTrigger {
|
|
|
174
181
|
// attributes
|
|
175
182
|
// );
|
|
176
183
|
|
|
184
|
+
// performance console log
|
|
185
|
+
// console.log("************* send message trigger: "+new Date().toISOString(), text);
|
|
186
|
+
|
|
177
187
|
// send(sender, senderFullname, recipient, text, id_project, createdBy, attributes, type, metadata, language) {
|
|
178
188
|
sendMessageUtil.send(
|
|
179
189
|
sender,
|
|
@@ -193,6 +203,93 @@ class RulesTrigger {
|
|
|
193
203
|
|
|
194
204
|
|
|
195
205
|
|
|
206
|
+
triggerEventEmitter.on('email.send', function(eventTrigger) {
|
|
207
|
+
|
|
208
|
+
try {
|
|
209
|
+
|
|
210
|
+
winston.debug('runAction eventTrigger.eventSuccess:', eventTrigger.eventSuccess);
|
|
211
|
+
var trigger = eventTrigger.trigger;
|
|
212
|
+
winston.debug('runAction trigger', trigger.toObject());
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
var action = eventTrigger.action;
|
|
216
|
+
winston.debug('runAction action', action.toObject());
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
var fullname = action.parameters.fullName || "BOT";
|
|
220
|
+
winston.debug('runAction action fullname: ' + fullname);
|
|
221
|
+
|
|
222
|
+
var subject = action.parameters.subject || "New Email";
|
|
223
|
+
|
|
224
|
+
winston.debug('runAction action subject: ' + subject);
|
|
225
|
+
|
|
226
|
+
var sender = "system";
|
|
227
|
+
|
|
228
|
+
if (action.parameters.sender) {
|
|
229
|
+
sender = action.parameters.sender;
|
|
230
|
+
}
|
|
231
|
+
winston.debug('runAction action sender: ' + sender);
|
|
232
|
+
|
|
233
|
+
var text = action.parameters.text;
|
|
234
|
+
winston.debug('runAction action text: ' + text);
|
|
235
|
+
|
|
236
|
+
var attributes = {};
|
|
237
|
+
|
|
238
|
+
// var attributes = action.parameters.attributes;
|
|
239
|
+
// winston.debug('runAction action attributes: ' + attributes);
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
var recipient;
|
|
243
|
+
if (eventTrigger.eventKey=="request.create" || eventTrigger.eventKey=="request.participants.join") {
|
|
244
|
+
recipient = eventTrigger.event.request_id;
|
|
245
|
+
}
|
|
246
|
+
if (eventTrigger.eventKey=="message.create.from.requester" || eventTrigger.eventKey=="message.received") {
|
|
247
|
+
recipient = eventTrigger.event.recipient;
|
|
248
|
+
|
|
249
|
+
//custom ocf here
|
|
250
|
+
if (eventTrigger.event.id_project =="636a63070d942d001950c023") {
|
|
251
|
+
subject = "Apertura richiesta di supporto #" + eventTrigger.event.request.ticket_id;
|
|
252
|
+
console.log("subject",subject);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
if (eventTrigger.eventKey=="event.emit") {
|
|
257
|
+
winston.debug('runAction action event.emit: ', eventTrigger.event.toObject());
|
|
258
|
+
|
|
259
|
+
//TODO funziona?
|
|
260
|
+
recipient = eventTrigger.event.project_user.id_user;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// console.log("eventTrigger.event", eventTrigger.event);
|
|
264
|
+
|
|
265
|
+
winston.debug('runAction action recipient: ' + recipient);
|
|
266
|
+
|
|
267
|
+
var id_project = eventTrigger.event.id_project;
|
|
268
|
+
winston.debug('runAction action id_project: ' + id_project);
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
var message = eventTrigger.event;
|
|
272
|
+
winston.debug('runAction action message: ', message);
|
|
273
|
+
|
|
274
|
+
if (eventTrigger.event.request && eventTrigger.event.request.lead && eventTrigger.event.request.lead.email) {
|
|
275
|
+
var to = eventTrigger.event.request.lead.email;
|
|
276
|
+
winston.debug('to ' + to);
|
|
277
|
+
|
|
278
|
+
// sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage) {
|
|
279
|
+
sendEmailUtil.sendEmailDirect(to, text, id_project, recipient, subject, message);
|
|
280
|
+
} else {
|
|
281
|
+
winston.info('email.send trigger. Lead email is undefined ');
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
} catch(e) {
|
|
286
|
+
winston.error("Error runAction", e);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
196
293
|
|
|
197
294
|
|
|
198
295
|
triggerEventEmitter.on('request.department.route', function(eventTrigger) {
|
|
@@ -675,12 +772,14 @@ class RulesTrigger {
|
|
|
675
772
|
var departmentid = action.parameters.departmentid;
|
|
676
773
|
winston.debug('runAction action departmentid: ' + departmentid);
|
|
677
774
|
|
|
775
|
+
var participants = action.parameters.participants;
|
|
776
|
+
winston.debug('runAction action participants: ' + participants);
|
|
678
777
|
// var attributes = action.parameters.attributes;
|
|
679
778
|
// winston.debug('runAction action attributes: ' + attributes);
|
|
680
779
|
|
|
681
780
|
|
|
682
781
|
|
|
683
|
-
var request_id = 'support-group-'+id_project+"-"+
|
|
782
|
+
var request_id = 'support-group-'+id_project+"-"+UIDGenerator.generate();
|
|
684
783
|
var id_user;
|
|
685
784
|
var fullname;
|
|
686
785
|
var email;
|
|
@@ -760,10 +859,24 @@ class RulesTrigger {
|
|
|
760
859
|
departmentid = eventAttributes.department;
|
|
761
860
|
}
|
|
762
861
|
|
|
862
|
+
|
|
863
|
+
|
|
763
864
|
if (eventAttributes.text) {
|
|
764
865
|
text = eventAttributes.text;
|
|
765
866
|
}
|
|
766
867
|
|
|
868
|
+
// console.log("eventAttributes.participants.length"+ eventAttributes.participants.length);
|
|
869
|
+
if (eventAttributes.participants && eventAttributes.participants.length>0) {
|
|
870
|
+
participants = eventAttributes.participants;
|
|
871
|
+
if (participants[0].indexOf("bot_")>-1) {
|
|
872
|
+
text = "\\start"; //if participants is passed than the bot reply to the first message "welcome" so I changed "welcome" with "\start"
|
|
873
|
+
}
|
|
874
|
+
// status = RequestConstants.ASSIGNED;
|
|
875
|
+
// console.log("eventAttributes.participants",eventAttributes.participants);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// console.log("text", text);
|
|
879
|
+
|
|
767
880
|
if (eventAttributes.status) {
|
|
768
881
|
status = eventAttributes.status;
|
|
769
882
|
}
|
|
@@ -856,7 +969,7 @@ class RulesTrigger {
|
|
|
856
969
|
|
|
857
970
|
var new_request = {
|
|
858
971
|
request_id: request_id, project_user_id: project_user_id, lead_id: createdLead._id, id_project: id_project,
|
|
859
|
-
first_text: text, departmentid: departmentid, sourcePage: sourcePage,
|
|
972
|
+
first_text: text, participants: participants, departmentid: departmentid, sourcePage: sourcePage,
|
|
860
973
|
language: language, userAgent: userAgent, status: status, createdBy: id_user,
|
|
861
974
|
attributes: attributes, subject: undefined, preflight: preflight, channel: undefined, location: undefined,
|
|
862
975
|
lead: createdLead, requester: puser
|
|
@@ -864,12 +977,14 @@ class RulesTrigger {
|
|
|
864
977
|
|
|
865
978
|
return requestService.create(new_request).then(function (savedRequest) {
|
|
866
979
|
|
|
980
|
+
// performance console log
|
|
981
|
+
// console.log("************* request created trigger: "+new Date().toISOString());
|
|
867
982
|
|
|
868
983
|
if (attributes) {
|
|
869
984
|
attributes.sendnotification = false; // sembra nn funzionae
|
|
870
985
|
}
|
|
871
986
|
|
|
872
|
-
var senderFullname = fullname || 'Guest';
|
|
987
|
+
var senderFullname = fullname || 'Guest'; // guest_here
|
|
873
988
|
|
|
874
989
|
// create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language) {
|
|
875
990
|
return messageService.create( id_user, senderFullname , savedRequest.request_id, text,
|
|
@@ -925,9 +1040,17 @@ class RulesTrigger {
|
|
|
925
1040
|
|
|
926
1041
|
winston.debug('trigger query', query);
|
|
927
1042
|
|
|
928
|
-
Trigger.find(query)
|
|
929
|
-
|
|
930
|
-
|
|
1043
|
+
let q = Trigger.find(query);
|
|
1044
|
+
|
|
1045
|
+
if (cacheEnabler.trigger) {
|
|
1046
|
+
q.cache(cacheUtil.longTTL, event.id_project+":triggers:trigger.key:"+eventKey) //CACHE_TRIGGER
|
|
1047
|
+
winston.debug('trigger cache enabled');
|
|
1048
|
+
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
q.exec(function(err, triggers) {
|
|
1052
|
+
|
|
1053
|
+
|
|
931
1054
|
if (err) {
|
|
932
1055
|
winston.error('Error gettting bots ', err);
|
|
933
1056
|
return 0;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const whatsapp = require("@tiledesk/tiledesk-whatsapp-connector");
|
|
2
|
+
var winston = require('../../config/winston');
|
|
3
|
+
var configGlobal = require('../../config/global');
|
|
4
|
+
|
|
5
|
+
const apiUrl = process.env.API_URL || configGlobal.apiUrl;
|
|
6
|
+
winston.info('Whatsapp apiUrl: ' + apiUrl);
|
|
7
|
+
|
|
8
|
+
class Listener {
|
|
9
|
+
|
|
10
|
+
listen(config) {
|
|
11
|
+
winston.info("WhatsApp Listener listen");
|
|
12
|
+
if (config.databaseUri) {
|
|
13
|
+
winston.debug("whatsapp config databaseUri: " + config.databaseUri);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
whatsapp.startApp({
|
|
17
|
+
MONGODB_URL: config.databaseUri,
|
|
18
|
+
API_URL: apiUrl,
|
|
19
|
+
GRAPH_URL: process.env.META_GRAPH_URL || config.graphUrl,
|
|
20
|
+
BASE_URL: apiUrl + "/modules/whatsapp",
|
|
21
|
+
APPS_API_URL: apiUrl + "/modules/apps",
|
|
22
|
+
log: process.env.WHATSAPP_LOG
|
|
23
|
+
}, () => {
|
|
24
|
+
winston.info("Tiledesk WhatsApp Connector proxy server succesfully started.");
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var listener = new Listener();
|
|
31
|
+
|
|
32
|
+
module.exports = listener;
|
package/routes/auth.js
CHANGED
|
@@ -112,13 +112,18 @@ function (req, res) {
|
|
|
112
112
|
winston.error("SigninAnonymously validation error", {errors: errors, reqBody: req.body, reqUrl: req.url });
|
|
113
113
|
return res.status(422).json({ errors: errors.array() });
|
|
114
114
|
}
|
|
115
|
-
|
|
115
|
+
|
|
116
|
+
let uid = uuidv4();
|
|
117
|
+
let shortuid = uid.substring(0,4);
|
|
118
|
+
var firstname = req.body.firstname || "guest#"+shortuid; // guest_here
|
|
119
|
+
// var firstname = req.body.firstname || "Guest"; // guest_here
|
|
120
|
+
|
|
116
121
|
|
|
117
122
|
|
|
118
123
|
//TODO togli trattini da uuidv4()
|
|
119
124
|
|
|
120
125
|
// TODO remove email.sec?
|
|
121
|
-
let userAnonym = {_id:
|
|
126
|
+
let userAnonym = {_id: uid, firstname:firstname, lastname: req.body.lastname, email: req.body.email, attributes: req.body.attributes};
|
|
122
127
|
|
|
123
128
|
req.user = UserUtil.decorateUser(userAnonym);
|
|
124
129
|
|
package/routes/campaigns.js
CHANGED
|
@@ -6,8 +6,7 @@ var winston = require('../config/winston');
|
|
|
6
6
|
var requestService = require("../services/requestService");
|
|
7
7
|
var messageService = require("../services/messageService");
|
|
8
8
|
var MessageConstants = require("../models/messageConstants");
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
var UIDGenerator = require("../utils/UIDGenerator");
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
|
|
@@ -19,7 +18,7 @@ router.post('/', function (req, res) {
|
|
|
19
18
|
|
|
20
19
|
winston.debug(req.body);
|
|
21
20
|
winston.debug("req.user", req.user);
|
|
22
|
-
var request_id = req.body.request_id || 'support-group-' + req.projectid + "-" +
|
|
21
|
+
var request_id = req.body.request_id || 'support-group-' + req.projectid + "-" + UIDGenerator.generate();
|
|
23
22
|
|
|
24
23
|
// TODO cicla su segment
|
|
25
24
|
|
|
@@ -73,6 +72,7 @@ router.post('/direct', async function (req, res) {
|
|
|
73
72
|
|
|
74
73
|
}
|
|
75
74
|
|
|
75
|
+
|
|
76
76
|
winston.info("recipients", recipients);
|
|
77
77
|
winston.info("recipients.length: " + recipients.length);
|
|
78
78
|
|
package/routes/department.js
CHANGED
|
@@ -175,7 +175,8 @@ router.get('/allstatus', [passport.authenticate(['basic', 'jwt'], { session: fal
|
|
|
175
175
|
|
|
176
176
|
winston.debug("## GET ALL DEPTS req.project ", req.project)
|
|
177
177
|
|
|
178
|
-
var query = { "id_project": req.projectid };
|
|
178
|
+
var query = { "id_project": req.projectid, status: { $gte: 0 } }; // nascondi quelli con status = hidden (-1) for dashboard
|
|
179
|
+
//secondo me qui manca un parentesi tonda per gli or
|
|
179
180
|
if (req.project && req.project.profile && (req.project.profile.type === 'free' && req.project.trialExpired === true) || (req.project.profile.type === 'payment' && req.project.isActiveSubscription === false)) {
|
|
180
181
|
|
|
181
182
|
query.default = true;
|
|
@@ -270,7 +271,7 @@ router.get('/', function (req, res) {
|
|
|
270
271
|
winston.debug('GET DEPTS FILTERED FOR STATUS === 1 req.project.profile.type ', req.project.trialExpired);
|
|
271
272
|
winston.debug('GET DEPTS FILTERED FOR STATUS === 1 req.project.isActiveSubscription ', req.project.isActiveSubscription);
|
|
272
273
|
|
|
273
|
-
|
|
274
|
+
//secondo me qui manca un parentesi tonda per gli or
|
|
274
275
|
if (req.project && req.project.profile && (req.project.profile.type === 'free' && req.project.trialExpired === true) || (req.project.profile.type === 'payment' && req.project.isActiveSubscription === false)) {
|
|
275
276
|
|
|
276
277
|
query.default = true;
|
package/routes/email.js
CHANGED
|
@@ -4,6 +4,9 @@ var router = express.Router();
|
|
|
4
4
|
|
|
5
5
|
var emailService = require("../services/emailService");
|
|
6
6
|
var winston = require('../config/winston');
|
|
7
|
+
const recipientEmailUtil = require("../utils/recipientEmailUtil");
|
|
8
|
+
|
|
9
|
+
|
|
7
10
|
|
|
8
11
|
router.get('/templates/:templateid',
|
|
9
12
|
async (req, res) => {
|
|
@@ -17,10 +20,10 @@ router.get('/templates/:templateid',
|
|
|
17
20
|
router.post('/test/send',
|
|
18
21
|
async (req, res) => {
|
|
19
22
|
let to = req.body.to;
|
|
20
|
-
winston.
|
|
23
|
+
winston.debug("to",to);
|
|
21
24
|
|
|
22
25
|
let configEmail = req.body.config;
|
|
23
|
-
winston.
|
|
26
|
+
winston.debug("configEmail", configEmail);
|
|
24
27
|
|
|
25
28
|
emailService.sendTest(to, configEmail, function(err,obj) {
|
|
26
29
|
// winston.info("sendTest rest", err, obj);
|
|
@@ -29,4 +32,31 @@ router.post('/test/send',
|
|
|
29
32
|
|
|
30
33
|
});
|
|
31
34
|
|
|
35
|
+
//TODO add cc
|
|
36
|
+
router.post('/send',
|
|
37
|
+
async (req, res) => {
|
|
38
|
+
let to = req.body.to;
|
|
39
|
+
winston.debug("to: " + to);
|
|
40
|
+
|
|
41
|
+
let text = req.body.text;
|
|
42
|
+
winston.debug("text: " + text);
|
|
43
|
+
|
|
44
|
+
let request_id = req.body.request_id;
|
|
45
|
+
winston.debug("request_id: " + request_id);
|
|
46
|
+
|
|
47
|
+
let subject = req.body.subject;
|
|
48
|
+
winston.debug("subject: " + subject);
|
|
49
|
+
|
|
50
|
+
winston.debug("req.project", req.project);
|
|
51
|
+
|
|
52
|
+
let newto = await recipientEmailUtil.process(to, req.projectid);
|
|
53
|
+
winston.debug("newto: " + newto);
|
|
54
|
+
|
|
55
|
+
//sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage)
|
|
56
|
+
emailService.sendEmailDirect(newto, text, req.project, request_id, subject, undefined, undefined);
|
|
57
|
+
|
|
58
|
+
res.json({"queued": true});
|
|
59
|
+
|
|
60
|
+
});
|
|
61
|
+
|
|
32
62
|
module.exports = router;
|
package/routes/faq.js
CHANGED
|
@@ -61,6 +61,7 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
|
|
|
61
61
|
// var row = {question: element.question, answer: element.answer,
|
|
62
62
|
// intent_id: element.intent_id, intent_display_name: element.intent_display_name,
|
|
63
63
|
// webhook_enabled: element.webhook_enabled || false }
|
|
64
|
+
|
|
64
65
|
var newFaq = new Faq({
|
|
65
66
|
id_faq_kb: id_faq_kb,
|
|
66
67
|
question: question,
|
|
@@ -114,6 +115,9 @@ router.post('/', function (req, res) {
|
|
|
114
115
|
id_faq_kb: req.body.id_faq_kb,
|
|
115
116
|
question: req.body.question,
|
|
116
117
|
answer: req.body.answer,
|
|
118
|
+
reply: req.body.reply,
|
|
119
|
+
form: req.body.form,
|
|
120
|
+
enabled: true,
|
|
117
121
|
id_project: req.projectid,
|
|
118
122
|
topic: req.body.topic,
|
|
119
123
|
language: faq_kb.language,
|
|
@@ -123,6 +127,13 @@ router.post('/', function (req, res) {
|
|
|
123
127
|
updatedBy: req.user.id
|
|
124
128
|
});
|
|
125
129
|
|
|
130
|
+
if (req.body.enabled != undefined) {
|
|
131
|
+
newFaq.enabled = req.body.enabled;
|
|
132
|
+
}
|
|
133
|
+
if (req.body.actions) {
|
|
134
|
+
newFaq.actions = req.body.actions
|
|
135
|
+
}
|
|
136
|
+
|
|
126
137
|
newFaq.save(function (err, savedFaq) {
|
|
127
138
|
if (err) {
|
|
128
139
|
if (err.code == 11000) {
|
|
@@ -177,8 +188,18 @@ router.put('/:faqid', function (req, res) {
|
|
|
177
188
|
if (req.body.webhook_enabled!=undefined) {
|
|
178
189
|
update.webhook_enabled = req.body.webhook_enabled;
|
|
179
190
|
}
|
|
180
|
-
|
|
181
|
-
|
|
191
|
+
if (req.body.enabled!=undefined) {
|
|
192
|
+
update.enabled = req.body.enabled;
|
|
193
|
+
}
|
|
194
|
+
if (req.body.reply!=undefined) {
|
|
195
|
+
update.reply = req.body.reply;
|
|
196
|
+
}
|
|
197
|
+
if (req.body.form!=undefined) {
|
|
198
|
+
update.form = req.body.form;
|
|
199
|
+
}
|
|
200
|
+
if (req.body.actions != undefined) {
|
|
201
|
+
update.actions = req.body.actions;
|
|
202
|
+
}
|
|
182
203
|
|
|
183
204
|
Faq.findByIdAndUpdate(req.params.faqid, update, { new: true, upsert: true }, function (err, updatedFaq) {
|
|
184
205
|
if (err) {
|
|
@@ -299,10 +320,24 @@ router.get('/', function (req, res, next) {
|
|
|
299
320
|
query.id_project = req.projectid
|
|
300
321
|
}
|
|
301
322
|
|
|
323
|
+
if (req.query.intent_display_name) {
|
|
324
|
+
query.intent_display_name=req.query.intent_display_name
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
|
|
302
328
|
winston.debug("GET FAQ query", query);
|
|
303
329
|
|
|
304
330
|
// query.$text = {"$search": "question"};
|
|
305
331
|
|
|
332
|
+
// TODO ORDER BY SCORE
|
|
333
|
+
// return Faq.find(query, {score: { $meta: "textScore" } })
|
|
334
|
+
// .sort( { score: { $meta: "textScore" } } ) //https://docs.mongodb.com/manual/reference/operator/query/text/#sort-by-text-search-score
|
|
335
|
+
|
|
336
|
+
// in testing...
|
|
337
|
+
// return Faq.search('a closer', (err, result) => {
|
|
338
|
+
// console.log("result: ", result);
|
|
339
|
+
// })
|
|
340
|
+
|
|
306
341
|
return Faq.find(query).
|
|
307
342
|
skip(skip).limit(limit).
|
|
308
343
|
populate({path:'faq_kb'})//, match: { trashed: { $in: [null, false] } }}).
|