Looking to hire Laravel developers? Try LaraJobs

laravel-ai-chat-bot maintained by yu-laravel

Description
AI chat widget for Laravel with multiple LLM providers, persistent conversation history, function-calling tools, and human handoff to Telegram.
Author
Last update
2026/09/17 12:45 (dev-main)
License
Links
Downloads
34

Comments
comments powered by Disqus

Laravel AI Chat Bot

Conversational AI chat widget for Laravel applications with a pluggable LLM provider. Persists conversation history, supports LLM function-calling tools, and can hand a conversation off to a human administrator over Telegram.

Installation

composer require yu-laravel/laravel-ai-chat-bot
php artisan vendor:publish --tag=ai-chat-config
php artisan vendor:publish --tag=ai-chat-assets
php artisan migrate

Set your OpenAI key in .env:

AI_CHAT_LLM_OPEN_AI_API_KEY=sk-...

Usage

Include the widget in a Blade layout:

@include('ai-chat::widget')

See config/ai-chat.php (after publishing) for all available options - LLM provider, widget theme, system prompt, Telegram handoff, and more.

LLM provider

OpenAI and Anthropic are both supported out of the box, selected via AI_CHAT_LLM_DEFAULT (open_ai or anthropic; open_ai is the default). Set the matching API key (AI_CHAT_LLM_OPEN_AI_API_KEY or AI_CHAT_LLM_ANTHROPIC_API_KEY) for whichever one you use. To add another provider, implement Yu\AiChatBot\Contracts\LlmProviderInterface and Yu\AiChatBot\Contracts\LlmSettingsInterface, then point provider_class/settings_class for that provider at your classes in config/ai-chat.php.

Human handoff via Telegram

When the AI can't answer from the data it has, or the customer explicitly asks to talk to a person, it hands the conversation off to a human administrator over Telegram instead of guessing. From that point, the customer's messages are relayed to your admin chat, and the admin's replies (sent as Telegram replies to that message) show up back in the widget - no LLM involved for the rest of that conversation.

To enable it, set in .env:

AI_CHAT_TELEGRAM_BOT_TOKEN=...
AI_CHAT_TELEGRAM_ADMIN_CHAT_ID=...
AI_CHAT_TELEGRAM_WEBHOOK_SECRET=...

Then register the webhook with Telegram so admin replies reach your app:

curl -X POST "https://api.telegram.org/bot<BOT_TOKEN>/setWebhook" \
    -d "url=https://your-app.example/ai-chat/telegram-webhook" \
    -d "secret_token=<AI_CHAT_TELEGRAM_WEBHOOK_SECRET>"

Widget themes

The widget ships with several color themes: blue, purple, orange, red, pink, indigo, emerald, amber, slate, periwinkle, plus the default (teal) theme built into the base CSS. Pick one with:

AI_CHAT_WIDGET_THEME=purple

Each theme is just a small CSS override of the widget's color variables (resources/dist/themes/<name>.css) — copy one and register your own name to make a custom color scheme.

Adding custom tools

The chat can call your own PHP code while answering a customer (look up an order, check stock, etc.). See docs/creating-tools.md for how to write and register a tool.