PHP code example of dypras666 / wabameta

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

    

dypras666 / wabameta example snippets


use Dypras666\WabaMeta\Config;
use Dypras666\WabaMeta\Waba;

$config = new Config(
    phoneNumberId: 'YOUR_PHONE_NUMBER_ID',
    wabaId: 'YOUR_WABA_ID',
    accessToken: 'YOUR_ACCESS_TOKEN',
    verifyToken: 'YOUR_VERIFY_TOKEN'
);

$waba = new Waba($config);

$waba->sendText('628123456789', 'Hello from WABA Meta!');

// Switch ke mode grup
$waba->setRecipientType('group');

// Kirim pesan teks ke grup
$waba->sendText('GROUP_ID_ANDA', 'Halo semua di grup!');

// Setelah selesai, kembalikan ke individual jika perlu
$waba->setRecipientType('individual');

$response = $waba->createGroup('Nama Group Baru');
$groupId = $response['id'];

use Dypras666\WabaMeta\ComponentBuilder;

$builder = new ComponentBuilder();
$components = $builder
    ->addDocumentHeader('https://example.com/invoice.pdf', 'Invoice.pdf')
    ->addBody(['Cabang Jakarta', 'INV-001']) // {{1}} dan {{2}}
    ->build();

$waba->sendTemplate(
    to: '628123456789',
    templateName: 'invoice_template',
    components: $components
);

use Dypras666\WabaMeta\ComponentBuilder;

$builder = new ComponentBuilder();
$components = $builder
    ->addTextHeader('Halo Pelanggan!')
    ->addBody(['Nama User', 'Order #123'])
    ->addFooter([['type' => 'text', 'text' => 'Terima kasih telah berbelanja!']])
    ->addUrlButton(0, 'tracking/123') // Menambahkan suffix ke URL button di index 0
    ->addQuickReplyButton(1, 'YES_CONFIRM') // Payload untuk button di index 1
    ->build();

$waba->sendTemplate(
    to: '628123456789',
    templateName: 'order_update',
    components: $components
);

$waba->sendCtaUrl(
    to: '6281373350813',
    body: 'Klik tombol di bawah untuk melihat detail pesanan Anda.',
    buttonText: 'Lihat Pesanan',
    url: 'https://example.com/order/123',
    headerText: 'Info Pesanan',
    footerText: 'Berlaku hingga 24 jam'
);

$waba->sendImageCtaUrl(
    to: '6281373350813',
    imageUrl: 'https://example.com/promo.jpg',
    body: 'Promo spesial hari ini! Cek sekarang sebelum kehabisan.',
    buttonText: 'Klaim Promo',
    url: 'https://example.com/promo',
    footerText: 'Syarat & Ketentuan berlaku'
);

$waba->sendDocumentCtaUrl(
    to: '6281373350813',
    documentUrl: 'https://example.com/invoice.pdf',
    filename: 'Invoice_User.pdf',
    body: 'Ini adalah invoice Anda. Klik tombol untuk melihat di dashboard.',
    buttonText: 'Dashboard',
    url: 'https://example.com/dashboard',
    footerText: 'Dokumen Resmi © 2026'
);

$waba->sendReplyButtons(
    to: '6281373350813',
    body: 'Apakah Anda ingin mengkonfirmasi pesanan?',
    buttons: [
        ['id' => 'conf_yes', 'title' => 'Ya, Benar'],
        ['id' => 'conf_no', 'title' => 'Tidak']
    ],
    headerText: 'Konfirmasi',
    footerText: 'Silakan pilih salah satu'
);

$sections = [
    [
        'title' => 'Pilihan Cabang',
        'rows' => [
            ['id' => 'br_1', 'title' => 'Cabang A', 'description' => 'Alamat cabang A'],
            ['id' => 'br_2', 'title' => 'Cabang B', 'description' => 'Alamat cabang B']
        ]
    ]
];

$waba->sendListMessage(
    to: '6281373350813',
    headerText: 'Lokasi Kami',
    body: 'Pilih cabang terdekat Anda:',
    buttonText: 'Lihat Daftar',
    sections: $sections,
    footerText: 'Info lebih lanjut hubungi CS'
);

$waba->sendImage('628123456789', 'https://example.com/image.jpg', 'Ini caption gambar');

$waba->sendDocument('628123456789', 'https://example.com/file.pdf', 'invoice.pdf', 'Ini invoice Anda');

$challenge = $waba->verifyWebhook(
    $_GET['hub_mode'] ?? '',
    $_GET['hub_verify_token'] ?? '',
    $_GET['hub_challenge'] ?? ''
);

if ($challenge) {
    echo $challenge;
    exit;
}

http_response_code(403);

$payload = json_decode(file_get_contents('php://input'), true);
$data = $waba->handleWebhook($payload);

if (isset($data['messages'])) {
    foreach ($data['messages'] as $message) {
        // Process new message
    }
}