CognxSafeTrack commited on
Commit ·
d8ac16e
1
Parent(s): 0ee3f5e
fix: pass correct imageUrl (R2 stored URL) to vision pipeline instead of empty audioUrl
Browse files
apps/whatsapp-worker/src/index.ts
CHANGED
|
@@ -725,11 +725,28 @@ const worker = new Worker('whatsapp-queue', async (job: Job) => {
|
|
| 725 |
throw new Error(`Transcription failed HTTP ${transcribeRes.status}`); // throw so BullMQ retries
|
| 726 |
}
|
| 727 |
} else if (mimeType.startsWith('image/')) {
|
| 728 |
-
// 📸 IMAGE-FLOW (
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 733 |
}
|
| 734 |
} catch (err: unknown) {
|
| 735 |
console.error(`[WORKER] download-media failed:`, err);
|
|
|
|
| 725 |
throw new Error(`Transcription failed HTTP ${transcribeRes.status}`); // throw so BullMQ retries
|
| 726 |
}
|
| 727 |
} else if (mimeType.startsWith('image/')) {
|
| 728 |
+
// 📸 IMAGE-FLOW: Build imageUrl from the R2 store result (same pattern as audioUrl for audio)
|
| 729 |
+
let imageUrl = '';
|
| 730 |
+
try {
|
| 731 |
+
const storeImgRes = await fetch(`${AI_API_BASE_URL.replace(/\/$/, '')}/v1/ai/store-audio`, {
|
| 732 |
+
method: 'POST',
|
| 733 |
+
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiKey}` },
|
| 734 |
+
body: JSON.stringify({ audioBase64: buffer.toString('base64'), mimeType, phone })
|
| 735 |
+
});
|
| 736 |
+
if (storeImgRes.ok) {
|
| 737 |
+
const storeImgData = await storeImgRes.json() as any;
|
| 738 |
+
if (storeImgData.url) {
|
| 739 |
+
imageUrl = storeImgData.url;
|
| 740 |
+
console.log(`[IMAGE-FLOW] ✅ Image uploaded to R2: ${imageUrl}`);
|
| 741 |
+
}
|
| 742 |
+
}
|
| 743 |
+
} catch (imgStoreErr: unknown) {
|
| 744 |
+
console.error('[IMAGE-FLOW] R2 store failed (image will be analyzed without permanent URL):', (imgStoreErr as Error).message);
|
| 745 |
+
}
|
| 746 |
+
|
| 747 |
+
console.log(`[IMAGE-FLOW] 📸 Image detected for ${phone}. Routing to WhatsAppLogic (imageUrl: ${imageUrl || 'none'})...`);
|
| 748 |
+
await WhatsAppLogic.handleIncomingMessage(phone, job.data.caption || 'Image reçue', undefined, imageUrl || undefined);
|
| 749 |
+
console.log(`[IMAGE-FLOW] ✅ Inbound image processing complete.`);
|
| 750 |
}
|
| 751 |
} catch (err: unknown) {
|
| 752 |
console.error(`[WORKER] download-media failed:`, err);
|