date('Y-m-d H:i:s'), 'event' => 'ai_agent_hired', 'agent' => $agentType, 'email' => $email, 'session_id' => $sessionId, 'amount' => $amount ]; // Save to hires log $logFile = '/var/www/hostpioneers.com/public_html/api/hires.log'; $existing = file_exists($logFile) ? json_decode(file_get_contents($logFile), true) : []; $existing[] = $log; file_put_contents($logFile, json_encode($existing, JSON_PRETTY_PRINT)); // Send Telegram notification $telegramToken = '8644418426:AAEL8GvHwohNDkxaru5yCZFPgh5Gsc-yAhA'; $chatId = '382315644'; $text = "🤖 *AI AGENT HIRED!* *Agent:* $agentType *Email:* $email *Amount:* $" . number_format($amount, 2) . " *Session:* $sessionId"; $ch = curl_init("https://api.telegram.org/bot$telegramToken/sendMessage?chat_id=$chatId&text=" . urlencode($text) . "&parse_mode=Markdown"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_exec($ch); curl_close($ch); // Send email $to = 'sales@hostpioneers.com'; $subject = "🤖 AI Agent Hired: $agentType - $" . number_format($amount, 2); $body = "AI Agent hired! Agent: $agentType Customer: $email Amount: $" . number_format($amount, 2) . " Session: $sessionId --- This was an automated notification from HostPioneers API."; @mail($to, $subject, $body); echo json_encode(['success' => true, 'message' => 'Hire logged and notifications sent']); } else { echo json_encode(['success' => true, 'message' => 'Event ignored']); }