PHP code example of getokta / okta-connect-sdk
1. Go to this page and download the library: Download getokta/okta-connect-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/ */
getokta / okta-connect-sdk example snippets
use Okta\Connect\WhatsApp\Client;
$client = new Client(
baseUrl: 'https://connect.example.com',
token: 'sanctum_token_here',
options: ['timeout' => 30, 'retries' => 2],
);
// Typed helpers build the correct request shape for you:
$client->messages()->sendText('01H...channel', '966500000000', 'Hello');
$client->messages()->sendMedia('01H...channel', '966500000000', 'image', 'https://cdn.example.com/a.jpg', 'Look!');
$client->messages()->reply('01H...conversation', 'Thanks!');
// Or send a raw payload (flat shape: channel_id + wa_id + body, or conversation_id + body):
$client->messages()->send([
'channel_id' => '01H...',
'wa_id' => '966500000000',
'type' => 'text',
'body' => 'Hello',
]);
$messages = $client->messages()->list(['conversation_id' => '01H...', 'per_page' => 50]);
$conversations = $client->conversations()->list();
$conversation = $client->conversations()->get($id);
$contacts = $client->contacts()->list(['search' => '+966']);
$client->contacts()->upsert(['phone' => '+9665...', 'name' => 'Ali']);
$channels = $client->channels()->list();
$client->webhooks()->register(['url' => 'https://...', 'events' => ['message.received']]);
// Meta message templates
$templates = $client->templates()->list(['status' => 'APPROVED', 'language' => 'ar']);
$client->templates()->send([
'channel_id' => '01H...',
'wa_id' => '966500000000',
'template_name' => 'order_ready',
'language' => 'ar',
'variables' => ['12345', '120 SAR'],
]);
// WhatsApp groups (Baileys-only)
$group = $client->groups()->create('Sales pod', ['966500000000', '966500000001']);
$client->groups()->addParticipants($group->id, ['966500000002']);
// Send an email
$email = $client->emails()->send([
'from' => 'Acme <[email protected] >', // bare address also accepted
'to' => ['[email protected] '],
'subject' => 'Your receipt',
'html' => '<h1>Thanks!</h1>',
'text' => 'Thanks!', // at least one of html/text/template
], idempotencyKey: 'order-1042-receipt');
echo $email->status; // queued | sent | delivered | bounced | complained | failed
// …or render a stored template with variables
$client->emails()->sendTemplate(
from: 'Acme <[email protected] >',
to: ['[email protected] '],
template: 'order-receipt', // slug or ULID
variables: ['order_id' => '1042'],
);
// Send log + a single message
$sent = $client->emails()->list(['status' => 'delivered', 'per_page' => 50]);
$one = $client->emails()->get('01H...');
// Delivery analytics (defaults to the last 30 days)
$stats = $client->emails()->analytics(from: '2026-06-01', to: '2026-06-30');
echo $stats->summary['delivery_rate'];
// Reusable templates
$tpl = $client->emails()->templates()->create([
'name' => 'Order receipt',
'subject' => 'Your order {{ order_id }} is confirmed',
'html' => '<p>Hi {{ name }}, order {{ order_id }} is on the way.</p>',
]);
$client->emails()->templates()->update($tpl->id, ['subject' => 'Order {{ order_id }} shipped']);
// Bulk broadcasts to a CRM-tag audience
$bc = $client->emails()->broadcasts()->create([
'name' => 'July newsletter',
'from' => 'Acme <[email protected] >',
'subject' => "What's new in July",
'html' => '<h1>Hello!</h1>',
'audience' => ['tag_slugs' => ['newsletter']], // omit ⇒ everyone with an email
]);
$client->emails()->broadcasts()->queue($bc->id); // fan out one send per recipient
// Suppression list (bounces/complaints are added automatically; you can add manually)
$client->emails()->suppressions()->add('[email protected] ');
$client->emails()->suppressions()->remove('[email protected] ');
$post = $client->socialPosts()->schedule(
text: 'New drop is live! 🎉',
channelIds: ['01H...x', '01H...telegram'],
scheduledAt: '2026-07-20T09:00:00+00:00',
media: [['url' => 'https://cdn.example.com/promo.jpg', 'type' => 'image']],
);
$client->socialPosts()->draft('Behind the scenes…', ['01H...instagram']);
// Read each platform's outcome — including the upstream failure reason
foreach ($client->socialPosts()->get($post->id)->targets as $t) {
echo "{$t->status} → {$t->permalink}\n";
}
$campaign = $client->campaigns()->create([
'name' => 'Ramadan promo',
'channel_id' => '01H...channel',
'template_id' => '01H...template',
'audience_filter' => ['tag_slugs' => ['vip']],
]);
$client->campaigns()->queue($campaign->id);
use Okta\Connect\WhatsApp\Embed\EmbedUser;
use Okta\Connect\WhatsApp\Embed\UiHide;
$embed = $client->embed($sharedSecret); // base URL reused from the client
$operator = new EmbedUser(sub: 'partner-user-7', email: '[email protected] ', name: 'Op');
// Cookieless per-request flow (survives third-party-cookie blocking). The token
// rides every request inside the iframe — recommended for white-label embeds.
$src = $embed->inboxUrl($operator, uiHide: [UiHide::AI, UiHide::ASSIGN_AGENT]);
// <iframe src="<?= $src
$client->messages()->send($payload, idempotencyKey: 'order-1234-confirmation');