Deploy: 2026-05-24 01:38:52

This commit is contained in:
Hamza-Ayed
2026-05-24 01:38:52 +03:00
parent b995ac1076
commit 922c2c0b06
2 changed files with 17 additions and 3 deletions

View File

@@ -71,6 +71,12 @@ class GeminiService
'parts' => [
['text' => $systemPrompt]
]
],
'safetySettings' => [
['category' => 'HARM_CATEGORY_HARASSMENT', 'threshold' => 'BLOCK_NONE'],
['category' => 'HARM_CATEGORY_HATE_SPEECH', 'threshold' => 'BLOCK_NONE'],
['category' => 'HARM_CATEGORY_SEXUALLY_EXPLICIT', 'threshold' => 'BLOCK_NONE'],
['category' => 'HARM_CATEGORY_DANGEROUS_CONTENT', 'threshold' => 'BLOCK_NONE']
]
]);
@@ -93,12 +99,18 @@ class GeminiService
}
$data = json_decode($response, true);
$text = $data['candidates'][0]['content']['parts'][0]['text'] ?? null;
$text = null;
if (isset($data['candidates'][0]['content']['parts'][0]['text'])) {
$text = $data['candidates'][0]['content']['parts'][0]['text'];
}
if ($text === null) {
$reason = $data['candidates'][0]['finishReason'] ?? 'مجهول';
$reason = isset($data['candidates'][0]['finishReason']) ? $data['candidates'][0]['finishReason'] : 'مجهول';
if (isset($data['error']['message'])) {
$reason = $data['error']['message'];
}
error_log("[Gemini Content Error] Reason: " . $reason . " | Response: " . $response);
return "عذراً، لم أتمكن من صياغة الرد لأسباب أمنية أو تقنية (السبب: " . $reason . ").";
return "عذراً، لم أتمكن من صياغة الرد (السبب: " . $reason . ").";
}
return $text;

View File

@@ -132,6 +132,8 @@ app.post('/api/messages/send', async (req, res) => {
if (!message && !audio && !media_url && !image) {
return res.status(400).json({ error: 'Missing message, audio, media_url, or image' });
}
console.log(`[API] Received request to send message to ${phone}: ${message ? message.substring(0, 50) + '...' : '(no text)'}`);
try {
const result = await sendMessage(session_key, phone, message, media_url, audio, mimetype, image);