1. Home
  2. Docs
  3. Dokumentasi API
  4. Webhook Receive Message

Webhook Receive Message

Retrieve new incoming messages from WhatsApp, so every time a new message is sent, we will forward it to this URL. The webhooks URL can be set on menu: Device – setting – webhook receive.

Make sure you have a domain that can be accessed publicly as namadomain.com, then place the webhook file in the folder, so that later your webhook URL isĀ https://yourdomain.com/webhook.php
The following is the data that will be sent to your webhook URL:

POSThttps://your-domain.com/webhook.php

<?php
/**
 * all data POST sent from http://app.absen.co.id
 * you must create URL what can receive POST data
 * we will sent data like this: 
 * id = message ID - string
 * phone = sender phone - string
 * message = content of message - text
 * pushName = Sender Name like contact name - string
 * groupId = Group ID if message from group - string
 * groupSubject = Group Name - string
 * timestamp = time send message - integer
 * image = name of the image file when receiving image message
 * file = name of the file file when receiving document/video message
 * url = URL of image/document/video
 */
extract($_POST);

/**
 * Save to database table inbox
 */
$conn = new mysqli("localhost", "user123", "password123", "bot_db");
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO inbox (message_id, phone, message)
VALUES ($id, $phone, $message)";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "" . $conn->error;
}
if($conn->close()) {
    echo null;
}

?>
<?php

extract($_POST);
/**
 * for auto reply or bot 
 */
 
echo "your phone: $phone \n";

if($message == 'hello') {
    echo "your message: $message";
} else {
    echo "I am still learning";
}

?>

the printed text on the echo will then be sent back to the user as a reply, if you request an automatic reply. if you do not want to reply in print enough “null” ( echo null ).

Body Response:
idstringMessage ID like random string
phonestringsender number, example: 62821144818
pushNamestringsender name example: Peter
messagestringcontent of message
groupIdstringGroup ID if message coming from group whatsapp, example: 6282111444818-84267713. So your Group ID is 84267713
groupSubjectstringGroup Name
imagestringname of image
filestringname of file like document or video
urlurl stringURL from image / document / video