PHP code example of orchestratexr / botman-chat-sdk

1. Go to this page and download the library: Download orchestratexr/botman-chat-sdk 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/ */

    

orchestratexr / botman-chat-sdk example snippets


use OrchestrateXR\SuperBotMan\Facades\SuperBotMan;
use OrchestrateXR\SuperBotMan\Channels\WebChannel;

SuperBotMan::registerAgent('chat', \App\Agents\ChatAgent::class)
    ->channel(WebChannel::class);

namespace App\Agents;

use Laravel\Ai\Attributes\Provider;
use Laravel\Ai\Attributes\Model;
use Laravel\Ai\Concerns\RemembersConversations;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\Conversational;
use Laravel\Ai\Enums\Lab;
use Laravel\Ai\Promptable;

#[Provider(Lab::Anthropic)]
#[Model('claude-sonnet-4-5')]
class ChatAgent implements Agent, Conversational
{
    use Promptable, RemembersConversations;

    public function instructions(): string
    {
        return 'You are a helpful assistant.';
    }
}

namespace App\Services;

use OrchestrateXR\SuperBotMan\SuperBotManConfigurator;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Auth;

class MyChat extends SuperBotManConfigurator
{
    public function agentUser(): Authenticatable
    {
        return Auth::user() ?? parent::agentUser();
    }

    public function isAnonymous(Authenticatable $user): bool
    {
        // E.g. for an app that authenticates everyone as a real user
        // and uses an `is_anonymous` flag for the shared visitor account:
        return $user->is_anonymous ?? parent::isAnonymous($user);
    }
}

// AppServiceProvider::register()
$this->app->singleton(
    \OrchestrateXR\SuperBotMan\Contracts\SuperBotManConfigurator::class,
    fn ($app) => new \App\Services\MyChat($app),
);

interface Channel
{
    public function inbound(Request $request): InboundMessage;
    public function outbound(AgentRunResult $result, ClientActionBag $actions, InboundMessage $inbound): Response;
    public function middleware(): array;            // ['web'], ['api', 'slack.signature'], ...
    public function endpoints(): array;             // [['POST', '/']], or multi-endpoint
    public function supportsConversationHistory(): bool;
}

SuperBotMan::registerAgent('support', \App\Agents\SupportAgent::class)
    ->channel(\App\Channels\SlackChannel::class)
    ->middleware(['slack.signature']);
bash
php artisan vendor:publish --tag=super-botman-config
php artisan vendor:publish --tag=super-botman-views
php artisan vendor:publish --tag=super-botman-assets
php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"
php artisan migrate