@peopl-health/nexus 3.1.1 → 3.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.
@@ -182,7 +182,11 @@ async function downloadMediaAndCreateFile(code, reply) {
182
182
 
183
183
  const sanitizedCode = sanitizeFilename(code, 20);
184
184
  const sanitizedSubType = sanitizeFilename(subType, 10);
185
- const sanitizedFileName = sanitizeFilename(fileName, 50);
185
+
186
+ const fileExt = path.extname(fileName);
187
+ const fileBaseName = path.basename(fileName, fileExt);
188
+ const sanitizedBaseName = sanitizeFilename(fileBaseName, 50 - fileExt.length);
189
+ const sanitizedFileName = sanitizedBaseName + fileExt;
186
190
 
187
191
  const sourceFile = `${sanitizedCode}-${sanitizedSubType}-${sanitizedFileName}`;
188
192
  const downloadPath = path.join(__dirname, 'assets', 'tmp', sourceFile);
@@ -147,41 +147,9 @@ const processAudioFileCore = async (fileName, provider) => {
147
147
  };
148
148
 
149
149
  try {
150
- const fileExtension = fileName.split('.').pop().toLowerCase();
151
- const needsConversion = fileExtension === 'ogg'; // Convert OGG for OpenAI compatibility
152
- let transcriptionFile = fileName;
153
- let convertedFile = null;
154
-
155
- if (needsConversion) {
156
- logger.info('[processAudioFile] Converting OGG to MP3 for transcription', {
157
- originalFile: fileName ? fileName.split('/').pop().replace(/^[^-]+-[^-]+-/, 'xxx-xxx-') : 'unknown',
158
- format: fileExtension
159
- });
160
-
161
- convertedFile = fileName.replace('.ogg', '_converted.mp3');
162
-
163
- try {
164
- const { execSync } = require('child_process');
165
- execSync(`ffmpeg -i "${fileName}" -acodec mp3 -ab 128k "${convertedFile}" -y`, {
166
- stdio: 'pipe'
167
- });
168
- transcriptionFile = convertedFile;
169
-
170
- logger.info('[processAudioFile] Conversion successful', {
171
- convertedFile: convertedFile.split('/').pop().replace(/^[^-]+-[^-]+-/, 'xxx-xxx-')
172
- });
173
- } catch (conversionError) {
174
- logger.error('[processAudioFile] Conversion failed, attempting with original file', {
175
- error: conversionError.message,
176
- originalFile: fileName ? fileName.split('/').pop().replace(/^[^-]+-[^-]+-/, 'xxx-xxx-') : 'unknown'
177
- });
178
- transcriptionFile = fileName;
179
- }
180
- }
181
-
182
150
  const { result: audioTranscript, duration: transcribeDuration } = await withTracing(
183
151
  async () => provider.transcribeAudio({
184
- file: fs.createReadStream(transcriptionFile),
152
+ file: fs.createReadStream(fileName),
185
153
  responseFormat: 'text',
186
154
  language: 'es'
187
155
  }),
@@ -189,17 +157,6 @@ const processAudioFileCore = async (fileName, provider) => {
189
157
  () => ({ 'audio.file_name': fileName ? fileName.split('/').pop().replace(/^[^-]+-[^-]+-/, 'xxx-xxx-') : 'unknown' }),
190
158
  { returnTiming: true }
191
159
  )();
192
-
193
- if (convertedFile && fs.existsSync(convertedFile)) {
194
- try {
195
- fs.unlinkSync(convertedFile);
196
- logger.debug('[processAudioFile] Cleaned up converted file');
197
- } catch (cleanupError) {
198
- logger.warn('[processAudioFile] Failed to cleanup converted file', {
199
- error: cleanupError.message
200
- });
201
- }
202
- }
203
160
  timings.transcribe_ms = transcribeDuration;
204
161
 
205
162
  const transcriptText = audioTranscript?.text || audioTranscript;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",