Search by

kavchat / kavchat-php

maxsave

Kavchat server SDK for PHP: identity tokens, webhook verification and the Server API

0.0.11 2026-10-30 14:41 UTC

This package is auto-updated.

Last update: 2026-10-30 14:42:22 UTC


README

Kavchat server SDK for PHP 8.1+. Uses ext-curl and ext-json, with no other dependencies.

Install

composer require kavchat/kavchat-php

Setup

use Kavchat\Kavchat;

$kavchat = new Kavchat(
    getenv('KAVCHAT_SECRET_KEY'),
    // baseUrl: 'https://api.kavchat.com',
    // timeout: 30.0,
    // locale: 'en',
);

Identify your users

$token = $kavchat->createUserToken(
    'user_123',              // required, 1 to 128 characters
    phone: '+972501234567',
    name: 'Dana',
    email: 'dana@example.com',
    expiresIn: 7 * 24 * 3600 // seconds, default 7 days, at most 30 days
);

Kavchat\Identity::createUserToken($secretKey, ...) is the static version.

Verify webhooks

use Kavchat\WebhookVerificationException;

try {
    $event = $kavchat->verifyWebhook(
        file_get_contents('php://input'),
        $_SERVER['HTTP_KAVCHAT_SIGNATURE'] ?? null,
    );
} catch (WebhookVerificationException $e) {
    http_response_code(400);
    exit($e->errorCode);
}

if ($event->type === 'ticket.created') {
    error_log('New ticket ' . $event->data->number);
}

$event->data is a Kavchat\Model\Ticket. $event->raw holds the decoded array.

Server API

$kavchat->getWorkspace();
$kavchat->listTickets(status: 'open', limit: 50, before: 120);
$kavchat->getTicket($id);
$kavchat->setTicketStatus($id, 'closed');
$kavchat->getReports(new DateTimeImmutable('2026-01-01'), new DateTimeImmutable());
$kavchat->getSettings();
$kavchat->updateSettings(audience: 'testers', testerPhones: ['+972501234567']);
$kavchat->listReleases();

Errors throw Kavchat\ApiException with $status, $errorCode, getMessage() and $details. (getCode() is reserved by PHP for integers, so the string code is in $errorCode.) $status is 0 for timeout and network_error.

Tests

composer install
vendor/bin/phpunit

The client tests start a local php -S server.

License and support

MIT. Documentation: https://kavchat.com/docs/. Questions: support@kavchat.com.