Chat
2. PHP Chat Classes & Targets
Creating a Chat Class
Creating a Chat Class
Each chat in your application is represented by a PHP class extending Tokomono\Chat\Chat. Because every setting is defined as a method, you can use Laravel's localization helper (__('...')) and dynamic runtime logic.
Generating a Chat Class via Artisan
Use the chat:make Artisan command to generate a new Chat class in app/Chats with a deployable hash:
php artisan chat:make SupportChat --target="App\Ai\Agents\SupportAgent"
Example Chat Class
<?php
namespace App\Chats;
use App\Ai\Agents\SupportAgent;
use Tokomono\Chat\Chat;
use Tokomono\Chat\DTOs\ChatFileDto;
class SupportChat extends Chat
{
/**
* Deployable unique hash used by the Vue component (<TokomonoChat hash="support_9f8a7b6c" />)
*/
public function getHash(): string
{
return 'support_9f8a7b6c';
}
/**
* Can be a Laravel AI Agent class, an AI-Suite Agent sync_hash, or an AI-Suite Workflow class/sync_hash.
*/
public function target(): string
{
return SupportAgent::class;
}
public function title(): string
{
return __('chat.support_title');
}
public function description(): string
{
return __('chat.support_description');
}
public function welcomeMessage(): string
{
return __('chat.welcome_message');
}
public function allowGuests(): bool
{
return true; // Allows unauthenticated users (user_id = null)
}
public function canSendLocation(): bool
{
return true; // Shows the GPS location button in the chat input bar
}
public function playSound(): bool
{
return true; // Plays notification sound when minimized in TokomonoChatWidget
}
public function maxConversations(): int
{
return 5; // Set to 1 to hide the "New Conversation" button
}
/**
* Override allowed file extensions and maximum size in KB using ChatFileDto.
*
* @return array<int, ChatFileDto>
*/
public function allowedAttachments(): array
{
return [
new ChatFileDto(['jpg', 'jpeg', 'png'], 1024),
new ChatFileDto(['pdf'], 5120),
];
}
public function rateLimitPerMinute(): int
{
return 10;
}
public function maxMessageLength(): int
{
return 1500;
}
public function maxTokens(): int
{
return 4096;
}
}