Deploy: 2026-05-24 01:38:52
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -133,6 +133,8 @@ app.post('/api/messages/send', async (req, res) => {
|
||||
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);
|
||||
res.json({ status: 'success', data: result });
|
||||
|
||||
Reference in New Issue
Block a user