I was trying to send sms with infobip with following way:
https://www.infobip.com/docs/api/channels/sms/sms-messaging/outbound-sms/send-sms-message
and i was also trying to get the delivery report with webhook so that i can store the log on my database
https://www.infobip.com/docs/api/channels/sms/sms-messaging/logs-and-status-reports/receive-outbound-sms-message-report
I have send the request in following way:
public function singleSMS($contacts,$sender,$communication)
{
$destinationsMapped = [];
foreach ($contacts as $contact) {
$destinationsMapped[] = ['to' => (string) $contact->contact_number];
}
$data = [
'bulkId' => $communication->id,
'messages' => [
[
'destinations' => $destinationsMapped,
'from' => $sender->sender_number,
'text' => $communication->communication_text
]
],
'notifyUrl' => 'https://test_url.com/infobip/sms/response',
'tracking' => [
'track' => 'SMS',
'type' => 'MY_CAMPAIGN'
]
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.infobip.com/sms/2/text/advanced',
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 => json_encode($data),
CURLOPT_HTTPHEADER => array(
'Authorization: App 7447',
'Content-Type: application/json',
'Accept: application/json'
),
));
$response = curl_exec($curl);
Log::info(json_encode($data));
curl_close($curl);
return $response;
}
I have stored the response from infobip in following way:
public function infobipResponse(Request $request)
{
$json = file_get_contents('php://input');
$data = json_decode($json, true);
Log::info(json_encode($responseArray));
if ($data === null)
{
return response()->json(['error' => 'Invalid JSON data'], 400);
}
if (!isset($data['results']) || !is_array($data['results']))
{
return response()->json(['error' => 'Missing or invalid results data'], 400);
}
foreach ($data['results'] as $result)
{
DB::table('communication_logs')->insert([
'msgCount' => $result['smsCount'],
'smscCost' => $result['price']['pricePerMessage'],
'no_of_contacts' => $result['status']['id'],
'communication_id' => $result['bulkId'],
'created_at' => $result['doneAt']
]);
}
return response()->json(['status' => 'success']);
}
Route:
Route::controller(InfobipController::class)->group(function() {
Route::post('infobip/sms/response','infobipResponse');
});
Sms send is OK, sms is sent to mobile successfullly. But the problem is I can’t get the delivery report response to notifyUrl.
Why’s that? What’s wrong with my above functionality?