Skip to content

Commit

Permalink
Update PlivoChannel.php
Browse files Browse the repository at this point in the history
  • Loading branch information
bobking256 authored Jul 28, 2021
1 parent 9f47e0b commit 57c8c8f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/PlivoChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Notifications\Notification;
use NotificationChannels\Plivo\Exceptions\CouldNotSendNotification;
use Plivo\Resources\Message\MessageCreateResponse;

class PlivoChannel
{
Expand Down Expand Up @@ -38,8 +39,8 @@ public function __construct(Plivo $plivo)
*/
public function send($notifiable, Notification $notification)
{
if (! $to = $notifiable->routeNotificationFor('plivo')) {
return;
if (!$to = $notifiable->routeNotificationFor('plivo')) {
return null;
}

$message = $notification->toPlivo($notifiable);
Expand All @@ -48,13 +49,14 @@ public function send($notifiable, Notification $notification)
$message = new PlivoMessage($message);
}

$response = $this->plivo->send_message([
'src' => $message->from ?: $this->from,
'dst' => $to,
'text' => trim($message->content),
]);
/** @var MessageCreateResponse $response */
$response = $this->plivo->messages->create(
$message->from ?: $this->from,
$to,
trim($message->content)
);

if ($response['status'] !== 202) {
if ($response->getStatusCode() > 400) {
throw CouldNotSendNotification::serviceRespondedWithAnError($response);
}

Expand Down

0 comments on commit 57c8c8f

Please sign in to comment.