@peopl-health/nexus 2.4.1 → 2.4.3
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 +0 -0
- package/LICENSE +0 -0
- package/MIGRATION_GUIDE.md +0 -0
- package/README.md +0 -0
- package/examples/.env.example +0 -0
- package/examples/assistants/BaseAssistant.js +0 -0
- package/examples/assistants/DoctorScheduleAssistant.js +0 -0
- package/examples/assistants/ExampleAssistant.js +0 -0
- package/examples/assistants/index.js +0 -0
- package/examples/basic-usage.js +0 -0
- package/examples/consumer-server.js +0 -0
- package/examples/test-batching.js +0 -0
- package/lib/adapters/BaileysProvider.js +0 -0
- package/lib/adapters/TwilioProvider.js +3 -2
- package/lib/adapters/index.js +0 -0
- package/lib/adapters/registry.js +0 -0
- package/lib/assistants/BaseAssistant.js +1 -1
- package/lib/assistants/index.js +0 -0
- package/lib/config/airtableConfig.js +0 -0
- package/lib/config/awsConfig.js +0 -0
- package/lib/config/configLoader.js +0 -0
- package/lib/config/interactionConfig.js +0 -0
- package/lib/config/llmConfig.js +0 -0
- package/lib/config/mongoAuthConfig.js +0 -0
- package/lib/config/runtimeConfig.js +0 -0
- package/lib/controllers/assistantController.js +0 -0
- package/lib/controllers/bugReportController.js +0 -0
- package/lib/controllers/conversationController.js +0 -0
- package/lib/controllers/interactionController.js +0 -0
- package/lib/controllers/mediaController.js +0 -0
- package/lib/controllers/messageController.js +0 -0
- package/lib/controllers/patientController.js +0 -0
- package/lib/controllers/qualityMessageController.js +0 -0
- package/lib/controllers/templateController.js +0 -0
- package/lib/controllers/templateFlowController.js +0 -0
- package/lib/controllers/uploadController.js +0 -0
- package/lib/core/MessageProvider.js +0 -0
- package/lib/core/NexusMessaging.js +0 -0
- package/lib/core/index.js +0 -0
- package/lib/helpers/assistantHelper.js +0 -0
- package/lib/helpers/baileysHelper.js +0 -0
- package/lib/helpers/filesHelper.js +6 -6
- package/lib/helpers/llmsHelper.js +0 -0
- package/lib/helpers/mediaHelper.js +0 -0
- package/lib/helpers/messageHelper.js +3 -11
- package/lib/helpers/mongoHelper.js +0 -0
- package/lib/helpers/processHelper.js +2 -1
- package/lib/helpers/qrHelper.js +0 -0
- package/lib/helpers/threadHelper.js +0 -0
- package/lib/helpers/twilioHelper.js +0 -0
- package/lib/helpers/twilioMediaProcessor.js +0 -0
- package/lib/helpers/whatsappHelper.js +0 -0
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -0
- package/lib/interactive/index.js +0 -0
- package/lib/interactive/registry.js +0 -0
- package/lib/interactive/twilioMapper.js +0 -0
- package/lib/models/agendaMessageModel.js +0 -0
- package/lib/models/index.js +0 -0
- package/lib/models/interactionModel.js +0 -0
- package/lib/models/messageModel.js +0 -0
- package/lib/models/qualityMessageModel.js +0 -0
- package/lib/models/templateModel.js +0 -0
- package/lib/models/threadModel.js +0 -0
- package/lib/observability/index.js +0 -0
- package/lib/observability/telemetry.js +0 -0
- package/lib/providers/OpenAIAssistantsProvider.js +0 -0
- package/lib/providers/OpenAIResponsesProvider.js +0 -0
- package/lib/providers/OpenAIResponsesProviderTools.js +0 -0
- package/lib/providers/createProvider.js +0 -0
- package/lib/routes/index.js +0 -0
- package/lib/services/airtableService.js +0 -0
- package/lib/services/assistantService.js +0 -0
- package/lib/services/conversationService.js +0 -0
- package/lib/services/preprocessingHooks.js +0 -0
- package/lib/services/twilioService.js +0 -0
- package/lib/storage/MongoStorage.js +0 -0
- package/lib/storage/NoopStorage.js +0 -0
- package/lib/storage/index.js +0 -0
- package/lib/storage/registry.js +0 -0
- package/lib/templates/predefinedTemplates.js +0 -0
- package/lib/templates/templateStructure.js +0 -0
- package/lib/utils/dateUtils.js +0 -0
- package/lib/utils/errorHandler.js +0 -0
- package/lib/utils/index.js +0 -0
- package/lib/utils/logger.js +0 -0
- package/lib/utils/mediaValidator.js +0 -0
- package/lib/utils/messageParser.js +0 -0
- package/lib/utils/retryHelper.js +0 -0
- package/lib/utils/sanitizer.js +0 -0
- package/lib/utils/tracingDecorator.js +0 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
File without changes
|
package/LICENSE
CHANGED
|
File without changes
|
package/MIGRATION_GUIDE.md
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/examples/.env.example
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/examples/basic-usage.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const { MessageProvider } = require('../core/MessageProvider');
|
|
2
2
|
const axios = require('axios');
|
|
3
3
|
const runtimeConfig = require('../config/runtimeConfig');
|
|
4
|
-
const { uploadMediaToS3,
|
|
4
|
+
const { uploadMediaToS3, getFileExtension } = require('../helpers/mediaHelper');
|
|
5
|
+
const { sanitizeMediaFilename } = require('../utils/sanitizer');
|
|
5
6
|
const { generatePresignedUrl } = require('../config/awsConfig');
|
|
6
7
|
const { validateMedia, getMediaType } = require('../utils/mediaValidator');
|
|
7
8
|
const { v4: uuidv4 } = require('uuid');
|
|
@@ -299,7 +300,7 @@ class TwilioProvider extends MessageProvider {
|
|
|
299
300
|
})();
|
|
300
301
|
|
|
301
302
|
const baseName = existingFileName ? existingFileName.split('.').slice(0, -1).join('.') : `${mediaType}_${Date.now()}`;
|
|
302
|
-
const sanitizedBase =
|
|
303
|
+
const sanitizedBase = sanitizeMediaFilename(baseName) || `${mediaType}_${Date.now()}`;
|
|
303
304
|
const extension = getFileExtension(contentType) || 'bin';
|
|
304
305
|
const uploadId = uuidv4();
|
|
305
306
|
const key = await uploadMediaToS3(buffer, uploadId, sanitizedBase, bucketName, contentType, mediaType);
|
package/lib/adapters/index.js
CHANGED
|
File without changes
|
package/lib/adapters/registry.js
CHANGED
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const llmConfig = require('../config/llmConfig');
|
|
2
2
|
const { Thread } = require('../models/threadModel');
|
|
3
3
|
const { Message } = require('../models/messageModel');
|
|
4
|
-
const { formatMessage } = require('../helpers/
|
|
4
|
+
const { formatMessage } = require('../helpers/messageHelper');
|
|
5
5
|
const { createProvider } = require('../providers/createProvider');
|
|
6
6
|
|
|
7
7
|
const DEFAULT_MAX_HISTORICAL_MESSAGES = parseInt(process.env.MAX_HISTORICAL_MESSAGES || '50', 10);
|
package/lib/assistants/index.js
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/config/awsConfig.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/config/llmConfig.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/core/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -15,7 +15,7 @@ async function convertPdfToImages(pdfName) {
|
|
|
15
15
|
const pdfPath = path.join(outputDir, `${sanitizedName}.pdf`);
|
|
16
16
|
const outputPattern = path.join(outputDir, sanitizedName);
|
|
17
17
|
|
|
18
|
-
await fs.
|
|
18
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
19
19
|
|
|
20
20
|
return new Promise((resolve, reject) => {
|
|
21
21
|
const args = ['-jpeg', pdfPath, outputPattern];
|
|
@@ -49,7 +49,7 @@ async function combineImagesToPDF(config) {
|
|
|
49
49
|
} = config;
|
|
50
50
|
|
|
51
51
|
const inputDir = path.join(__dirname, 'assets', 'tmp');
|
|
52
|
-
const files = await fs.
|
|
52
|
+
const files = await fs.readdir(inputDir);
|
|
53
53
|
|
|
54
54
|
const imageFiles = files.filter(file => {
|
|
55
55
|
const ext = path.extname(file).toLowerCase().substring(1);
|
|
@@ -81,7 +81,7 @@ async function combineImagesToPDF(config) {
|
|
|
81
81
|
const filePath = path.join(inputDir, file);
|
|
82
82
|
console.log(`Processing file ${index + 1}/${imageFiles.length}: ${file}`);
|
|
83
83
|
|
|
84
|
-
const imageBuffer = await fs.
|
|
84
|
+
const imageBuffer = await fs.readFile(filePath);
|
|
85
85
|
const pngBuffer = await sharp(imageBuffer)
|
|
86
86
|
.toFormat('png')
|
|
87
87
|
.toBuffer();
|
|
@@ -116,7 +116,7 @@ const cleanupFiles = async (files) => {
|
|
|
116
116
|
|
|
117
117
|
await Promise.all(files.map(async (filePath) => {
|
|
118
118
|
try {
|
|
119
|
-
await fs.
|
|
119
|
+
await fs.unlink(filePath);
|
|
120
120
|
} catch (error) {
|
|
121
121
|
if (error?.code !== 'ENOENT') {
|
|
122
122
|
const safeFileName = filePath ? filePath.split('/').pop().replace(/^[^-]+-[^-]+-/, 'xxx-xxx-') : 'unknown';
|
|
@@ -154,7 +154,7 @@ async function downloadMediaAndCreateFile(code, reply) {
|
|
|
154
154
|
const sourceFile = `${sanitizedCode}-${sanitizedSubType}-${sanitizedFileName}`;
|
|
155
155
|
const downloadPath = path.join(__dirname, 'assets', 'tmp', sourceFile);
|
|
156
156
|
|
|
157
|
-
await fs.
|
|
157
|
+
await fs.mkdir(path.dirname(downloadPath), { recursive: true });
|
|
158
158
|
await downloadFileFromS3(bucketName, key, downloadPath);
|
|
159
159
|
|
|
160
160
|
const { name: baseName } = path.parse(sourceFile);
|
|
@@ -163,7 +163,7 @@ async function downloadMediaAndCreateFile(code, reply) {
|
|
|
163
163
|
: [downloadPath];
|
|
164
164
|
|
|
165
165
|
if (subType === 'document' || subType === 'application') {
|
|
166
|
-
await fs.
|
|
166
|
+
await fs.unlink(downloadPath);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
return fileNames;
|
|
File without changes
|
|
File without changes
|
|
@@ -39,13 +39,7 @@ const updateMessageRecord = async (reply, thread) => {
|
|
|
39
39
|
|
|
40
40
|
async function getLastMessages(code) {
|
|
41
41
|
try {
|
|
42
|
-
let query = { processed: false };
|
|
43
|
-
if (code.endsWith('@g.us')) {
|
|
44
|
-
query = { ...query, numero: code, $or: [{ origin: 'patient' }, { origin: 'whatsapp_platform' }] };
|
|
45
|
-
} else {
|
|
46
|
-
query = { ...query, numero: code, $or: [{ origin: 'patient' }] };
|
|
47
|
-
}
|
|
48
|
-
|
|
42
|
+
let query = { processed: false, numero: code, $or: [{ origin: 'patient' }, { origin: 'whatsapp_platform' }] };
|
|
49
43
|
const lastMessages = await Message.find(query)
|
|
50
44
|
.sort({ createdAt: 1 });
|
|
51
45
|
|
|
@@ -91,13 +85,11 @@ async function getLastNMessages(code, n) {
|
|
|
91
85
|
|
|
92
86
|
function formatMessage(reply) {
|
|
93
87
|
try {
|
|
94
|
-
if (!reply.
|
|
88
|
+
if (!reply.createdAt) {
|
|
95
89
|
return null;
|
|
96
90
|
}
|
|
97
91
|
|
|
98
|
-
const
|
|
99
|
-
const msgDate = new Date(timestamp);
|
|
100
|
-
|
|
92
|
+
const msgDate = new Date(reply.createdAt);
|
|
101
93
|
if (isNaN(msgDate.getTime())) {
|
|
102
94
|
console.warn(`[formatMessage] Invalid timestamp for message ID: ${reply.message_id}`);
|
|
103
95
|
return reply.body;
|
|
File without changes
|
|
@@ -43,7 +43,8 @@ const processTextMessage = (reply) => {
|
|
|
43
43
|
timestamp: reply.timestamp,
|
|
44
44
|
from_me: reply.from_me,
|
|
45
45
|
body: reply.body,
|
|
46
|
-
hasContent: !!formattedMessage
|
|
46
|
+
hasContent: !!formattedMessage,
|
|
47
|
+
formattedMessage
|
|
47
48
|
});
|
|
48
49
|
logger.debug('processTextMessage_content', { formattedMessage });
|
|
49
50
|
|
package/lib/helpers/qrHelper.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/index.d.ts
CHANGED
|
File without changes
|
package/lib/index.js
CHANGED
|
File without changes
|
package/lib/interactive/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/models/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/routes/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/storage/index.js
CHANGED
|
File without changes
|
package/lib/storage/registry.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/utils/dateUtils.js
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/utils/index.js
CHANGED
|
File without changes
|
package/lib/utils/logger.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/utils/retryHelper.js
CHANGED
|
File without changes
|
package/lib/utils/sanitizer.js
CHANGED
|
File without changes
|
|
File without changes
|