File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ Add your Utalk token on `app/services.php` file. You can get your API Token [her
3434],
3535```
3636
37+ ** You need to create a ` UTALK_TOKEN ` on your ` .env ` file.**
38+
3739## Usage
3840
3941Now you can use the channel in your ` via() ` method inside the notification:
@@ -45,11 +47,24 @@ use Illuminate\Notifications\Notification;
4547
4648class TeamCreated extends Notification
4749{
50+
51+ /**
52+ * Get the notification's delivery channels.
53+ *
54+ * @param mixed $notifiable
55+ * @return array
56+ */
4857 public function via($notifiable)
4958 {
5059 return [UtalkChannel::class];
5160 }
5261
62+ /**
63+ * Get the UTalk representation of the notification.
64+ *
65+ * @param mixed $notifiable
66+ * @return \Powertic\Utalk\UtalkMessage
67+ */
5368 public function toUtalk($notifiable)
5469 {
5570 return UtalkMessage::create()
@@ -60,9 +75,14 @@ class TeamCreated extends Notification
6075
6176In order to let your Notification know which number should receive the message, add the ` routeNotificationForUtalk ` method to your Notifiable model.
6277
63- This method needs to return the mobile number where the notification will be sent.
78+ ** This method expects a [ valid E.164 mobile number] ( https://en.wikipedia.org/wiki/E.164 ) where the notification will be sent.**
6479
6580``` php
81+ /**
82+ * Route notifications for the Utalk channel.
83+ *
84+ * @return string
85+ */
6686public function routeNotificationForUtalk()
6787{
6888 return $this->mobile;
Original file line number Diff line number Diff line change 1919 "php" : " ^7.2.5 || ^8.0" ,
2020 "guzzlehttp/guzzle" : " ^6.2 || ^7.0" ,
2121 "illuminate/notifications" : " ^6.0 || ^7.0 || ^8.0" ,
22- "illuminate/support" : " ^6.0 || ^7.0 || ^8.0"
22+ "illuminate/support" : " ^6.0 || ^7.0 || ^8.0" ,
23+ "propaganistas/laravel-phone" : " ^4.2"
2324 },
2425 "require-dev" : {
2526 "mockery/mockery" : " ^1.3" ,
Original file line number Diff line number Diff line change 77use Illuminate \Notifications \Notification ;
88use Powertic \Utalk \Exceptions \CouldNotSendNotification ;
99use Powertic \Utalk \Exceptions \InvalidConfiguration ;
10+ use Propaganistas \LaravelPhone \PhoneNumber ;
1011
1112class UtalkChannel
1213{
@@ -21,6 +22,19 @@ public function __construct(Utalk $utalk)
2122 $ this ->utalk = $ utalk ;
2223 }
2324
25+ /**
26+ * Transform Mobile Number to Utalk Format
27+ *
28+ * @param [string] $mobile
29+ * @return string
30+ */
31+ private function transformMobileNumber ($ mobile )
32+ {
33+ $ transformed = PhoneNumber::make ($ mobile )->formatE164 ();
34+ $ transformed = str_replace ('+ ' , '' , $ transformed );
35+ return "{$ transformed }@c.us " ;
36+ }
37+
2438 /**
2539 * Send the given notification.
2640 *
@@ -35,10 +49,12 @@ public function __construct(Utalk $utalk)
3549 public function send ($ notifiable , Notification $ notification )
3650 {
3751 // Exit if $notifiable doesn't have a route
38- if (!$ to = $ notifiable ->routeNotificationFor ('utalk ' )) {
52+ if (!$ mobile = $ notifiable ->routeNotificationFor ('utalk ' )) {
3953 return ;
4054 }
4155
56+ $ to = $ this ->transformMobileNumber ($ mobile );
57+
4258 // Exit if token not found
4359 if (!$ token = $ this ->utalk ->getToken ()) {
4460 throw new InvalidConfiguration ();
You can’t perform that action at this time.
0 commit comments