@tiledesk/tiledesk-server 2.5.3 → 2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/app.js +7 -1
- package/config/labels/widget.json +257 -252
- package/event/botEvent.js +24 -3
- package/jobs.js +9 -1
- package/jobsManager.js +13 -1
- package/middleware/fetchLabels.js +23 -13
- package/package.json +6 -4
- package/pubmodules/queue/reconnect.js +47 -0
- package/pubmodules/trigger/default.js +2 -2
- package/pubmodules/trigger/rulesTrigger.js +14 -2
- package/routes/kb.js +307 -62
- package/services/QuoteManager.js +26 -20
- package/services/Scheduler.js +33 -0
- package/services/openaiService.js +12 -11
- package/services/requestService.js +96 -92
- package/services/updateLeadQueued.js +149 -0
- package/test/TooManykbUrlsList.txt +304 -0
- package/test/kbRoute.js +331 -20
- package/test/kbUrlsList.txt +4 -0
- package/utils/jobs-worker-queue-manager/JobManagerV2.js +146 -0
- package/utils/jobs-worker-queue-manager/queueManagerClassV2.js +355 -0
@@ -4,7 +4,8 @@ require('dotenv').config();
|
|
4
4
|
|
5
5
|
let openai_endpoint = process.env.OPENAI_ENDPOINT;
|
6
6
|
let kb_endpoint = process.env.KB_ENDPOINT;
|
7
|
-
let
|
7
|
+
let kb_endpoint_train = process.env.KB_ENDPOINT_TRAIN;
|
8
|
+
let kb_endpoint_qa = process.env.KB_ENDPOINT_QA;
|
8
9
|
|
9
10
|
class OpenaiService {
|
10
11
|
|
@@ -100,12 +101,12 @@ class OpenaiService {
|
|
100
101
|
|
101
102
|
// PUGLIA AI V2
|
102
103
|
singleScrape(data) {
|
103
|
-
winston.debug("[OPENAI SERVICE] kb endpoint: " +
|
104
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_train);
|
104
105
|
|
105
106
|
return new Promise((resolve, reject) => {
|
106
107
|
|
107
108
|
axios({
|
108
|
-
url:
|
109
|
+
url: kb_endpoint_train + "/scrape/single",
|
109
110
|
headers: {
|
110
111
|
'Content-Type': 'application/json'
|
111
112
|
},
|
@@ -121,12 +122,12 @@ class OpenaiService {
|
|
121
122
|
}
|
122
123
|
|
123
124
|
scrapeStatus(data) {
|
124
|
-
winston.debug("[OPENAI SERVICE] kb endpoint: " +
|
125
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_train);
|
125
126
|
|
126
127
|
return new Promise((resolve, reject) => {
|
127
128
|
|
128
129
|
axios({
|
129
|
-
url:
|
130
|
+
url: kb_endpoint_train + "/scrape/status",
|
130
131
|
headers: {
|
131
132
|
'Content-Type': 'application/json'
|
132
133
|
},
|
@@ -141,12 +142,12 @@ class OpenaiService {
|
|
141
142
|
}
|
142
143
|
|
143
144
|
askNamespace(data) {
|
144
|
-
winston.debug("[OPENAI SERVICE] kb endpoint: " +
|
145
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_qa);
|
145
146
|
|
146
147
|
return new Promise((resolve, reject) => {
|
147
148
|
|
148
149
|
axios({
|
149
|
-
url:
|
150
|
+
url: kb_endpoint_qa + "/qa",
|
150
151
|
headers: {
|
151
152
|
'Content-Type': 'application/json'
|
152
153
|
},
|
@@ -162,12 +163,12 @@ class OpenaiService {
|
|
162
163
|
}
|
163
164
|
|
164
165
|
deleteIndex(data) {
|
165
|
-
winston.debug("[OPENAI SERVICE] kb endpoint: " +
|
166
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_train);
|
166
167
|
|
167
168
|
return new Promise((resolve, reject) => {
|
168
169
|
|
169
170
|
axios({
|
170
|
-
url:
|
171
|
+
url: kb_endpoint_train + "/delete/id",
|
171
172
|
headers: {
|
172
173
|
'Content-Type': 'application/json'
|
173
174
|
},
|
@@ -182,12 +183,12 @@ class OpenaiService {
|
|
182
183
|
}
|
183
184
|
|
184
185
|
deleteNamespace(data) {
|
185
|
-
winston.debug("[OPENAI SERVICE] kb endpoint: " +
|
186
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_train);
|
186
187
|
|
187
188
|
return new Promise((resolve, reject) => {
|
188
189
|
|
189
190
|
axios({
|
190
|
-
url:
|
191
|
+
url: kb_endpoint_train + "/delete/namespace",
|
191
192
|
headers: {
|
192
193
|
'Content-Type': 'application/json'
|
193
194
|
},
|
@@ -32,100 +32,104 @@ class RequestService {
|
|
32
32
|
}
|
33
33
|
|
34
34
|
listen() {
|
35
|
-
|
36
|
-
this.
|
35
|
+
// 12 marzo 2024 I disabled these two functions due to performance problems for a chatbot created by Sponziello "Community bots Sendinblue Hubspot Qapla)"
|
36
|
+
// this.updateSnapshotLead();
|
37
|
+
// this.sendMessageUpdateLead();
|
37
38
|
}
|
38
|
-
updateSnapshotLead() {
|
39
|
-
leadEvent.on('lead.update', function (lead) {
|
40
|
-
setImmediate(() => {
|
41
|
-
winston.debug("updateSnapshotLead on lead.update ", lead);
|
42
39
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
40
|
+
// 12 marzo 2024 I disabled these two functions due to performance problems for a chatbot created by Sponziello "Community bots Sendinblue Hubspot Qapla)"
|
41
|
+
// updateSnapshotLead() {
|
42
|
+
// leadEvent.on('lead.update', function (lead) {
|
43
|
+
// setImmediate(() => {
|
44
|
+
// winston.debug("updateSnapshotLead on lead.update ", lead);
|
45
|
+
|
46
|
+
// Request.updateMany({ lead: lead._id, id_project: lead.id_project }, { "$set": { "snapshot.lead": lead } }, function (err, updates) {
|
47
|
+
// if (err) {
|
48
|
+
// winston.error("Error updating requests updateSnapshotLead", err);
|
49
|
+
// return 0;
|
50
|
+
// }
|
51
|
+
// winston.verbose("updateSnapshotLead updated for " + updates.nModified + " request")
|
52
|
+
// requestEvent.emit('request.update.snapshot.lead', { lead: lead, updates: updates });
|
53
|
+
// return;
|
54
|
+
// });
|
55
|
+
// // Request.find({lead: lead._id, id_project: lead.id_project}, function(err, requests) {
|
56
|
+
|
57
|
+
// // if (err) {
|
58
|
+
// // winston.error("Error getting request by lead", err);
|
59
|
+
// // return 0;
|
60
|
+
// // }
|
61
|
+
// // if (!requests || (requests && requests.length==0)) {
|
62
|
+
// // winston.warn("No request found for lead id " +lead._id );
|
63
|
+
// // return 0;
|
64
|
+
// // }
|
65
|
+
|
66
|
+
// // requests.forEach(function(request) {
|
67
|
+
|
68
|
+
|
69
|
+
// // });
|
70
|
+
|
71
|
+
// // });
|
72
|
+
|
73
|
+
|
74
|
+
// });
|
75
|
+
// });
|
76
|
+
// }
|
77
|
+
|
78
|
+
|
79
|
+
// 12 marzo 2024 I disabled these two functions due to performance problems for a chatbot created by Sponziello "Community bots Sendinblue Hubspot Qapla)"
|
80
|
+
// sendMessageUpdateLead() {
|
81
|
+
// leadEvent.on('lead.fullname.email.update', function (lead) {
|
82
|
+
// winston.debug("lead.fullname.email.update ");
|
83
|
+
// // leadEvent.on('lead.update', function(lead) {
|
84
|
+
|
85
|
+
// setImmediate(() => {
|
86
|
+
// winston.debug("sendMessageUpdateLead on lead.update ", lead);
|
87
|
+
|
88
|
+
// Request.find({ lead: lead._id, id_project: lead.id_project }, function (err, requests) {
|
89
|
+
|
90
|
+
// if (err) {
|
91
|
+
// winston.error("Error getting sendMessageUpdateLead request by lead", err);
|
92
|
+
// return 0;
|
93
|
+
// }
|
94
|
+
// if (!requests || (requests && requests.length == 0)) {
|
95
|
+
// winston.warn("sendMessageUpdateLead No request found for lead id " + lead._id);
|
96
|
+
// return 0;
|
97
|
+
// }
|
98
|
+
|
99
|
+
// // winston.info("sendMessageUpdateLead requests ", requests);
|
100
|
+
|
101
|
+
// requests.forEach(function (request) {
|
102
|
+
|
103
|
+
// winston.debug("sendMessageUpdateLead request ", request);
|
104
|
+
|
105
|
+
// // send(sender, senderFullname, recipient, text, id_project, createdBy, attributes, type, metadata, language)
|
106
|
+
// messageService.send(
|
107
|
+
// 'system',
|
108
|
+
// 'Bot',
|
109
|
+
// // lead.fullname,
|
110
|
+
// request.request_id,
|
111
|
+
// "Lead updated",
|
112
|
+
// request.id_project,
|
113
|
+
// 'system',
|
114
|
+
// {
|
115
|
+
// subtype: "info/support",
|
116
|
+
// "updateconversation": false,
|
117
|
+
// messagelabel: { key: "LEAD_UPDATED" },
|
118
|
+
// updateUserEmail: lead.email,
|
119
|
+
// updateUserFullname: lead.fullname
|
120
|
+
// },
|
121
|
+
// undefined,
|
122
|
+
// request.language
|
123
|
+
|
124
|
+
// );
|
125
|
+
|
126
|
+
// });
|
127
|
+
|
128
|
+
// });
|
129
|
+
|
130
|
+
// });
|
131
|
+
// });
|
132
|
+
// }
|
129
133
|
|
130
134
|
|
131
135
|
getAvailableAgentsCount(agents) {
|
@@ -0,0 +1,149 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var Request = require("../models/request");
|
4
|
+
var messageService = require('../services/messageService');
|
5
|
+
const requestEvent = require('../event/requestEvent');
|
6
|
+
const leadEvent = require('../event/leadEvent');
|
7
|
+
var winston = require('../config/winston');
|
8
|
+
|
9
|
+
class UpdateLeadQueued {
|
10
|
+
|
11
|
+
constructor() {
|
12
|
+
// this.listen();
|
13
|
+
}
|
14
|
+
|
15
|
+
listen() {
|
16
|
+
// 12 marzo 2024 I disabled these two functions due to performance problems for a chatbot created by Sponziello "Community bots Sendinblue Hubspot Qapla)"
|
17
|
+
this.updateSnapshotLead();
|
18
|
+
this.sendMessageUpdateLead();
|
19
|
+
winston.info("Listening UpdateLeadQueued started")
|
20
|
+
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
updateSnapshotLead() {
|
25
|
+
|
26
|
+
var leadUpdateKey = 'lead.update';
|
27
|
+
if (leadEvent.queueEnabled) {
|
28
|
+
leadUpdateKey = 'lead.update.queue';
|
29
|
+
}
|
30
|
+
winston.debug("leadUpdateKey: " + leadUpdateKey);
|
31
|
+
|
32
|
+
leadEvent.on(leadUpdateKey, function (lead) {
|
33
|
+
setImmediate(() => {
|
34
|
+
winston.debug("updateSnapshotLead on lead.update ", lead);
|
35
|
+
|
36
|
+
var query = { lead: lead._id, id_project: lead.id_project };
|
37
|
+
winston.debug("query ", query);
|
38
|
+
|
39
|
+
Request.updateMany(query, { "$set": { "snapshot.lead": lead } }, function (err, updates) {
|
40
|
+
if (err) {
|
41
|
+
winston.error("Error updating requests updateSnapshotLead", err);
|
42
|
+
return 0;
|
43
|
+
}
|
44
|
+
winston.debug("updateSnapshotLead updated for " + updates.nModified + " request")
|
45
|
+
requestEvent.emit('request.update.snapshot.lead', { lead: lead, updates: updates });
|
46
|
+
return;
|
47
|
+
});
|
48
|
+
// Request.find({lead: lead._id, id_project: lead.id_project}, function(err, requests) {
|
49
|
+
|
50
|
+
// if (err) {
|
51
|
+
// winston.error("Error getting request by lead", err);
|
52
|
+
// return 0;
|
53
|
+
// }
|
54
|
+
// if (!requests || (requests && requests.length==0)) {
|
55
|
+
// winston.warn("No request found for lead id " +lead._id );
|
56
|
+
// return 0;
|
57
|
+
// }
|
58
|
+
|
59
|
+
// requests.forEach(function(request) {
|
60
|
+
|
61
|
+
|
62
|
+
// });
|
63
|
+
|
64
|
+
// });
|
65
|
+
|
66
|
+
|
67
|
+
});
|
68
|
+
});
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
sendMessageUpdateLead() {
|
73
|
+
|
74
|
+
var leadUpdateEmailKey = 'lead.fullname.email.update';
|
75
|
+
if (leadEvent.queueEnabled) {
|
76
|
+
leadUpdateEmailKey = 'lead.fullname.email.update.queue';
|
77
|
+
}
|
78
|
+
winston.debug("leadUpdateEmailKey: " + leadUpdateEmailKey);
|
79
|
+
|
80
|
+
|
81
|
+
leadEvent.on(leadUpdateEmailKey, function (lead) {
|
82
|
+
winston.debug("lead.fullname.email.update ");
|
83
|
+
// leadEvent.on('lead.update', function(lead) {
|
84
|
+
|
85
|
+
setImmediate(() => {
|
86
|
+
winston.debug("sendMessageUpdateLead on lead.update ", lead);
|
87
|
+
|
88
|
+
// .find({"channel.name":"chat21"}).sort({"createdAt": -1}).limit(2)
|
89
|
+
Request.find({ lead: lead._id, id_project: lead.id_project, "channel.name":"chat21" }).limit(1).sort({"createdAt": -1}).
|
90
|
+
exec(function (err, requests) {
|
91
|
+
|
92
|
+
if (err) {
|
93
|
+
winston.error("Error getting sendMessageUpdateLead request by lead", err);
|
94
|
+
return 0;
|
95
|
+
}
|
96
|
+
if (!requests || (requests && requests.length == 0)) {
|
97
|
+
winston.warn("sendMessageUpdateLead No request found for lead id " + lead._id);
|
98
|
+
return 0;
|
99
|
+
}
|
100
|
+
|
101
|
+
// winston.info("sendMessageUpdateLead requests ", requests);
|
102
|
+
|
103
|
+
// requests.forEach(function (request) {
|
104
|
+
|
105
|
+
var request = requests[0];
|
106
|
+
|
107
|
+
winston.debug("sendMessageUpdateLead request ", request);
|
108
|
+
|
109
|
+
// send(sender, senderFullname, recipient, text, id_project, createdBy, attributes, type, metadata, language)
|
110
|
+
messageService.send(
|
111
|
+
'system',
|
112
|
+
'Bot',
|
113
|
+
// lead.fullname,
|
114
|
+
request.request_id,
|
115
|
+
"Lead updated",
|
116
|
+
request.id_project,
|
117
|
+
'system',
|
118
|
+
{
|
119
|
+
subtype: "info/support",
|
120
|
+
"updateconversation": false,
|
121
|
+
messagelabel: { key: "LEAD_UPDATED" },
|
122
|
+
updateUserEmail: lead.email,
|
123
|
+
updateUserFullname: lead.fullname
|
124
|
+
},
|
125
|
+
undefined,
|
126
|
+
request.language
|
127
|
+
|
128
|
+
);
|
129
|
+
|
130
|
+
// });
|
131
|
+
|
132
|
+
});
|
133
|
+
|
134
|
+
});
|
135
|
+
});
|
136
|
+
}
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
var updateLeadQueued = new UpdateLeadQueued();
|
146
|
+
|
147
|
+
|
148
|
+
module.exports = updateLeadQueued;
|
149
|
+
|