-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
350 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# Changelog | ||
|
||
## 1.0.1 (20??-??-??) | ||
## 1.1.0 (20??-??-??) | ||
|
||
- Add a notification channel to send SMS messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace BabDev\Twilio\Notifications\Channels; | ||
|
||
use BabDev\Twilio\Contracts\TwilioClient; | ||
use Illuminate\Notifications\Notification; | ||
use Twilio\Exceptions\TwilioException; | ||
use Twilio\Rest\Api\V2010\Account\MessageInstance; | ||
|
||
final class TwilioChannel | ||
{ | ||
/** | ||
* @var TwilioClient | ||
*/ | ||
private $twilio; | ||
|
||
/** | ||
* Creates a new Twilio notification channel. | ||
* | ||
* @param TwilioClient $twilio The Twilio client. | ||
*/ | ||
public function __construct(TwilioClient $twilio) | ||
{ | ||
$this->twilio = $twilio; | ||
} | ||
|
||
/** | ||
* Send the given notification. | ||
* | ||
* @param mixed $notifiable | ||
* @param Notification $notification | ||
* | ||
* @return MessageInstance|null | ||
* | ||
* @throws TwilioException on Twilio API failure | ||
*/ | ||
public function send($notifiable, Notification $notification): ?MessageInstance | ||
{ | ||
$to = $notifiable->routeNotificationFor('twilio', $notification); | ||
|
||
if (!$to) { | ||
return null; | ||
} | ||
|
||
$message = $notification->toTwilio($notifiable); | ||
|
||
if (!$message) { | ||
return null; | ||
} | ||
|
||
return $this->twilio->message($to, $message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.