PHP SDK
Official PHP SDK for backend integration with the Uchara Chat Platform.
Requirements
Section titled “Requirements”- PHP 8.0+
- Composer
- ext-json
Installation
Section titled “Installation”composer require uchara/sdkServer SDK
Section titled “Server SDK”<?php
require 'vendor/autoload.php';
use Uchara\SDK\ServerSDK;use Uchara\SDK\UcharaException;
$client = new ServerSDK( apiUrl: 'https://api.uchara.com', apiKey: getenv('UCHARA_API_KEY'));
try { // Send a message $message = $client->sendMessage('conv_abc123', [ 'content' => 'Your order has shipped! 🚚', 'sender_type' => 'bot', ]); echo "Message sent: {$message['id']}\n";
// List open conversations $conversations = $client->listConversations([ 'status' => 'open', 'limit' => 10, ]);
foreach ($conversations as $conv) { echo "{$conv['id']} - {$conv['contact_name']}\n"; }
// Upsert contact (match by external_id) $contact = $client->upsertContact([ 'external_id' => 'user_123', 'name' => 'John Doe', 'email' => 'john@example.com', ]);
echo "Contact: {$contact['id']}\n";
} catch (UcharaException $e) { echo "Error ({$e->getCode()}): {$e->getMessage()}\n"; if ($e->getDetails()) { print_r($e->getDetails()); }}Available Methods
Section titled “Available Methods”// Contacts$client->upsertContact(array $data): array$client->getContact(string $id): array$client->listContacts(array $options = []): array
// Conversations$client->getConversation(string $id): array$client->listConversations(array $filters = []): array$client->assignConversation(string $id, ?string $agentId): array$client->resolveConversation(string $id): array
// Messages$client->sendMessage(string $convId, array $data): array$client->getMessages(string $convId, array $options = []): array
// Channels & Members$client->listChannels(): array$client->listMembers(): arrayLaravel Example
Section titled “Laravel Example”return [ 'uchara' => [ 'api_url' => env('UCHARA_API_URL', 'https://api.uchara.com'), 'api_key' => env('UCHARA_API_KEY'), ],];
// app/Providers/AppServiceProvider.phppublic function register(): void{ $this->app->singleton(ServerSDK::class, fn() => new ServerSDK( apiUrl: config('services.uchara.api_url'), apiKey: config('services.uchara.api_key'), ));}
// In a controller / jobpublic function notify(ServerSDK $uchara, Order $order): void{ $uchara->sendMessage($order->conversation_id, [ 'content' => "Order #{$order->id} has shipped!", 'sender_type' => 'bot', ]);}