dypras666/wabameta

WhatsApp Business API (WABA) Meta Integration Module

Maintainers

Package info

github.com/dypras666/waba

pkg:composer/dypras666/wabameta

Statistics

Installs: 73

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.0.1 2026-02-24 16:10 UTC

This package is auto-updated.

Last update: 2026-04-24 16:59:20 UTC


README

A simple PHP package to integrate with Meta's WhatsApp Business API (WABA).

Installation

composer require dypras666/waba

Usage

Configuration

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);

Sending Messages

Send Text Message

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

Group Messaging (Kirim ke Grup)

Anda dapat mengirim pesan ke WhatsApp Group menggunakan group_id.

// 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');

Create Group (Experimental)

Membuat grup baru melalui API. Membutuhkan wabaId di Config.

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

Sending Templates with Media Headers & Variables

Gunakan ComponentBuilder untuk menyisipkan PDF/Gambar sebagai header dan identitas cabang di body.

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
);

Sending Templates with Components (Buttons, Footer, etc.)

For complex templates, you can use the ComponentBuilder utility.

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
);

Interactive Messages (Tanpa Template)

Anda dapat mengirim pesan dengan tombol tanpa perlu mendaftarkan template di Meta.

Send CTA URL (Button Link)

$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'
);

Send Image + Footer + Link (Tanpa Template)

$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'
);

Send PDF + Footer + Link (Tanpa Template)

$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'
);

Send Reply Buttons (Max 3 buttons)

$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'
);

Send List Message (Selection)

$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'
);

Sending Media

Send Image

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

Send Document

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

Verification (Route /webhook GET)

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

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

http_response_code(403);

Handling Payloads (Route /webhook POST)

$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
    }
}

Authors