1. Go to this page and download the library: Download uchara/uchara-php 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/ */
uchara / uchara-php example snippets
chara\SDK\ServerSDK;
$client = new ServerSDK(
apiUrl: 'https://api.uchara.com',
apiKey: getenv('UCHARA_API_KEY')
);
// Send a message
$message = $client->sendMessage('conv_abc123', [
'content' => 'Your order has shipped!',
'sender_type' => 'bot',
]);
echo "Message sent: {$message['id']}\n";
// List conversations
$conversations = $client->listConversations([
'status' => 'open',
'limit' => 10,
]);
foreach ($conversations as $conv) {
echo "Conversation: {$conv['id']} - {$conv['contact_name']}\n";
}
// Authorized assignee/admin invites an existing workspace member to collaborate.
$agent->inviteToConversation('conv_abc123', 'member_456');
// The invited agent (a separate authenticated AgentSDK session) accepts by joining.
// Join persists multi-agent membership and emits `conversation.joined`.
$agent->joinConversation('conv_abc123');
// The joined agent can now operate as a collaborator (send messages, add notes,
// resolve, etc.) on the conversation.
$agent->sendMessage('conv_abc123', ['content' => 'Saya ikut menangani.']);
// A collaborator removes their membership when done.
$agent->leaveConversation('conv_abc123');
// Bot-to-agent takeover (distinct from collaborator approval).
$agent->takeoverConversation('conv_abc123');
// Backend only — UCHARA_API_KEY must remain server-side.
$server = new ServerSDK('https://api.uchara.com', getenv('UCHARA_API_KEY'));
$session = $server->createAgentSession('[email protected]');
// Return $session to your dashboard frontend over your own authenticated HTTPS endpoint.
chara\SDK\ServerSDK;
// Backend only — UCHARA_API_KEY must remain server-side.
$server = new ServerSDK('https://api.uchara.com', getenv('UCHARA_API_KEY'));
// Issue a one-time ticket for the target member (optional channel scope).
$result = $server->http()->post('/v1/auth/sso/ticket', [
'email' => '[email protected]',
// 'channel_ids' => ['<channel-uuid>'], // optional; omitted = full workspace
]);
// Return $result['redirect_url'] from your own authenticated HTTPS endpoint.
// The browser opens it; the dashboard bootstrap exchanges the ticket and
// strips it from the URL.
$redirectUrl = $result['redirect_url'];
use Uchara\SDK\DeliveryStatus;
if ($message['delivery_status'] === DeliveryStatus::READ) {
// the recipient has read the message
}
// Visitor marks the responder's messages as read (widget)
$visitor->markConversationRead($conversationId); // ['updated' => int]
// Agent marks the visitor's messages as read (dashboard)
$agent->markConversationRead($conversationId); // ['marked_read' => int]
use Uchara\SDK\Uchara;
$server = Uchara::server('https://api.uchara.com', 'uchara_sk_...');
$agent = Uchara::agent('https://api.uchara.com');
$visitor = Uchara::visitor('https://api.uchara.com', 'widget_token_...');
// From a config array
$sdk = Uchara::make([
'api_url' => 'https://api.uchara.com',
'api_key' => 'uchara_sk_...',
'access_token' => 'agent_access_token',
'default' => 'server', // or 'agent' or 'visitor'
]);