Skip to content

Commit f50ca46

Browse files
committed
Added alphanumeric sending, and messaging service capabilities
1 parent e906a04 commit f50ca46

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/TwilioChannel.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public function send($notifiable, Notification $notification)
5151

5252
try {
5353
$message = $notification->toTwilio($notifiable);
54+
$params = [];
55+
$from = null;
5456

5557
if (is_string($message)) {
5658
$message = new TwilioSmsMessage($message);
@@ -60,11 +62,23 @@ public function send($notifiable, Notification $notification)
6062
throw CouldNotSendNotification::invalidMessageObject($message);
6163
}
6264

63-
if (! $from = $message->from ?: config('services.twilio.from')) {
65+
if (method_exists($notifiable, 'canReceiveAlphanumericSender') &&
66+
$notifiable->canReceiveAlphanumericSender() &&
67+
$sender = config('services.twilio.alphanumeric_sender')) {
68+
$from = $sender;
69+
} else {
70+
$from = $message->from ?: config('services.twilio.from');
71+
}
72+
73+
if (! $from) {
6474
throw CouldNotSendNotification::missingFrom();
6575
}
6676

67-
return $this->sendMessage($message, $from, $to);
77+
if ($serviceSid = config('services.twilio.sms_service_sid')) {
78+
$params['MessagingServiceSid'] = $serviceSid;
79+
}
80+
81+
return $this->sendMessage($message, $from, $to, $params);
6882
} catch (Exception $exception) {
6983
$this->events->fire(
7084
new NotificationFailed($notifiable, $notification, 'twilio', ['message' => $exception->getMessage()])
@@ -80,13 +94,15 @@ public function send($notifiable, Notification $notification)
8094
*
8195
* @throws \NotificationChannels\Twilio\Exceptions\CouldNotSendNotification
8296
*/
83-
protected function sendMessage($message, $from, $to)
97+
protected function sendMessage($message, $from, $to, $params = [])
8498
{
8599
if ($message instanceof TwilioSmsMessage) {
86100
return $this->twilio->account->messages->sendMessage(
87101
$from,
88102
$to,
89-
trim($message->content)
103+
trim($message->content),
104+
null,
105+
$params
90106
);
91107
}
92108

0 commit comments

Comments
 (0)