Skip to content

Commit 8139b1d

Browse files
committed
feat: allow on-demand notifications to ignore the channel
1 parent ce3eebe commit 8139b1d

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/Channels/TwilioChannel.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,27 @@ public function send($notifiable, TwilioNotification $notification)
6666
// notifications, as well as normal notifiable notifications.
6767
$phoneNumber = $this->getRecipientPhoneNumber($notifiable);
6868

69+
if (empty($phoneNumber)) {
70+
return;
71+
}
72+
6973
// Send the SMS message
7074
$this->client->messages->create($phoneNumber, [
7175
'from' => $this->from_phone_number,
7276
'body' => $twilioMessage->fullMessage(),
7377
]);
7478
}
7579

76-
private function getRecipientPhoneNumber(mixed $notifiable): string
80+
private function getRecipientPhoneNumber(mixed $notifiable): ?string
7781
{
78-
if ($notifiable instanceof AnonymousNotifiable && array_key_exists('twilio', $notifiable->routes)) {
79-
return strval($notifiable->routes['twilio']);
82+
if ($notifiable instanceof AnonymousNotifiable) {
83+
if (array_key_exists('twilio', $notifiable->routes)) {
84+
return strval($notifiable->routes['twilio']);
85+
}
86+
87+
// If a notification supports twilio, but the on-demand nature of
88+
// the notification doesn't send choose to send via the channel.
89+
return null;
8090
}
8191

8292
if ($notifiable->twilioPhoneNumberField !== null) {

0 commit comments

Comments
 (0)