@tiledesk/tiledesk-server 2.13.49 → 2.13.51

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 CHANGED
@@ -5,6 +5,15 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.13.51
9
+ - Refactoring of route() and create() method on RequestService in order to improve performance for firt message
10
+ - Updated tests
11
+
12
+ # 2.13.50
13
+ - Updated kb route to support embeddings
14
+ - Updated tybot-connector to 2.0.41
15
+ - Updated vxml-connector to 0.1.89
16
+
8
17
  # 2.13.49
9
18
  - Updated tybot-connector to 2.0.41
10
19
 
package/app.js CHANGED
@@ -64,10 +64,12 @@ var autoIndex = true;
64
64
  if (process.env.MONGOOSE_AUTOINDEX) {
65
65
  autoIndex = process.env.MONGOOSE_AUTOINDEX;
66
66
  }
67
-
68
67
  winston.info("DB AutoIndex: " + autoIndex);
69
68
 
70
- var connection = mongoose.connect(databaseUri, { "useNewUrlParser": true, "autoIndex": autoIndex }, function(err) {
69
+ let useUnifiedTopology = process.env.MONGOOSE_UNIFIED_TOPOLOGY === 'true';
70
+ winston.info("DB useUnifiedTopology: ", useUnifiedTopology, typeof useUnifiedTopology);
71
+
72
+ var connection = mongoose.connect(databaseUri, { "useNewUrlParser": true, "autoIndex": autoIndex, "useUnifiedTopology": useUnifiedTopology }, function(err) {
71
73
  if (err) {
72
74
  winston.error('Failed to connect to MongoDB on ' + databaseUri + " ", err);
73
75
  process.exit(1);
@@ -79,7 +81,7 @@ if (process.env.MONGOOSE_DEBUG==="true") {
79
81
  }
80
82
  mongoose.set('useFindAndModify', false); // https://mongoosejs.com/docs/deprecations.html#-findandmodify-
81
83
  mongoose.set('useCreateIndex', true);
82
- mongoose.set('useUnifiedTopology', false);
84
+ //mongoose.set('useUnifiedTopology', false);
83
85
 
84
86
  // CONNECT REDIS - CHECK IT
85
87
  const { TdCache } = require('./utils/TdCache');
@@ -180,6 +182,7 @@ var geoService = require('./services/geoService');
180
182
  // geoService.listen(); //queued
181
183
 
182
184
  var updateLeadQueued = require('./services/updateLeadQueued');
185
+ var updateRequestSnapshotQueued = require('./services/updateRequestSnapshotQueued');
183
186
 
184
187
  let JobsManager = require('./jobsManager');
185
188
 
@@ -189,7 +192,7 @@ if (process.env.JOB_WORKER_ENABLED=="true" || process.env.JOB_WORKER_ENABLED ==
189
192
  }
190
193
  winston.info("JobsManager jobWorkerEnabled: "+ jobWorkerEnabled);
191
194
 
192
- let jobsManager = new JobsManager(jobWorkerEnabled, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier, updateLeadQueued);
195
+ let jobsManager = new JobsManager(jobWorkerEnabled, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier, updateLeadQueued, updateRequestSnapshotQueued);
193
196
 
194
197
  var faqBotHandler = require('./services/faqBotHandler');
195
198
  faqBotHandler.listen();
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ provider: process.env.EMBEDDINGS_PROVIDER || "openai",
3
+ name: process.env.EMBEDDINGS_NAME || "text-embedding-ada-002",
4
+ api_key: "",
5
+ dimension: Number(process.env.EMBEDDINGS_DIMENSION) || 1536,
6
+ url: process.env.EMBEDDINGS_URL
7
+ }
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ name: process.env.VECTOR_STORE_NAME || 'pinecone',
3
+ type: process.env.INDEX_TYPE_HYBRID || process.env.PINECONE_TYPE_HYBRID || 'serverless',
4
+ apikey: process.env.VECTOR_STORE_APIKEY || '',
5
+ vector_size: Number(process.env.VECTOR_SIZE_HYBRID) || 1536,
6
+ index_name: process.env.INDEX_NAME_HYBRID || process.env.PINECONE_INDEX_HYBRID || 'llm-sample-hybrid-index',
7
+ host: process.env.VECTOR_STORE_HOST,
8
+ port: process.env.VECTOR_STORE_PORT ? Number(process.env.VECTOR_STORE_PORT) : undefined,
9
+ deployment: process.env.VECTOR_STORE_DEPLOYMENT
10
+ }
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ name: process.env.VECTOR_STORE_NAME || 'pinecone',
3
+ type: process.env.INDEX_TYPE || process.env.PINECONE_TYPE || 'serverless',
4
+ apikey: process.env.VECTOR_STORE_APIKEY || '',
5
+ vector_size: Number(process.env.VECTOR_SIZE) || 1536,
6
+ index_name: process.env.INDEX_NAME || process.env.PINECONE_INDEX || 'llm-sample-index',
7
+ host: process.env.VECTOR_STORE_HOST,
8
+ port: process.env.VECTOR_STORE_PORT ? Number(process.env.VECTOR_STORE_PORT) : undefined,
9
+ deployment: process.env.VECTOR_STORE_DEPLOYMENT
10
+ }
package/jobs.js CHANGED
@@ -29,6 +29,7 @@ const botEvent = require('./event/botEvent');
29
29
  var channelManager = require('./channels/channelManager');
30
30
 
31
31
  var updateLeadQueued = require('./services/updateLeadQueued');
32
+ var updateRequestSnapshotQueued = require('./services/updateRequestSnapshotQueued');
32
33
 
33
34
 
34
35
  require('./services/mongoose-cache-fn')(mongoose);
@@ -47,7 +48,10 @@ if (!databaseUri) { //TODO??
47
48
  winston.warn('DATABASE_URI not specified, falling back to localhost.');
48
49
  }
49
50
 
50
- var connection = mongoose.connect(databaseUri, { "useNewUrlParser": true, "autoIndex": autoIndex }, function(err) {
51
+ let useUnifiedTopology = process.env.MONGOOSE_UNIFIED_TOPOLOGY === 'true';
52
+ winston.info("DB useUnifiedTopology: ", useUnifiedTopology, typeof useUnifiedTopology);
53
+
54
+ var connection = mongoose.connect(databaseUri, { "useNewUrlParser": true, "autoIndex": autoIndex, "useUnifiedTopology": useUnifiedTopology }, function(err) {
51
55
  if (err) {
52
56
  winston.error('Failed to connect to MongoDB on ' + databaseUri + " ", err);
53
57
  process.exit(1);
@@ -83,7 +87,7 @@ async function main()
83
87
 
84
88
 
85
89
 
86
- let jobsManager = new JobsManager(undefined, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier, updateLeadQueued);
90
+ let jobsManager = new JobsManager(undefined, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier, updateLeadQueued, updateRequestSnapshotQueued);
87
91
 
88
92
  jobsManager.listen();
89
93
 
package/jobsManager.js CHANGED
@@ -2,7 +2,7 @@
2
2
  var winston = require('./config/winston');
3
3
 
4
4
  class JobsManager {
5
- constructor(jobWorkerEnabled, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier, updateLeadQueued) {
5
+ constructor(jobWorkerEnabled, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier, updateLeadQueued, updateRequestSnapshotQueued) {
6
6
  this.geoService = geoService;
7
7
  this.botEvent = botEvent;
8
8
  // this.subscriptionNotifier = subscriptionNotifier;
@@ -22,6 +22,7 @@ class JobsManager {
22
22
  // winston.info("JobsManager jobWorkerEnabled: "+ this.jobWorkerEnabled);
23
23
 
24
24
  this.updateLeadQueued = updateLeadQueued;
25
+ this.updateRequestSnapshotQueued = updateRequestSnapshotQueued;
25
26
  }
26
27
 
27
28
 
@@ -39,6 +40,10 @@ class JobsManager {
39
40
 
40
41
  this.updateLeadQueued.listen();
41
42
 
43
+ if (this.updateRequestSnapshotQueued) {
44
+ this.updateRequestSnapshotQueued.listen();
45
+ }
46
+
42
47
  // this.botSubscriptionNotifier.start(); // disabled
43
48
  }
44
49
 
@@ -1,9 +1,9 @@
1
- var mongoose = require('mongoose');
2
- var Schema = mongoose.Schema;
3
- var winston = require('../config/winston');
1
+ let mongoose = require('mongoose');
2
+ let Schema = mongoose.Schema;
3
+ let winston = require('../config/winston');
4
4
  let expireAfterSeconds = process.env.UNANSWERED_QUESTION_EXPIRATION_TIME || 7 * 24 * 60 * 60; // 7 days
5
5
 
6
- var EngineSchema = new Schema({
6
+ const EngineSchema = new Schema({
7
7
  name: {
8
8
  type: String,
9
9
  required: true
@@ -23,12 +23,49 @@ var EngineSchema = new Schema({
23
23
  index_name: {
24
24
  type: String,
25
25
  required: true
26
+ },
27
+ host: {
28
+ type: String,
29
+ required: false
30
+ },
31
+ port: {
32
+ type: String,
33
+ required: false
34
+ },
35
+ deployment: {
36
+ type: String,
37
+ required: false
38
+ },
39
+ }, {
40
+ _id: false // This is schema is always used as an embedded object inside NamespaceSchema
41
+ })
42
+
43
+ const EmbeddingSchema = new Schema({
44
+ provider: {
45
+ type: String,
46
+ required: true
47
+ },
48
+ name: {
49
+ type: String,
50
+ required: true
51
+ },
52
+ dimension: {
53
+ type: Number,
54
+ reuired: true
55
+ },
56
+ url: {
57
+ type: String,
58
+ required: false
59
+ },
60
+ api_key: {
61
+ type: String,
62
+ required: false
26
63
  }
27
64
  }, {
28
65
  _id: false // This is schema is always used as an embedded object inside NamespaceSchema
29
66
  })
30
67
 
31
- var NamespaceSchema = new Schema({
68
+ const NamespaceSchema = new Schema({
32
69
  id_project: {
33
70
  type: String,
34
71
  required: true
@@ -55,7 +92,11 @@ var NamespaceSchema = new Schema({
55
92
  },
56
93
  engine: {
57
94
  type: EngineSchema,
58
- required: false
95
+ required: true
96
+ },
97
+ embedding: {
98
+ type: EmbeddingSchema,
99
+ required: true
59
100
  }
60
101
  }, {
61
102
  timestamps: true
@@ -86,6 +127,14 @@ var KBSchema = new Schema({
86
127
  type: String,
87
128
  required: false
88
129
  },
130
+ sitemap_origin_id: {
131
+ type: String,
132
+ required: false
133
+ },
134
+ sitemap_origin: {
135
+ type: String,
136
+ required: false
137
+ },
89
138
  namespace: {
90
139
  type: String,
91
140
  required: false
@@ -122,6 +171,10 @@ var KBSchema = new Schema({
122
171
  last_refresh: {
123
172
  type: Date,
124
173
  required: false
174
+ },
175
+ last_error: {
176
+ type: Object,
177
+ required: false
125
178
  }
126
179
  }, {
127
180
  timestamps: true
@@ -141,14 +194,6 @@ const UnansweredQuestionSchema = new Schema({
141
194
  question: {
142
195
  type: String,
143
196
  required: true
144
- },
145
- created_at: {
146
- type: Date,
147
- default: Date.now
148
- },
149
- updated_at: {
150
- type: Date,
151
- default: Date.now
152
197
  }
153
198
  },{
154
199
  timestamps: true
@@ -158,7 +203,7 @@ const UnansweredQuestionSchema = new Schema({
158
203
  UnansweredQuestionSchema.index({ created_at: 1 }, { expireAfterSeconds: expireAfterSeconds }); // 30 days
159
204
 
160
205
  // DEPRECATED !! - Start
161
- var KBSettingSchema = new Schema({
206
+ const KBSettingSchema = new Schema({
162
207
  id_project: {
163
208
  type: String,
164
209
  required: true,
package/models/profile.js CHANGED
@@ -1,11 +1,17 @@
1
1
  var mongoose = require('mongoose');
2
2
  var Schema = mongoose.Schema;
3
3
  var winston = require('../config/winston');
4
+ let isCommunity = false;
5
+ if (process.env.COMMUNITY_VERSION === true || process.env.COMMUNITY_VERSION === 'true') {
6
+ isCommunity = true;
7
+ }
4
8
 
5
9
  var ProfileSchema = new Schema({
6
10
  name: {
7
11
  type: String,
8
- default: 'Sandbox',
12
+ default: function() {
13
+ return (isCommunity) ? 'Custom' : 'Sandbox';
14
+ },
9
15
  index: true
10
16
  },
11
17
  trialDays: {
@@ -14,23 +20,66 @@ var ProfileSchema = new Schema({
14
20
  },
15
21
  agents: {
16
22
  type: Number,
17
- default: 0 //??
23
+ default: function() {
24
+ return (isCommunity) ? 1000 : 0;
25
+ }
18
26
  },
19
27
  type: {
20
28
  type: String,
21
- default: 'free',
29
+ default: function() {
30
+ return (isCommunity) ? 'payment' : 'free';
31
+ }
22
32
  },
23
33
  quotes: {
24
- type: Object
34
+ type: Object,
35
+ default: function() {
36
+ if (isCommunity) {
37
+ return {
38
+ chatbots: 10000,
39
+ kbs: 10000,
40
+ namespace: 10000,
41
+ }
42
+ }
43
+ return undefined;
44
+ }
25
45
  },
26
46
  customization: {
27
- type: Object
47
+ type: Object,
48
+ default: function() {
49
+ if (isCommunity) {
50
+ return {
51
+ copilot: true,
52
+ webhook: true,
53
+ widgetUnbranding: true,
54
+ smtpSettings: true,
55
+ knowledgeBases: true,
56
+ reindex: true,
57
+ messanger: true,
58
+ telegram: true,
59
+ chatbot: true
60
+ };
61
+ }
62
+ return undefined;
63
+ }
28
64
  },
29
65
  subStart: {
30
66
  type: Date,
67
+ default: function() {
68
+ if (isCommunity) {
69
+ return new Date();
70
+ }
71
+ return undefined;
72
+ }
31
73
  },
32
74
  subEnd: {
33
75
  type: Date,
76
+ default: function() {
77
+ if (isCommunity) {
78
+ // Set date to 31 December 2099
79
+ return new Date('2099-12-31T23:59:59.999Z');
80
+ }
81
+ return undefined;
82
+ }
34
83
  },
35
84
  subscriptionId: {
36
85
  type: String,
package/models/request.js CHANGED
@@ -460,7 +460,7 @@ RequestSchema.index({ id_project: 1, request_id: 1 }
460
460
  //TODO cambiare dummy con language? attento che il codice deve essere compatibile
461
461
 
462
462
 
463
- RequestSchema.index({transcript: 'text', rating_message: 'text', subject: 'text', "tags.tag": 'text', "notes.text": 'text', "snapshot.lead.email": 'text', "snapshot.lead.fullname": 'text' },
463
+ RequestSchema.index({id_project: 1, transcript: 'text', rating_message: 'text', subject: 'text', "tags.tag": 'text', "notes.text": 'text', "snapshot.lead.email": 'text', "snapshot.lead.fullname": 'text' },
464
464
  {"name":"request_fulltext","default_language": defaultFullTextLanguage,"language_override": "dummy"}); // schema level
465
465
 
466
466
  // let query = {id_project: operatorSelectedEvent.id_project, participants: { $exists: true, $ne: [] }};
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.13.49",
4
+ "version": "2.13.51",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -49,9 +49,9 @@
49
49
  "@tiledesk/tiledesk-rasa-connector": "^1.0.10",
50
50
  "@tiledesk/tiledesk-sms-connector": "^0.1.11",
51
51
  "@tiledesk/tiledesk-telegram-connector": "^0.1.14",
52
- "@tiledesk/tiledesk-tybot-connector": "^2.0.41",
52
+ "@tiledesk/tiledesk-tybot-connector": "^2.0.42",
53
53
  "@tiledesk/tiledesk-voice-twilio-connector": "^0.1.26",
54
- "@tiledesk/tiledesk-vxml-connector": "^0.1.87",
54
+ "@tiledesk/tiledesk-vxml-connector": "^0.1.89",
55
55
  "@tiledesk/tiledesk-whatsapp-connector": "1.0.18",
56
56
  "@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.13",
57
57
  "amqplib": "^0.5.5",
@@ -113,7 +113,7 @@
113
113
  "retry-request": "^4.2.2",
114
114
  "serve-favicon": "~2.5.0",
115
115
  "sharp": "^0.27.2",
116
- "sitemapper": "^3.2.8",
116
+ "sitemapper": "^3.2.24",
117
117
  "stripe": "^7.2.0",
118
118
  "uniqid": "^5.4.0",
119
119
  "uuid": "^3.3.3",
@@ -29,7 +29,8 @@ class Listener {
29
29
  ACCESS_TOKEN_SECRET: process.env.APPS_ACCESS_TOKEN_SECRET || configSecretOrPubicKay,
30
30
  MONGODB_URI: process.env.APPS_MONGODB_URI || config.databaseUri,
31
31
  KALEYRA_ENABLED: process.env.KALEYRA_ENABLED || config.kaleyra_enabled,
32
- VOICE_ENABLED: process.env.VOICE_ENABLED || false
32
+ VOICE_ENABLED: process.env.VOICE_ENABLED || false,
33
+ isCommunity: process.env.COMMUNITY_VERSION || false
33
34
  }, () => {
34
35
  winston.info("Tiledesk Apps proxy server succesfully started.")
35
36
  })
@@ -204,9 +204,10 @@ function startWorker() {
204
204
  winston.info("Data queue", oka)
205
205
  });
206
206
 
207
-
208
-
209
-
207
+ ch.bindQueue(_ok.queue, exchange, "request_snapshot_update", {}, function(err3, oka) {
208
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: request_snapshot_update");
209
+ winston.info("Data queue", oka)
210
+ });
210
211
 
211
212
 
212
213
  ch.consume(queueName, processMsg, { noAck: false });
@@ -320,6 +321,11 @@ function work(msg, cb) {
320
321
  leadEvent.emit('lead.fullname.email.update.queue', JSON.parse(message_string));
321
322
  }
322
323
 
324
+ if (topic === 'request_snapshot_update') {
325
+ winston.debug("reconnect here topic request_snapshot_update:" + topic);
326
+ requestEvent.emit('request.snapshot.update.queue', JSON.parse(message_string));
327
+ }
328
+
323
329
 
324
330
 
325
331
  cb(true);
@@ -404,6 +410,13 @@ function listen() {
404
410
  });
405
411
  });
406
412
 
413
+ requestEvent.on('request.snapshot.update', function(data) {
414
+ setImmediate(() => {
415
+ winston.debug("reconnect request.snapshot.update")
416
+ console.log("reconnect request.snapshot.update")
417
+ publish(exchange, "request_snapshot_update", Buffer.from(JSON.stringify(data)));
418
+ });
419
+ });
407
420
 
408
421
 
409
422
  messageEvent.on('message.create', function(message) {
@@ -184,6 +184,10 @@ function work(msg, cb) {
184
184
  winston.debug("reconnectfanout here topic faqbot_update:" + topic);
185
185
  botEvent.emit('faqbot.update.queue.pubsub', JSON.parse(message_string));
186
186
  }
187
+ if (topic === 'request_snapshot_add') {
188
+ winston.debug("reconnectfanout here topic request_snapshot_add:" + topic);
189
+ requestEvent.emit('request.snapshot.add.queue.pubsub', JSON.parse(message_string));
190
+ }
187
191
  cb(true);
188
192
  // WebSocket.cb(true);
189
193
  // requestEvent.on(msg.KEYYYYYYY+'.ws', msg.content);