PHP code example of chatbridge / php-sdk

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

    

chatbridge / php-sdk example snippets


use ChatBridge\Sdk\ClientFactory;
use ChatBridge\Sdk\Config\ClientConfig;
use ChatBridge\Sdk\Idempotency\IdempotencyKey;
use ChatBridge\Sdk\Messages\Message;
use ChatBridge\Sdk\Recipients\ExternalContactRecipient;

$client = (new ClientFactory)->make(new ClientConfig(
    baseUrl: 'https://chatbridge.example',
    clientId: 'cbic_01J00000000000000000000000',
    clientSecret: 'cbis_REPLACE_WITH_ONE_TIME_SECRET',
    webhookSecrets: ['cbwh_REPLACE_WITH_WEBHOOK_SECRET'],
));

$contact = $client->contacts()->upsert(
    externalKey: 'example-app:lead:123',
    accountId: '2',
    phoneE164: '+60123456789',
    displayName: 'Aminah Ismail',
);

$key = IdempotencyKey::fromParts(
    'example-app',
    'production',
    'agency',
    '42',
    'lead',
    '123',
    'suggestion',
    '9001',
    'send-v1',
);

$sent = $client->messages()->send(
    accountId: '2',
    recipient: new ExternalContactRecipient('example-app:lead:123'),
    message: Message::text('Hello'),
    idempotencyKey: $key,
    externalReference: 'example-app:lead:123:suggestion:9001',
);

$conversation = $client->conversations()->get($sent->conversationId);

$event = $client->webhooks()->verifyAndParse(
    payload: $request->getContent(),
    signature: (string) $request->header('X-ChatBridge-Signature'),
    timestamp: (string) $request->header('X-ChatBridge-Timestamp'),
    eventId: $request->header('X-ChatBridge-Event-Id'),
    eventType: $request->header('X-ChatBridge-Event-Type'),
    webhookVersion: $request->header('X-ChatBridge-Webhook-Version'),
);
bash
composer 
bash
php artisan vendor:publish --tag=chatbridge-config