PHP code example of bootdesk / chat-sdk-adapter-web
1. Go to this page and download the library: Download bootdesk/chat-sdk-adapter-web 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/ */
bootdesk / chat-sdk-adapter-web example snippets
use BootDesk\ChatSDK\Web\WebAdapter;
use BootDesk\ChatSDK\Web\WebAdapterConfig;
use BootDesk\ChatSDK\Core\Contracts\BroadcastAdapter;
use Psr\Http\Message\ServerRequestInterface;
class MyAppWebConfig extends WebAdapterConfig
{
public function getUser(ServerRequestInterface $request): ?array
{
return auth()->user()
? ['id' => (string) auth()->id(), 'name' => auth()->user()?->name]
: null;
}
public function verifySignature(ServerRequestInterface $request): bool|string
{
$signature = $request->getHeaderLine('X-Signature');
$payload = (string) $request->getBody();
$expected = 'sha256=' . hash_hmac('sha256', $payload, config('app.webhook_secret'));
return hash_equals($expected, $signature) ? true : 'Invalid signature';
}
}
$adapter = new WebAdapter(
userName: env('WEB_USER_NAME', 'Bot'),
config: new MyAppWebConfig,
broadcaster: $broadcaster, // Optional: BroadcastAdapter instance
asyncMode: true, // Optional: Enable async broadcasting
);
// Post a message in a web session
$adapter->postMessage('web:session-abc123', 'Hello from laravel-bootdesk!');
// Handle incoming webhook
// POST body: {"text": "Hi", "userId": "user-1", "sessionId": "session-abc123"}
use BootDesk\ChatSDK\Laravel\Broadcasting\LaravelBroadcastAdapter;
$broadcaster = new LaravelBroadcastAdapter(
broadcastManager: broadcast(),
broadcasterType: 'pusher',
channelPrefix: 'chat',
);
$adapter = new WebAdapter(
userName: 'Bot',
config: new MyAppWebConfig,
broadcaster: $broadcaster,
asyncMode: true, // Broadcast immediately; sync mode accumulates events
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.