1. Go to this page and download the library: Download rumenx/php-chatbot library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rumenx / php-chatbot example snippets
use Rumenx\PhpChatbot\PhpChatbot;
use Rumenx\PhpChatbot\Models\ModelFactory;
$config = ly = $chatbot->ask('Hello!');
echo $reply;
// src/Controller/ChatbotController.php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Rumenx\PhpChatbot\PhpChatbot;
use Rumenx\PhpChatbot\Models\ModelFactory;
class ChatbotController extends AbstractController
{
public function message(Request $request): JsonResponse
{
$config =
// routes/web.php
Route::post('/php-chatbot/message', function (Request $request) {
// ...existing code...
})->middleware('throttle:10,1'); // 10 requests per minute per IP
// routes/web.php
use Illuminate\Http\Request;
use Rumenx\PhpChatbot\PhpChatbot;
use Rumenx\PhpChatbot\Models\ModelFactory;
use Illuminate\Support\Facades\Log;
Route::post('/php-chatbot/message', function (Request $request) {
$config = config('phpchatbot');
$model = ModelFactory::make($config);
$chatbot = new PhpChatbot($model, $config);
$context = [
'prompt' => $config['prompt'],
'logger' => Log::getFacadeRoot(), // Optional PSR-3 logger
];
$reply = $chatbot->ask($request->input('message'), $context);
return response()->json(['reply' => $reply]);
});