@charrua How did you end up solving this issue?
Get nexmo SMS notification API response when sending SMS
Hello, I'm using nexmo SMS notifications and wanted to get the nexmo API response when I send an SMS to get the ID (of the message sent) and then store it.
The main purpose is then to get the nexmo delivery status of that particular message and assign it to some model also...
The nexmo library I'm using is nexmo/client as told in Laravel docs.
In my notification class I use:
public function via($notifiable)
{
return ['mail', 'nexmo'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return Mailable
*/
public function toMail($notifiable)
{
return (new Mailable($this->appointment))->to($this->appointment->email);
}
/**
* Get the Nexmo / SMS representation of the notification.
*
* @param mixed $notifiable
* @return NexmoMessage
*/
public function toNexmo($notifiable)
{
return (new NexmoMessage)
->content('Test SMS');
}
The nexmo response to this API request should be (https://developer.nexmo.com/api/sms#send-an-sms):
{
"to": "447700900000",
"message-id": "0A0000000123ABCD1",
"status": "0",
"remaining-balance": "3.14159265",
"message-price": "0.03330000",
"network": "12345"
}
But I don't know how to obtain this response using public function toNexmo($notifiable)in my notification class.
Any ideas?
I know if I send the message using the API directly:
$message = $client->message()->send([
'to' => NEXMO_TO,
'from' => NEXMO_FROM,
'text' => 'Test message from the Nexmo PHP Client'
]);
I can then access to $message['message-id']and get what I want. But I'm not using the API directly, instead I'm using it with public function toNexmo($notifiable) in the notification.
Then investigating further, I have found that there is a class under namespace Illuminate\Notifications\Channels called NexmoSmsChannel that has a send method.
public function send($notifiable, Notification $notification)
{
if (! $to = $notifiable->routeNotificationFor('nexmo')) {
return;
}
$message = $notification->toNexmo($notifiable);
if (is_string($message)) {
$message = new NexmoMessage($message);
}
return $this->nexmo->message()->send([
'type' => $message->type,
'from' => $message->from ?: $this->from,
'to' => $to,
'text' => trim($message->content),
]);
}
This method implements the same API call but as before, I don't know how to get the response from nexmo.
Please or to participate in this conversation.