$token = '1xmrd7YHjff5';
$array = [
[
'chatId' => '79999999999@c.us', // Recipient's phone number
'message' => 'Привет! Как дела?', // Message
],
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.api-messenger.com/sendmessage?token=' . $token);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($array));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json; charset=utf-8'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$result = curl_exec($ch); // We will send a request
curl_close($ch);
$data = json_decode($result, true); // Parse the received JSON into an array
echo $data['status'] . ': ' . $data['message'];
$token = '1xmrd7YHjff5';
$url = 'https://app.api-messenger.com/messages?new=1&token=' . $token;
$result = file_get_contents($url); // We will send a request
$data = json_decode($result, true); // Parse the received JSON into an array
foreach ($data['messages'] as $message) { // Print each message
echo 'Sender: ' . preg_replace('~\D+~', '', $message['sender']);
echo 'Message: ' . $message['body'];
}
// First, install the webhook according to the documentation.
// for example at http://you.site/incoming_message.php
// Decode the JSON that came over the webhook.
$data = json_decode(file_get_contents('php://input'), true);
foreach($data['messages'] as $message) {
// Process each message here already:
// Add to the database or answer right away
}