1212
1313class SmsChannelAdapter implements ChannelAdapterInterface
1414{
15- /**
16- * @var Client
17- */
18- private Client $ client ;
19-
2015 /**
2116 * @var string
2217 */
@@ -83,24 +78,23 @@ private function sendWithTwilio(Model $context, Notifier $notifier): void
8378 {
8479 $ data = $ notifier ->toSms ($ context );
8580
86- $ account_sid = config ( ' notifier.twilio. account_sid ') ;
87- $ auth_token = config ( ' notifier.twilio. auth_token ') ;
88- $ this ->from_number = config ( ' notifier.twilio. from ') ;
81+ $ account_sid = $ this -> setting [ ' account_sid '] ?? null ;
82+ $ auth_token = $ this -> setting [ ' auth_token '] ?? null ;
83+ $ this ->from_number = $ this -> setting [ ' from '] ?? null ;
8984
9085 if (!$ account_sid || !$ auth_token || !$ this ->from_number ) {
9186 throw new InvalidArgumentException ('Twilio credentials are required ' );
9287 }
9388
94- $ this ->client = new Client ($ account_sid , $ auth_token );
95-
9689 if (!isset ($ data ['to ' ]) || !isset ($ data ['message ' ])) {
9790 throw new InvalidArgumentException ('The phone number and notifier are required ' );
9891 }
9992
10093 try {
101- $ this ->client ->notifiers ->create ($ data ['to ' ], [
94+ $ client = new Client ($ account_sid , $ auth_token );
95+ $ client ->messages ->create ($ data ['to ' ], [
10296 'from ' => $ this ->from_number ,
103- 'body ' => $ data ['notifier ' ]
97+ 'body ' => $ data ['message ' ]
10498 ]);
10599 } catch (\Exception $ e ) {
106100 throw new \RuntimeException ('Error while sending SMS: ' . $ e ->getMessage ());
@@ -126,7 +120,7 @@ private function sendWithCallisto(Model $context, Notifier $notifier): void
126120
127121 $ data = $ notifier ->toSms ($ context );
128122
129- if (!isset ($ data ['to ' ]) || !isset ($ data ['message ' ])) {
123+ if (!isset ($ data ['to ' ]) || !isset ($ data ['message ' ]) || ! isset ( $ data [ ' sender ' ]) ) {
130124 throw new InvalidArgumentException ('The phone number and notifier are required ' );
131125 }
132126
@@ -139,6 +133,7 @@ private function sendWithCallisto(Model $context, Notifier $notifier): void
139133 $ payload = [
140134 'to ' => (array ) $ data ['to ' ],
141135 'message ' => $ data ['message ' ],
136+ 'sender ' => $ data ['sender ' ],
142137 ];
143138
144139 if ($ data ['notify_url ' ]) {
@@ -149,4 +144,4 @@ private function sendWithCallisto(Model $context, Notifier $notifier): void
149144 ->acceptJson ()
150145 ->post ('v1/sms/send ' , $ payload );
151146 }
152- }
147+ }
0 commit comments