Enforce maximum audio duration limit and bypass Gemini
This commit is contained in:
@@ -369,18 +369,23 @@ 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.";
|
||||
|
||||
if ($hasAudio) {
|
||||
$mimeType = $msgData['mimeType'];
|
||||
if (strpos($mimeType, ';') !== false) {
|
||||
$mimeType = trim(explode(';', $mimeType)[0]);
|
||||
}
|
||||
// Try generating native audio response first
|
||||
$audioResponse = \App\Services\GeminiService::generateAudioResponseFromAudio($apiKey, $systemPrompt, $msgData['audio'], $mimeType);
|
||||
if ($audioResponse && !empty($audioResponse['audio'])) {
|
||||
$replyAudio = $audioResponse['audio'];
|
||||
$replyText = '[صوت من الذكاء الاصطناعي]';
|
||||
$duration = isset($msgData['duration']) ? intval($msgData['duration']) : null;
|
||||
if ($duration !== null && $duration > 90) {
|
||||
$replyText = "⚠️ عذراً، التسجيل الصوتي طويل جداً. يرجى إرسال تسجيل صوتي موجز (لا يتجاوز دقيقة واحدة) لتلخيص المشكلة لكي نتمكن من مساعدتك بشكل أفضل.";
|
||||
} else {
|
||||
// Fallback to text output from audio
|
||||
$replyText = \App\Services\GeminiService::generateResponseFromAudio($apiKey, $systemPrompt, $msgData['audio'], $mimeType);
|
||||
$mimeType = $msgData['mimeType'];
|
||||
if (strpos($mimeType, ';') !== false) {
|
||||
$mimeType = trim(explode(';', $mimeType)[0]);
|
||||
}
|
||||
// Try generating native audio response first
|
||||
$audioResponse = \App\Services\GeminiService::generateAudioResponseFromAudio($apiKey, $systemPrompt, $msgData['audio'], $mimeType);
|
||||
if ($audioResponse && !empty($audioResponse['audio'])) {
|
||||
$replyAudio = $audioResponse['audio'];
|
||||
$replyText = '[صوت من الذكاء الاصطناعي]';
|
||||
} else {
|
||||
// Fallback to text output from audio
|
||||
$replyText = \App\Services\GeminiService::generateResponseFromAudio($apiKey, $systemPrompt, $msgData['audio'], $mimeType);
|
||||
}
|
||||
}
|
||||
} elseif ($hasImage) {
|
||||
$mimeType = $msgData['imageMimeType'];
|
||||
|
||||
Reference in New Issue
Block a user