-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhooks.php
More file actions
34 lines (26 loc) · 988 Bytes
/
Copy pathwebhooks.php
File metadata and controls
34 lines (26 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
$waboxapp_api_key = 'YOUR APIKEY WABOXAPP';
// Baca data dari webhook
$json = file_get_contents('php://input');
$decodedData = urldecode($json);
parse_str($decodedData, $result);
// Ambil pesan dan nomor pengirim
$pesan = $result['message']['body']['text'];
$pengirim = $result['contact']['uid'];
$aksi_event = $result['event'];
// Simpan pesan ke database atau lakukan operasi lainnya
// Contoh: Simpan pesan ke database MySQL
$koneksi = new mysqli('HOST', 'USERNAME', 'PASSWORD', 'DATABASE');
if ($koneksi->connect_error) {
die("Koneksi ke database gagal: " . $koneksi->connect_error);
}
$query = "INSERT INTO messages (pengirim, pesan, aksi_event) VALUES ('$pengirim', '$pesan','$aksi_event')";
if ($koneksi->query($query) === TRUE) {
echo "Pesan berhasil disimpan ke database.";
} else {
echo "Error: " . $query . "<br>" . $koneksi->error;
}
$koneksi->close();
// Beri respons 200 OK ke Waboxapp
http_response_code(200);
?>