1. Go to this page and download the library: Download texhub/whatsapp-cloud-api 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/ */
texhub / whatsapp-cloud-api example snippets
use TexHub\WhatsApp\WhatsApp;
$wa = WhatsApp::make(
accessToken: 'YOUR_PERMANENT_TOKEN',
phoneNumberId: 'YOUR_PHONE_NUMBER_ID',
businessAccountId: 'YOUR_WABA_ID', // optional, needed for templates/phone list
);
$wa->sendText('992900123456', 'Привет из TexHub! 👋');
use TexHub\WhatsApp\Builders\Button;
// Media (by public URL):
$wa->messages()->image('992900123456', 'https://cdn/photo.jpg', caption: 'Фото');
$wa->messages()->document('992900123456', 'https://cdn/file.pdf', filename: 'invoice.pdf');
// Interactive reply buttons (max 3):
$wa->messages()->buttons('992900123456', 'Подтвердите заказ:', [
Button::reply('confirm', 'Подтвердить'),
Button::reply('cancel', 'Отменить'),
]);
// Interactive list:
$wa->messages()->list('992900123456', 'Выберите услугу', 'Открыть меню', [
Button::section('Услуги', [
Button::row('svc_1', 'Доставка', 'Курьером по городу'),
Button::row('svc_2', 'Самовывоз'),
]),
]);
// Template (the only way to message outside the 24h window):
$wa->messages()->template('992900123456', 'hello_world', 'en_US');
// Location, reaction, mark as read:
$wa->messages()->location('992900123456', 38.5598, 68.7870, 'Душанбе');
$wa->messages()->reaction('992900123456', 'wamid.XXX', '👍');
$wa->messages()->markRead('wamid.INCOMING');
$id = $wa->media()->upload('/path/image.jpg')->id(); // upload, get a media id
$wa->messages()->mediaById('992900123456', 'image', $id);
$url = $wa->media()->url($mediaId); // temporary download URL
$bytes = $wa->media()->download($mediaId); // raw binary
$wa->media()->delete($mediaId);
use TexHub\WhatsApp\Laravel\WhatsApp;
WhatsApp::sendText('992900123456', 'Привет из Laravel!');
WhatsApp::messages()->buttons('992900123456', 'Выбор:', [/* ... */]);
// 1) Customer onboarding via Embedded Signup (front-end returns a `code`):
$wa = WhatsApp::fromArray(['access_token' => '...', 'phone_number_id' => '...', 'app_id' => '...', 'app_secret' => '...']);
$token = $wa->onboarding()->exchangeCode($code)->get('access_token'); // customer business token
$wa->onboarding()->subscribeApp($wabaId, $token); // route their webhooks to you
$wa->onboarding()->registerPhone($phoneNumberId, '123456', $token); // 6-digit PIN
// → store {token, waba_id, phone_number_id} for this tenant
// 2) Send as any tenant — build a client with their stored creds:
WhatsApp::fromArray($tenant->whatsappConfig())->sendText($to, $text);
// 3) One webhook for everyone — route by phone number / WABA id:
foreach ($wa->webhooks()->parse($raw) as $event) {
$tenant = Tenant::where('wa_phone_number_id', $event->phoneNumberId())->first();
// or ->where('wa_business_account_id', $event->wabaId())
}
use TexHub\WhatsApp\WhatsApp;
use TexHub\WhatsApp\Config;
use TexHub\WhatsApp\Tests\Support\FakeTransport;
$t = (new FakeTransport())->push(['messages' => [['id' => 'wamid.1']]]);
$wa = new WhatsApp(new Config('TOKEN', '123456'), $t);
$wa->sendText('992900123456', 'hi'); // assert on $t->last()