PHP code example of omnifox / sdk

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

    

omnifox / sdk example snippets



Omnifox\OmnifoxClient;

$omnifox = new OmnifoxClient([
    'apiKey' => getenv('OMNIFOX_API_KEY'),
    'workspaceId' => 1,                                  // optional, see "Workspaces"
    // 'baseUrl' => 'https://app.omnifox.io/api/v1',     // default
    // 'timeout' => 30,                                  // seconds
    // 'maxRetries' => 3,                                // on 429 / 5xx / connection errors
]);

// Look a contact up by id, email, phone or external id.
$contact = $omnifox->contacts->get('email:[email protected]');

// Send a WhatsApp text.
$omnifox->messages->send([
    'contact' => 'phone:+593987654321',
    'channel_id' => 5,
    'text' => 'Hello from the Omnifox PHP SDK',
]);

// Walk every open conversation; pages are fetched on demand.
foreach ($omnifox->conversations->list(['status' => 'open']) as $conversation) {
    echo $conversation['id'], PHP_EOL;
}

'omnifox' => [
    'key' => env('OMNIFOX_API_KEY'),
    'workspace_id' => env('OMNIFOX_WORKSPACE_ID'),
],

use Omnifox\OmnifoxClient;

$this->app->singleton(OmnifoxClient::class, fn () => new OmnifoxClient([
    'apiKey' => config('services.omnifox.key'),
    'workspaceId' => config('services.omnifox.workspace_id'),
]));

use Omnifox\Exception\ValidationException;
use Omnifox\OmnifoxClient;

class SyncLeadToOmnifox
{
    public function __construct(private OmnifoxClient $omnifox) {}

    public function handle(Lead $lead): void
    {
        try {
            $contact = $this->omnifox->contacts->upsert([
                'unique_by' => ['email'],
                'email' => $lead->email,
                'display_name' => $lead->name,
            ], ['idempotencyKey' => "lead-{$lead->id}"]);

            $this->omnifox->contacts->attachTagsByName($contact['id'], ['web-lead']);
        } catch (ValidationException $e) {
            logger()->warning('Omnifox rejected the lead', $e->getFieldErrors());
        }
    }
}

$omnifox->contacts->get(42);
$omnifox->contacts->get('email:[email protected]');
$omnifox->contacts->get('phone:+593987654321');
$omnifox->contacts->get('external:crm-123');

foreach ($omnifox->contacts->list(['per_page' => 100]) as $contact) {
    // every contact of the workspace
}

$first25 = $omnifox->contacts->list()->toArray(25);

$page = $omnifox->contacts->listPage(['page' => 2]);
$page->data;      // list of rows
$page->hasMore;   // bool
$page->page;      // page mode: current page / lastPage / total
$page->nextCursor; // cursor mode

use Omnifox\Exception\ConflictException;

try {
    $omnifox->appointments->book(['calendar_id' => 3, 'starts_at' => '2026-10-20T15:00:00Z']);
} catch (ConflictException $e) {
    // the slot was taken in the meantime: offer another one
}

$omnifox->orders->create($order, [
    'idempotencyKey' => $uuid,   // Idempotency-Key header
    'maxRetries' => 0,
    'timeout' => 10,             // seconds (default Guzzle transport only)
    'headers' => ['X-Trace-Id' => $traceId],
]);

// Assignment is an assignee_type + assignee_id pair: user | team | ai_agent | none.
$omnifox->conversations->assign($id, ['assignee_type' => 'team', 'assignee_id' => 3, 'only_online' => true]);
$omnifox->conversations->assign($id, []);   // unassign

// Closing reads `resolution` and `notes`.
$omnifox->conversations->close($id, ['resolution' => 'resolved', 'notes' => 'Refund sent']);

// WhatsApp / TikTok only allow free text for 24 h after the customer's last message.
if (!$omnifox->conversations->windowStatus($id)['open']) {
    // send an approved template instead
}

$contact = $omnifox->contacts->create(['display_name' => 'Ada Lovelace', 'email' => '[email protected]']);
$omnifox->contacts->merge(['primary_contact_id' => $keep, 'merged_contact_id' => $duplicate]);
$omnifox->contacts->attachTagsByName($contact['id'], ['vip', 'newsletter']);
$omnifox->contacts->detachTagsByName($contact['id'], ['newsletter']);   // a DELETE with a body
$omnifox->contacts->sendMessage($contact['id'], [
    'channelId' => 5,
    'message' => ['type' => 'text', 'text' => 'Hi Ada'],
]);

$pipeline = $omnifox->pipelines->create(['name' => 'Sales']);
$stage = $omnifox->pipelines->createStage($pipeline['id'], ['name' => 'Won', 'is_won' => true]);
$deal = $omnifox->deals->create(['title' => 'ACME renewal', 'pipeline_id' => $pipeline['id'], 'amount' => 1500]);
$omnifox->deals->moveToStage($deal['id'], $stage['id']);
$omnifox->crmActivities->create('deal', $deal['id'], ['type' => 'call', 'title' => 'Follow-up']);
$omnifox->deals->close($deal['id'], ['result' => 'won']);

$slots = $omnifox->appointments->slots(['calendar_id' => 3, 'from' => '2026-10-20', 'to' => '2026-10-27']);

$appointment = $omnifox->appointments->book([
    'calendar_id' => 3,
    'starts_at' => '2026-10-21T15:00:00Z',
    'contact_id' => 42,
    'location_type' => 'video_omnifox',          // Omnifox video room, created on the fly
    'video_options' => ['translate_mode' => 'voice', 'host_lang' => 'es', 'guest_lang' => 'en'],
]);
$appointment['video_guest_url'];

$product = $omnifox->products->create(['name' => 'Espresso', 'unit_price' => 2.5, 'is_orderable' => true]);

// Send product + quantity: the server prices each line from the catalog and the
// workspace tax settings. (An explicit unit_price is honoured as a manual override.)
$order = $omnifox->orders->create([
    'items' => [['product_id' => $product['id'], 'quantity' => 2]],
    'fulfillment' => 'pickup',
    'customer_name' => 'Ada',
]);
$omnifox->orders->setStatus($order['id'], 'confirmed');
$omnifox->orders->recordPayment($order['id'], 5.0, 'cash');

$quote = $omnifox->quotes->create(['currency' => 'USD', 'items' => [['product_id' => $product['id'], 'quantity' => 10]]]);
$omnifox->quotes->pdf($quote['id'])->saveTo('/tmp/quote.pdf');   // binary, not JSON
$omnifox->quotes->send($quote['id'], ['channels' => ['email' => true]]);

$board = $omnifox->boards->create(['name' => 'Onboarding', 'template' => 'blank']);
$item = $omnifox->boardItems->create($board['id'], ['title' => 'Kick-off call']);
$omnifox->boardItems->setCellValue($item['id'], $columnId, 'Done');
bash
composer install
composer test                       # unit tests (no network)

OMNIFOX_TOKEN=... OMNIFOX_WORKSPACE_ID=1 \
OMNIFOX_E2E_WORKFLOW_ID=12 OMNIFOX_E2E_BROADCAST_ID=1 \
php tests/e2e/e2e.php --write       # live run; deletes what it creates