Deploy: 2026-05-24 01:38:52
This commit is contained in:
@@ -71,6 +71,12 @@ class GeminiService
|
|||||||
'parts' => [
|
'parts' => [
|
||||||
['text' => $systemPrompt]
|
['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);
|
$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) {
|
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);
|
error_log("[Gemini Content Error] Reason: " . $reason . " | Response: " . $response);
|
||||||
return "عذراً، لم أتمكن من صياغة الرد لأسباب أمنية أو تقنية (السبب: " . $reason . ").";
|
return "عذراً، لم أتمكن من صياغة الرد (السبب: " . $reason . ").";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ app.post('/api/messages/send', async (req, res) => {
|
|||||||
if (!message && !audio && !media_url && !image) {
|
if (!message && !audio && !media_url && !image) {
|
||||||
return res.status(400).json({ error: 'Missing message, audio, media_url, or 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 {
|
try {
|
||||||
const result = await sendMessage(session_key, phone, message, media_url, audio, mimetype, image);
|
const result = await sendMessage(session_key, phone, message, media_url, audio, mimetype, image);
|
||||||
|
|||||||
Reference in New Issue
Block a user