This commit is contained in:
2025-12-28 12:16:05 +05:45
commit 7c46ec6731
3358 changed files with 467149 additions and 0 deletions

View File

@@ -0,0 +1,195 @@
<?php
namespace Modules\Chatbot\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\RequestException;
class ChatbotController extends Controller
{
public function index()
{
return view('chatbot::index');
}
public function create()
{
return view('chatbot::create');
}
public function store(Request $request)
{
//
}
public function show($id)
{
return view('chatbot::show');
}
public function edit($id)
{
return view('chatbot::edit');
}
public function update(Request $request, $id)
{
//
}
public function destroy($id)
{
//
}
public function queryold(Request $request)
{
$message = $request->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 = <<<EOT
// You are an assistant for Rohini International Education Services in Nepal.
// Use *only* the following facts when answering:
// • Website: https://rohini.edu.np/
// • Phone: {$phone}
// • Email: {$email}
// • Address: {$address}
// EOT;
// // 3) Prepare the message payload
// $messages = [
// ['role' => '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 <a href=\"https://rohini.edu.np/\" target=\"_blank\">https://rohini.edu.np/</a> or contact us: Phone: <a href=\"tel:{$phone}\">{$phone}</a>, Email: <a href=\"mailto:{$email}\">{$email}</a>, WhatsApp: <a href=\"{$whatsapp}\" target=\"_blank\">{$whatsapp}</a>.";
// 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 <a href=\"{$instagram}\" target=\"_blank\">Instagram</a>, <a href=\"{$youtube}\" target=\"_blank\">Youtube</a>, <a href=\"{$tiktok}\" target=\"_blank\">Tiktok</a>."
],
];
// 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
]);
}
}

View File

View File

@@ -0,0 +1,135 @@
<?php
namespace Modules\Chatbot\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
class ChatbotServiceProvider extends ServiceProvider
{
use PathNamespace;
protected string $name = 'Chatbot';
protected string $nameLower = 'chatbot';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->name, 'database/migrations'));
}
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->register(EventServiceProvider::class);
$this->app->register(RouteServiceProvider::class);
}
/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
// $this->commands([]);
}
/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
// $this->app->booted(function () {
// $schedule = $this->app->make(Schedule::class);
// $schedule->command('inspire')->hourly();
// });
}
/**
* Register translations.
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/'.$this->nameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->nameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->nameLower);
$this->loadJsonTranslationsFrom(module_path($this->name, 'lang'));
}
}
/**
* Register config.
*/
protected function registerConfig(): void
{
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);
if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));
foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;
$this->publishes([$file->getPathname() => config_path($relativePath)], 'config');
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/'.$this->nameLower);
$sourcePath = module_path($this->name, 'resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower);
$componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path')));
Blade::componentNamespace($componentNamespace, $this->nameLower);
}
/**
* Get the services provided by the provider.
*/
public function provides(): array
{
return [];
}
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path.'/modules/'.$this->nameLower)) {
$paths[] = $path.'/modules/'.$this->nameLower;
}
}
return $paths;
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Modules\Chatbot\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event handler mappings for the application.
*
* @var array<string, array<int, string>>
*/
protected $listen = [];
/**
* Indicates if events should be discovered.
*
* @var bool
*/
protected static $shouldDiscoverEvents = true;
/**
* Configure the proper event listeners for email verification.
*/
protected function configureEmailVerification(): void
{
//
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Modules\Chatbot\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
protected string $name = 'Chatbot';
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*/
public function boot(): void
{
parent::boot();
}
/**
* Define the routes for the application.
*/
public function map(): void
{
$this->mapApiRoutes();
$this->mapWebRoutes();
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*/
protected function mapWebRoutes(): void
{
Route::middleware('web')->group(module_path($this->name, '/routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*/
protected function mapApiRoutes(): void
{
Route::middleware('api')->prefix('api')->name('api.')->group(module_path($this->name, '/routes/api.php'));
}
}

View File