Enforce maximum audio duration limit and bypass Gemini

This commit is contained in:
Hamza-Ayed
2026-05-22 15:38:03 +03:00
parent f1d57e2763
commit df8d905da7
2 changed files with 17 additions and 11 deletions

View File

@@ -369,6 +369,10 @@ class WhatsAppController extends BaseController
$systemPrompt .= "\n\nIMPORTANT LANGUAGE RULE: Detect the language of the incoming message. If the incoming message is in English, you MUST reply in English. If the incoming message is in Arabic, you MUST reply in Arabic. Override any default language instruction to match the user's language."; $systemPrompt .= "\n\nIMPORTANT LANGUAGE RULE: Detect the language of the incoming message. If the incoming message is in English, you MUST reply in English. If the incoming message is in Arabic, you MUST reply in Arabic. Override any default language instruction to match the user's language.";
if ($hasAudio) { if ($hasAudio) {
$duration = isset($msgData['duration']) ? intval($msgData['duration']) : null;
if ($duration !== null && $duration > 90) {
$replyText = "⚠️ عذراً، التسجيل الصوتي طويل جداً. يرجى إرسال تسجيل صوتي موجز (لا يتجاوز دقيقة واحدة) لتلخيص المشكلة لكي نتمكن من مساعدتك بشكل أفضل.";
} else {
$mimeType = $msgData['mimeType']; $mimeType = $msgData['mimeType'];
if (strpos($mimeType, ';') !== false) { if (strpos($mimeType, ';') !== false) {
$mimeType = trim(explode(';', $mimeType)[0]); $mimeType = trim(explode(';', $mimeType)[0]);
@@ -382,6 +386,7 @@ class WhatsAppController extends BaseController
// Fallback to text output from audio // Fallback to text output from audio
$replyText = \App\Services\GeminiService::generateResponseFromAudio($apiKey, $systemPrompt, $msgData['audio'], $mimeType); $replyText = \App\Services\GeminiService::generateResponseFromAudio($apiKey, $systemPrompt, $msgData['audio'], $mimeType);
} }
}
} elseif ($hasImage) { } elseif ($hasImage) {
$mimeType = $msgData['imageMimeType']; $mimeType = $msgData['imageMimeType'];
if (strpos($mimeType, ';') !== false) { if (strpos($mimeType, ';') !== false) {

View File

@@ -184,6 +184,7 @@ async function startSession(session_key, webhook_url) {
body: body, body: body,
audio: audioBase64, audio: audioBase64,
mimeType: audioMimeType, mimeType: audioMimeType,
duration: msg.message?.audioMessage?.seconds ? Number(msg.message.audioMessage.seconds) : null,
image: imageBase64, image: imageBase64,
imageMimeType: imageMimeType, imageMimeType: imageMimeType,
timestamp: msg.messageTimestamp timestamp: msg.messageTimestamp