Update: 2026-07-04 21:38:44

This commit is contained in:
Hamza-Ayed
2026-07-04 21:38:44 +03:00
parent df4af1ac2b
commit ce7db27936
8 changed files with 310 additions and 25 deletions
+54 -1
View File
@@ -133,7 +133,7 @@ class SiroGeminiService {
*/
public function analyzeCompetitorFormulas(
array $formulas,
string $model = 'gemini-1.5-flash'
string $model = 'gemini-flash-lite-latest'
): ?array {
if (!$this->apiKey) return null;
@@ -249,5 +249,58 @@ class SiroGeminiService {
error_log("[SiroGeminiService] Exception: " . $e->getMessage());
return null;
}
public function evaluatePostsForReporting(array $posts, string $model = 'gemini-flash-lite-latest'): ?string {
if (!$this->apiKey || empty($posts)) return null;
$postsJson = json_encode($posts, JSON_UNESCAPED_UNICODE);
$prompt = "
أنت محلل بيانات استخباراتية للسوق لتطبيق 'سيرو' لنقل الركاب.
إليك مجموعة من المنشورات والتعليقات التي جمعها الروبوت الخاص بنا من مجموعات فيسبوك اليوم:
$postsJson
المطلوب منك:
1. قراءة جميع هذه المنشورات واستخراج أي شكاوى، أسئلة، أو نقاشات تتعلق بـ (تطبيقات النقل الذكي، أسعار المحروقات، باقات الإنترنت، مشاكل السيارات).
2. تلخيص أهم هذه النقاشات في تقرير قصير ومفيد (News Report).
3. تجاهل المنشورات العشوائية أو الشخصية التي لا تفيد السوق.
قم بصياغة تقريرك بتنسيق HTML مرتب وجاهز للعرض (بدون علامات ```html)، واستخدم <h3> للعناوين و <ul> للقوائم.
إذا لم يكن هناك أي شيء مفيد، اكتب فقط: <p>لا توجد بيانات مفيدة في هذه الدفعة.</p>
";
$url = $this->baseUrl . "{$model}:generateContent?key={$this->apiKey}";
$postData = [
'contents' => [
[
'parts' => [
['text' => $prompt]
]
]
],
'generationConfig' => [
'temperature' => 0.5,
'maxOutputTokens' => 1500
]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$data = json_decode($response, true);
$text = $data['candidates'][0]['content']['parts'][0]['text'] ?? '';
return trim(preg_replace('/```html|```/', '', $text));
}
return null;
}
}
@@ -0,0 +1,9 @@
<?php
require_once __DIR__ . '/../core/bootstrap.php';
$con = Database::get('main');
// Insert the autonomous_scroll_and_reply task
$stmt = $con->prepare("INSERT INTO marketing_tasks (platform, type, status) VALUES ('facebook', 'autonomous_scroll_and_reply', 'pending')");
$stmt->execute();
echo "Task inserted successfully at " . date('Y-m-d H:i:s') . "\n";
+34 -13
View File
@@ -6,29 +6,26 @@
require_once __DIR__ . '/../core/bootstrap.php';
require_once __DIR__ . '/../functions.php';
require_once __DIR__ . '/../core/Services/SiroGeminiService.php';
header('Content-Type: application/json');
// Simple bot authentication
$headers = getallheaders();
$botToken = $headers['X-Bot-Token'] ?? '';
if ($botToken !== 'YOUR_SECRET_BOT_TOKEN') {
// http_response_code(401);
// exit(json_encode(['status' => 'error', 'message' => 'Unauthorized']));
}
// if ($botToken !== 'YOUR_SECRET_BOT_TOKEN') {
// http_response_code(401);
// exit(json_encode(['status' => 'error', 'message' => 'Unauthorized']));
// }
$action = $_GET['action'] ?? '';
$platform = $_GET['platform'] ?? 'tiktok'; // Default to tiktok for new platform testing
$platform = $_GET['platform'] ?? 'facebook';
try {
// In a real scenario, you'd use a dedicated database.
// Here we use the main DB but with marketing_ prefixed tables.
$con = Database::get('main');
switch ($action) {
case 'get_task':
// 1. First, check if the bot needs a task
// We look for pending tasks for this platform
$stmt = $con->prepare("
SELECT id, type, target_url, content_text, media_url
FROM marketing_tasks
@@ -39,10 +36,6 @@ try {
$task = $stmt->fetch(PDO::FETCH_ASSOC);
if ($task) {
// If the task requires a media file (like upload_video)
// The Android app will need to download it first using the media_url
// Mark as in progress
$update = $con->prepare("UPDATE marketing_tasks SET status = 'in_progress' WHERE id = ?");
$update->execute([$task['id']]);
@@ -78,6 +71,34 @@ try {
}
break;
case 'evaluate_posts':
$input = json_decode(file_get_contents('php://input'), true);
$posts = $input['posts'] ?? [];
if (empty($posts)) {
echo json_encode(['status' => 'success', 'data' => null]);
break;
}
$gemini = new SiroGeminiService();
$reportHtml = $gemini->evaluatePostsForReporting($posts);
if ($reportHtml) {
// Save to database
$con->query("CREATE TABLE IF NOT EXISTS `marketing_reports` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`platform` VARCHAR(50) NOT NULL,
`report_html` TEXT NOT NULL,
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP
)");
$stmt = $con->prepare("INSERT INTO marketing_reports (platform, report_html) VALUES (?, ?)");
$stmt->execute([$platform, $reportHtml]);
}
echo json_encode(['status' => 'success', 'message' => 'Posts evaluated and report saved']);
break;
default:
echo json_encode(['status' => 'error', 'message' => 'Invalid action']);
}