input('message'); return response()->json(['reply' => 'You said: ' . $message]); } // public function query(Request $request) // { // $request->validate([ // 'message' => 'required|string' // ]); // // 1) Pull the current contact details from settings // $phone = setting('phone'); // e.g. "5344710" // $email = setting('email'); // e.g. "info@rohini.edu.np" // $address = setting('address'); // e.g. "House #160, Adwait Marg, Putalisadak, Kathmandu, Nepal" // $facebook = setting('facebook'); // if you have this // $whatsapp = setting('whatsapp'); // if you have this // $userMessage = trim($request->message); // // 2) Build a system prompt that *includes* your real contact info // $systemContents = << 'system', 'content' => $systemContents], // ['role' => 'user', 'content' => $userMessage], // ]; // // 4) Call the AI as before // try { // $response = Http::timeout(60) // ->retry(2, 100) // ->withToken(config('services.openrouter.key')) // ->post('https://openrouter.ai/api/v1/chat/completions', [ // 'model' => 'deepseek/deepseek-r1:free', // 'messages' => $messages, // ]); // $response->throw(); // // 5) Return exactly what the AI gave, knowing the system prompt constrained it // return response()->json([ // 'reply' => $response->json('choices.0.message.content') ?? 'No response from assistant.' // ]); // } catch (ConnectionException $e) { // return response()->json([ // 'reply' => 'Sorry, I could not connect to the AI service. Please try again later.' // ], 504); // } catch (RequestException $e) { // $msg = $e->response->json('error.message') ?? $e->getMessage(); // return response()->json([ // 'reply' => 'Sorry, an error occurred. Please try again later.', // 'error' => $msg // ], 500); // } // } public function query(Request $request) { $request->validate([ 'message' => 'required|string' ]); // Company info $phone = setting('phone'); $email = setting('email'); $address = setting('location'); $whatsapp = setting('whatsapp'); $instagram = setting('instagram'); $youtube = setting('youtube'); $tiktok = setting('tiktok'); $userMessage = strtolower(trim($request->message)); $companyInfo = "\n\nFor more information, visit https://rohini.edu.np/ or contact us: Phone: {$phone}, Email: {$email}, WhatsApp: {$whatsapp}."; // Define topics instead of strict questions $topics = [ 'greeting' => [ 'keywords' => ['hi','hello','hey','good morning','good afternoon','good evening'], 'response' => 'Hello! How can I assist you with your study abroad plans today?' ], 'company_info' => [ 'keywords' => ['rohini', 'about us', 'who are you', 'information'], 'response' => 'Rohini International Education Services is a Nepal-based consultancy specializing in guiding students who want to study in New Zealand.' ], 'location' => [ 'keywords' => ['location','located','where'], 'response' => "Our Kathmandu office is at {$address}." ], 'contact' => [ 'keywords' => ['contact','support','call','email','whatsapp'], 'response' => "You can call us at {$phone}, email at {$email}, or message on WhatsApp at {$whatsapp}." ], 'services' => [ 'keywords' => ['service','services','what do you offer','help','assistance','counseling','visa','course','accommodation'], 'response' => 'We provide counseling, university & course selection, visa support, documentation help, pre-departure briefings, financial & scholarship guidance, and accommodation support for students going to New Zealand.' ], 'test_preparation' => [ 'keywords' => ['ielts','pte','test','exam','preparation','coaching','classes'], 'response' => 'Yes, we offer IELTS and PTE preparation with experienced instructors.' ], 'application_process' => [ 'keywords' => ['process','apply','application','visa','eligibility','documents'], 'response' => 'We guide students through course selection, eligibility, document preparation, visa application, and departure preparation.' ], 'new_zealand_education' => [ 'keywords' => ['new zealand','study in new zealand','higher education','university','study abroad','post study','work opportunities', 'newzealand'], 'response' => 'New Zealand offers globally recognized qualifications, high-quality education, a safe environment, and post-study work opportunities.' ], 'accommodation' => [ 'keywords' => ['hostel','homestay','flat','housing','accommodation','stay'], 'response' => 'Students can choose shared flats, homestays, hostels, or on-campus housing. We assist in finding the right option.' ], 'social_media' => [ 'keywords' => ['social media','instagram','youtube','tiktok','follow','socials','facebook'], 'response' => "Follow us on Instagram, Youtube, Tiktok." ], ]; // Match by topic keywords foreach ($topics as $topic) { foreach ($topic['keywords'] as $keyword) { if (str_contains($userMessage, strtolower($keyword))) { return response()->json(['reply' => $topic['response'] . $companyInfo]); } } } // Fallback for unknown queries: just show company info return response()->json([ 'reply' => "I'm here to help with questions about Rohini International Education Services and studying in New Zealand." . $companyInfo ]); } }