Uji Coba Bot Ujian
Simulasi interaksi siswa menggunakan tombol balasan cepat WhatsApp.
CBT MTsN 16 Jakarta
Akun Bisnis ⢠Online
Total Bank Soal
0
Peserta Selesai
0
Rata-Rata Nilai
0
Tambah Soal Baru
Soal akan otomatis diformat menjadi pesan WhatsApp dengan tombol pilihan A, B, C, D.
Daftar Soal Aktif
Rekap Hasil Ujian Siswa
| Nama Siswa | No. WhatsApp | Benar | Skor | Waktu |
|---|
Menyimpan & Menghubungkan ke Hosting
Agar aplikasi CBT ini dapat merespons pesan WhatsApp secara nyata 24 jam penuh, unggah file aplikasi ini beserta skrip Webhook Server ke layanan hosting Anda (cPanel, VPS, Vercel, atau Railway).
Siapkan Penyedia WA API
Gunakan WhatsApp Cloud API (Meta) resmi untuk fitur Interactive Reply Buttons gratis, atau gateway lokal seperti Fonnte / Wablas.
Upload ke Hosting Anda
Simpan halaman ini sebagai index.html untuk dashboard admin, dan unggah file webhook.php atau server.js di bawah ke folder hosting Anda.
Pasang URL Webhook
Masukkan URL hosting Anda (contoh: https://cbt.sekolah.sch.id/webhook.php) ke pengaturan Webhook di dashboard WhatsApp API.
<?php
// webhook.php - Simpan di Shared Hosting / cPanel Anda
// Mendukung WhatsApp Cloud API (Meta) dengan Interactive Quick Reply Buttons
$verify_token = "TOKEN_RAHASIA_CBT_2026";
$wa_token = "MASUKKAN_ACCESS_TOKEN_WHATSAPP_CLOUD_API_ANDA";
$phone_id = "MASUKKAN_PHONE_NUMBER_ID_ANDA";
// 1. Verifikasi Webhook Meta
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['hub_verify_token'])) {
if ($_GET['hub_verify_token'] === $verify_token) {
echo $_GET['hub_challenge'];
exit;
}
http_response_code(403);
exit;
}
// 2. Tangkap Pesan Masuk & Klik Tombol Quick Reply
$input = json_decode(file_get_contents('php://input'), true);
if (isset($input['entry'][0]['changes'][0]['value']['messages'][0])) {
$msg = $input['entry'][0]['changes'][0]['value']['messages'][0];
$from = $msg['from']; // Nomor WA Siswa
// Cek apakah siswa mengetik teks atau menekan tombol balasan cepat
$reply = "";
if ($msg['type'] === 'text') {
$reply = strtoupper(trim($msg['text']['body']));
} elseif ($msg['type'] === 'interactive') {
$reply = strtoupper(trim($msg['interactive']['button_reply']['id']));
}
// Contoh logika pengiriman soal dengan tombol cepat (Quick Reply)
if ($reply === "MULAI" || $reply === "UJIAN2026") {
kirimSoalQuickReply($from, "Soal 1: Apa ibu kota negara Indonesia saat ini?", [
["id" => "JAWAB_A", "title" => "A. Jakarta"],
["id" => "JAWAB_B", "title" => "B. Bandung"],
["id" => "JAWAB_C", "title" => "C. Nusantara"]
], $phone_id, $wa_token);
}
}
function kirimSoalQuickReply($to, $teksSoal, $buttons, $phone_id, $token) {
$btnPayload = [];
foreach ($buttons as $b) {
$btnPayload[] = [
"type" => "reply",
"reply" => ["id" => $b["id"], "title" => $b["title"]]
];
}
$data = [
"messaging_product" => "whatsapp",
"to" => $to,
"type" => "interactive",
"interactive" => [
"type" => "button",
"body" => ["text" => $teksSoal],
"action" => ["buttons" => $btnPayload]
]
];
$ch = curl_init("https://graph.facebook.com/v18.0/$phone_id/messages");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $token",
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
?>
// server.js - Jalankan di VPS, Railway, Render, atau Vercel
// Install dependencies: npm install express axios body-parser
const express = require('express');
const axios = require('axios');
const app = express();
app.use(express.json());
const VERIFY_TOKEN = 'TOKEN_RAHASIA_CBT_2026';
const WA_TOKEN = 'MASUKKAN_ACCESS_TOKEN_WHATSAPP_CLOUD_API_ANDA';
const PHONE_NUMBER_ID = 'MASUKKAN_PHONE_NUMBER_ID_ANDA';
// Database sesi sementara di memori server
const userSessions = {};
// Verifikasi Webhook
app.get('/webhook', (req, res) => {
if (req.query['hub.verify_token'] === VERIFY_TOKEN) {
return res.status(200).send(req.query['hub.challenge']);
}
res.sendStatus(403);
});
// Penerima Pesan WhatsApp
app.post('/webhook', async (req, res) => {
const entry = req.body.entry?.[0]?.changes?.[0]?.value?.messages?.[0];
if (!entry) return res.sendStatus(200);
const from = entry.from;
const text = entry.type === 'text'
? entry.text.body.trim().toUpperCase()
: entry.interactive?.button_reply?.id;
if (text === 'MULAI' || text === 'UJIAN2026') {
userSessions[from] = { index: 0, score: 0 };
await sendInteractiveQuestion(from, "Soal 1:\nPerangkat keras komputer yang berfungsi sebagai otak pemroses data adalah...", [
{ id: 'A', title: 'A. CPU' },
{ id: 'B', title: 'B. RAM' },
{ id: 'C', title: 'C. Harddisk' }
]);
}
res.sendStatus(200);
});
async function sendInteractiveQuestion(to, bodyText, buttons) {
await axios.post(`https://graph.facebook.com/v18.0/${PHONE_NUMBER_ID}/messages`, {
messaging_product: 'whatsapp',
to,
type: 'interactive',
interactive: {
type: 'button',
body: { text: bodyText },
action: {
buttons: buttons.map(b => ({
type: 'reply',
reply: { id: b.id, title: b.title }
}))
}
}
}, {
headers: { Authorization: `Bearer ${WA_TOKEN}` }
});
}
app.listen(3000, () => console.log('WA-CBT Webhook aktif di port 3000'));