Skip to content

sikuning/WaWaBot-CI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

WaWaBot — Library WhatsApp untuk CodeIgniter 3

Library sederhana untuk mengirim pesan WhatsApp lewat API wa-api.wawabot.id.

Instalasi

  1. Copy folder application/libraries/WaWaBot.php ke application/libraries/ project CI3 Anda.
  2. Copy application/config/wawabot.php ke application/config/.
  3. Isi api_key dan account_id dari penyedia layanan.

Pastikan ekstensi php-curl aktif.

Konfigurasi

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

Alur koneksi WhatsApp

  1. Start sesistart()
  2. Ambil QRgetQr() → scan di HP: WhatsApp → Pengaturan → Perangkat tertaut → Tautkan perangkat
  3. Cek logininfoMe() atau session()
  4. Kirim pesansendText() / sendMedia()

Contoh penggunaan

Load library

$this->load->library('WaWaBot');
// atau dengan override config:
$this->load->library('WaWaBot', array('api_key' => 'xxx', 'account_id' => 'user-1'));

Mulai sesi & QR

$result = $this->wawabot->start();
if ($result['success']) {
    $qr = $this->wawabot->getQr(false);
    // $qr['data'] berisi response API (JSON/base64 sesuai API)
}

Cek status

$me = $this->wawabot->infoMe();
$session = $this->wawabot->session();

Kirim teks

$result = $this->wawabot->sendText('6281234567890', 'Halo dari WaWaBot!');

if ($result['success']) {
    echo 'Terkirim';
} else {
    log_message('error', 'WaWaBot: ' . $result['raw']);
}

Kirim gambar / media

$result = $this->wawabot->sendMedia(
    '6281234567890',
    FCPATH . 'uploads/foto.jpg',
    'Ini caption opsional'
);

Lookup nomor

$result = $this->wawabot->lookup('6285612312311');

Logout

$this->wawabot->logout();

Format response

Semua method mengembalikan array:

array(
    'success'   => true|false,   // HTTP 2xx
    'http_code' => 200,
    'data'      => mixed,        // JSON ter-decode atau string
    'raw'       => '...',        // body mentah
)

Method API

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

Contoh di Controller

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

Lisensi

Gunakan sesuai kebutuhan project Anda.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages