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
+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']);
}