sontus / laravel-support-chatbot
AI-powered support chatbot package for Laravel with direct Gemini and OpenAI integration.
Requires
- php: ^8.2
- illuminate/database: ^11.0|^12.0|^13.0
- illuminate/routing: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
This package is auto-updated.
Last update: 2026-05-05 10:52:34 UTC
README
A production-ready, AI-powered support chatbot package for Laravel applications. This package seamlessly integrates an intelligent, context-aware chatbot into your application. It uses direct HTTP integrations without heavy dependencies.
Features
- AI Integration: Directly supports OpenAI and Gemini models without requiring PHP 8.4 dependencies.
- Knowledge Base (RAG): Admin panel to add FAQs and documentation, searchable via AI embeddings.
- Context Awareness: The chatbot automatically understands the logged-in user, their orders, and tickets.
- Frontend Widget: A sleek, customizable, floating Vanilla JS widget for real-time chat. Drop it into any site!
- Queue System: Messages are processed asynchronously to maintain high performance.
- Multi-channel API: Interact via frontend widget or via exposed REST APIs.
- Multi-Tenancy Ready: Configurable database connection for tenant-specific deployments.
Installation
- Install via Composer:
composer require sontus/laravel-support-chatbot
- Run the installation command:
php artisan chatbot:install
- Run Migrations:
php artisan migrate
- Configure Environment:
Add the following to your
.envfile:
CHATBOT_AI_API_KEY="your_api_key_here" # For Gemini (Default) CHATBOT_AI_PROVIDER=gemini CHATBOT_AI_MODEL=gemini-2.0-flash # For OpenAI # CHATBOT_AI_PROVIDER=openai # CHATBOT_AI_MODEL=gpt-4o-mini
- Start the Queue Worker: Because the chatbot processes AI requests asynchronously to ensure high performance and avoid blocking your app, you need to run a queue worker:
php artisan queue:work
Usage
1. Frontend Chat Widget
The frontend widget is pure Vanilla JavaScript and includes its own styling. It works on any Laravel site without needing a Node/Vue compilation step.
Simply add the script tag before the closing </body> tag in your layout (e.g. resources/views/layouts/app.blade.php):
<script src="{{ asset('vendor/chatbot/chatbot-widget.js') }}"></script>
Add a meta tag for CSRF and optionally User ID if authenticated (in your <head>):
<meta name="csrf-token" content="{{ csrf_token() }}"> @auth <meta name="user-id" content="{{ auth()->id() }}"> @endauth
2. Admin Panel
To train the chatbot and view conversations, visit the admin dashboard:
URL: /admin/chatbot
Ensure your admin users pass the configured middleware (web, auth).
3. Customizing Context
You can bind your own ContextResolver in your application's AppServiceProvider if you want to provide custom data (like specific tenant data) to the AI:
use Sontus\SupportChatbot\Services\ContextResolver; $this->app->bind(ContextResolver::class, function ($app) { return new class extends ContextResolver { public function resolveForUser($user = null): array { // Return any array of data you want the AI to know about this user return [ 'name' => $user->name, 'subscription_plan' => $user->plan->name, ]; } }; });
4. API Endpoints
POST /api/chatbot/message(Requiresmessage, andsession_idoruser_id)GET /api/chatbot/history(Requiressession_idoruser_id)
License
MIT