Webhook update message status will be replacement of API message status to make the updating status real time and do not need an API hit to update it.
The message status would have id and stateid to update the message status and message state.
The example below show how to save message status to mysql, you can modify as you need.
You need to send from API to be able to save it. this is the example of API send with saving the report to mysql.
You can download example database table here.
API send and save report :
<?php
$conn = mysqli_connect("localhost","root","","db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$message = "test ya";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.fonnte.com/send',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('target' => '083120942579','message' => $message),
CURLOPT_HTTPHEADER => array(
'Authorization: TOKEN'
),
));
$response = curl_exec($curl);
curl_close($curl);
$res = json_decode($response,true);
var_dump($res);
foreach($res["id"] as $k=>$v){
$target = $res["target"][$k];
$status = $res["process"];
mysqli_query($conn,"INSERT INTO report (id,target,message,status) VALUES ('$v','$target','$message','$status')");
}
Then use the example code below to update the message status and state to mysql.
Webhook script :
<?php
header('Content-Type: application/json; charset=utf-8');
$conn = mysqli_connect("localhost","root","","db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$json = file_get_contents('php://input');
$data = json_decode($json, true);
$device = $data['device'];
$id = $data['id'];
$stateid = $data['stateid'];
$status= $data['status'];
$state = $data['state'];
//update status and state
if(isset($id) && isset($stateid)){
mysqli_query($conn,"UPDATE report SET status = '$status',state = '$state',stateid = '$stateid' WHERE id = '$id'");
}else if(isset($id) && !isset($stateid)){
mysqli_query($conn,"UPDATE report SET status = '$status' WHERE id = '$id'");
}else{
mysqli_query($conn,"UPDATE report SET state = '$state' WHERE stateid = '$stateid'");
}
Available parameter
- Device - Your device number (not connected device)
- Id - The message id
- Stateid - The message stateid
- Status - The status of the message
- State - The state of the message