Library sederhana untuk mengirim pesan WhatsApp lewat API wa-api.wawabot.id.
- Copy folder
application/libraries/WaWaBot.phpkeapplication/libraries/project CI3 Anda. - Copy
application/config/wawabot.phpkeapplication/config/. - Isi
api_keydanaccount_iddari penyedia layanan.
Pastikan ekstensi php-curl aktif.
Edit application/config/wawabot.php:
$config['api_key'] = 'api-key-anda';
$config['account_id'] = 'user-1';Atau set saat load:
$this->load->library('WaWaBot', array(
'api_key' => 'api-key-anda',
'account_id' => 'user-1',
));- Start sesi —
start() - Ambil QR —
getQr()→ scan di HP: WhatsApp → Pengaturan → Perangkat tertaut → Tautkan perangkat - Cek login —
infoMe()atausession() - Kirim pesan —
sendText()/sendMedia()
$this->load->library('WaWaBot');
// atau dengan override config:
$this->load->library('WaWaBot', array('api_key' => 'xxx', 'account_id' => 'user-1'));$result = $this->wawabot->start();
if ($result['success']) {
$qr = $this->wawabot->getQr(false);
// $qr['data'] berisi response API (JSON/base64 sesuai API)
}$me = $this->wawabot->infoMe();
$session = $this->wawabot->session();$result = $this->wawabot->sendText('6281234567890', 'Halo dari WaWaBot!');
if ($result['success']) {
echo 'Terkirim';
} else {
log_message('error', 'WaWaBot: ' . $result['raw']);
}$result = $this->wawabot->sendMedia(
'6281234567890',
FCPATH . 'uploads/foto.jpg',
'Ini caption opsional'
);$result = $this->wawabot->lookup('6285612312311');$this->wawabot->logout();Semua method mengembalikan array:
array(
'success' => true|false, // HTTP 2xx
'http_code' => 200,
'data' => mixed, // JSON ter-decode atau string
'raw' => '...', // body mentah
)| Method | Endpoint | Keterangan |
|---|---|---|
start() |
POST /accounts/{id}/start |
Mulai sesi |
session() |
GET /accounts/{id}/session |
Status sesi |
getQr($isHtml) |
GET /accounts/{id}/qr |
QR code |
infoMe() |
GET /info-me |
Info akun / login |
sendText($to, $text) |
POST /accounts/{id}/send |
Pesan teks |
sendMedia($to, $path, $caption) |
POST /accounts/{id}/send-media |
File/gambar |
lookup($to) |
GET /accounts/{id}/lookup |
Cek nomor WA |
logout() |
POST /accounts/{id}/logout |
Putus sesi |
Base URL default: https://wa-api.wawabot.id/ (bukan IP langsung).
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Whatsapp extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('WaWaBot');
}
public function kirim()
{
$result = $this->wawabot->sendText(
$this->input->post('nomor'),
$this->input->post('pesan')
);
$this->output
->set_content_type('application/json')
->set_output(json_encode($result));
}
}Gunakan sesuai kebutuhan project Anda.