Skip to content

Commit 33f9f04

Browse files
committed
Refactoring sms adapter
1 parent 3a7b588 commit 33f9f04

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/Notifier/Adapters/SmsChannelAdapter.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SmsChannelAdapter implements ChannelAdapterInterface
3939
public function __construct()
4040
{
4141
$config = config('notifier.sms');
42-
$this->setting = $config['setting'] ?? [];
42+
$this->setting = $config;
4343
$this->sms_provider = $config['provider'] ?? 'callisto';
4444
}
4545

@@ -77,10 +77,11 @@ public function send(Model $context, Notifier $notifier): void
7777
private function sendWithTwilio(Model $context, Notifier $notifier): void
7878
{
7979
$data = $notifier->toSms($context);
80+
$config = $this->setting['twilio'] ?? [];
8081

81-
$account_sid = $this->setting['account_sid'] ?? null;
82-
$auth_token = $this->setting['auth_token'] ?? null;
83-
$this->from_number = $this->setting['from'] ?? null;
82+
$account_sid = $config['account_sid'] ?? null;
83+
$auth_token = $config['auth_token'] ?? null;
84+
$this->from_number = $config['from'] ?? null;
8485

8586
if (!$account_sid || !$auth_token || !$this->from_number) {
8687
throw new InvalidArgumentException('Twilio credentials are required');
@@ -110,17 +111,20 @@ private function sendWithTwilio(Model $context, Notifier $notifier): void
110111
*/
111112
private function sendWithCallisto(Model $context, Notifier $notifier): void
112113
{
113-
$access_key = $this->setting['access_key'] ?? null;
114-
$access_secret = $this->setting['access_secret'] ?? null;
115-
$notify_url = $this->setting['notify_url'] ?? null;
114+
$config = $this->setting['callisto'] ?? [];
115+
116+
$access_key = $config['access_key'] ?? null;
117+
$access_secret = $config['access_secret'] ?? null;
118+
$notify_url = $config['notify_url'] ?? null;
119+
$sender = $config['sender'] ?? null;
116120

117121
if (!$access_key || !$access_secret) {
118122
throw new InvalidArgumentException('Callisto credentials are required');
119123
}
120124

121125
$data = $notifier->toSms($context);
122126

123-
if (!isset($data['to']) || !isset($data['message']) || !isset($data['sender'])) {
127+
if (!isset($data['to']) || !isset($data['message'])) {
124128
throw new InvalidArgumentException('The phone number and notifier are required');
125129
}
126130

@@ -133,7 +137,7 @@ private function sendWithCallisto(Model $context, Notifier $notifier): void
133137
$payload = [
134138
'to' => (array) $data['to'],
135139
'message' => $data['message'],
136-
'sender' => $data['sender'],
140+
'sender' => $data['sender'] ?? $sender,
137141
];
138142

139143
if ($data['notify_url']) {

0 commit comments

Comments
 (0)