laravel-chatbot maintained by sakibulrasel
Laravel Chatbot
A Laravel package that adds a configurable rule-based chatbot to a Laravel application.
It includes:
- separate chatbot admin authentication
- questionnaire CRUD
- category CRUD
- unanswered-question review
- CSV questionnaire import/export
- analytics page
- embeddable frontend widget
- public chatbot API endpoints
Requirements
- PHP 8.2+
- Laravel 11 or 12
Installation
Install the package in a Laravel app:
composer require sakibulrasel/laravel-chatbot
Run the package installer:
php artisan chatbot:install
The install command will:
- publish the config file
- publish package migrations
- publish widget assets
- run migrations
- ask for chatbot admin credentials
- seed default settings
- optionally seed demo questions
Quick Start
After installation:
- Open the admin login:
/chatbot-admin/login
-
Log in with the credentials you created during
chatbot:install. -
Add or edit chatbot questions in:
/chatbot-admin/questionnaires
- Render the widget in any Blade view:
<x-chatbot-widget />
Package Routes
Admin Routes
Default admin prefix:
/chatbot-admin
Main admin pages:
/chatbot-admin/login/chatbot-admin/dashboard/chatbot-admin/analytics/chatbot-admin/categories/chatbot-admin/questionnaires/chatbot-admin/unanswered-questions/chatbot-admin/settings
Public Routes
Default public prefix:
/chatbot
Public endpoints:
GET /chatbot/widgetGET /chatbot/configPOST /chatbot/message
Widget Usage
Add the widget to any Blade template:
<x-chatbot-widget />
The widget uses published static assets:
public/vendor/chatbot/chatbot-widget.css
public/vendor/chatbot/chatbot-widget.js
If you need to republish them:
php artisan chatbot:publish-assets
Configuration
The package config file is published to:
config/chatbot.php
Important options:
- admin route prefix
- public route prefix
- fallback message
- welcome message
- widget position
- primary color
- enable/disable widget
- conversation logging
To republish config manually:
php artisan vendor:publish --tag=chatbot-config
Admin Authentication
This package does not depend on the host app's users table.
It uses its own chatbot_admins table and a session-based package login flow.
That keeps the chatbot admin isolated from the main application authentication layer.
Questionnaire Management
The questionnaire section supports:
- create, edit, and delete question/answer pairs
- category assignment
- active/inactive status
- keyword matching
- sort order
- search and filtering
- CSV import/export
CSV Import/Export
Questionnaire import expects this CSV header:
question,answer,keywords,category,status,sort_order
Example:
"What are your hours?","We are open 9 AM to 6 PM.","hours,time,open","General","active","1"
Behavior:
- existing questions are updated by
question - missing categories can be created automatically
statuscan use values likeactive,inactive,true,false,1,0
Unanswered Questions
If the chatbot cannot match a question strongly enough:
- it returns the fallback message
- it logs the user prompt to
chatbot_unanswered_questions
The admin can review those prompts at:
/chatbot-admin/unanswered-questions
From there, the admin can:
- convert a failed prompt into a questionnaire entry
- assign a category
- add keywords
- dismiss it
Analytics
Analytics are available at:
/chatbot-admin/analytics
Current analytics include:
- total conversations in a period
- resolved failures
- pending failures
- daily conversation counts
- top matched questions
- top failed questions
Available Artisan Commands
php artisan chatbot:install
php artisan chatbot:create-admin {username}
php artisan chatbot:reset-password {username}
php artisan chatbot:publish-assets
Manual Publish Commands
If you need manual publish steps instead of chatbot:install:
php artisan vendor:publish --tag=chatbot-config
php artisan vendor:publish --tag=chatbot-migrations
php artisan chatbot:publish-assets
php artisan migrate
Using In Another Laravel App Before Packagist
If the package is not yet published on Packagist, you can still use it through a local path repository.
In the target Laravel app's composer.json:
{
"repositories": [
{
"type": "path",
"url": "/absolute/path/to/laravel_chatbot"
}
]
}
Then install:
composer require sakibulrasel/laravel-chatbot:*
php artisan chatbot:install
Publishing To Packagist
Typical release flow:
git add .
git commit -m "Initial package release"
git push origin main
git tag v0.1.0
git push origin v0.1.0
Then submit the GitHub repository to Packagist.
After Packagist indexes the package, users can install it with:
composer require sakibulrasel/laravel-chatbot
Local Workbench
This repository includes a local Testbench workbench app for package verification.
Build it:
composer build
Serve it:
composer serve
Open:
http://127.0.0.1:8000http://127.0.0.1:8000/chatbot-admin/login
Default workbench admin credentials:
username: admin
password: password
Testing
Run the package tests with:
composer test
Current Scope
This package currently provides a stable first version of:
- admin auth
- widget
- questionnaires and categories
- unanswered review
- analytics
- CSV import/export
Still reasonable future additions:
- AI drivers
- richer dashboard charts
- multi-tenant support
- improved widget customization
- more extensive test coverage