Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add sms from override to constructor #66

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Utopia/Messaging/Adapters/SMS/Clickatell.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Clickatell extends SMSAdapter
*/
public function __construct(
private string $apiKey,
private ?string $from = null
) {
}

Expand Down Expand Up @@ -43,7 +44,7 @@ protected function process(SMS $message): string
],
body: \json_encode([
'content' => $message->getContent(),
'from' => $message->getFrom(),
'from' => $this->from ?? $message->getFrom(),
'to' => $message->getTo(),
]),
);
Expand Down
5 changes: 3 additions & 2 deletions src/Utopia/Messaging/Adapters/SMS/Infobip.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Infobip extends SMSAdapter
*/
public function __construct(
private string $apiBaseUrl,
private string $apiKey
private string $apiKey,
private ?string $from = null
) {
}

Expand Down Expand Up @@ -48,7 +49,7 @@ protected function process(SMS $message): string
body: \json_encode([
'messages' => [
'text' => $message->getContent(),
'from' => $message->getFrom(),
'from' => $this->from ?? $message->getFrom(),
'destinations' => $to,
],
]),
Expand Down
5 changes: 3 additions & 2 deletions src/Utopia/Messaging/Adapters/SMS/Plivo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Plivo extends SMSAdapter
*/
public function __construct(
private string $authId,
private string $authToken
private string $authToken,
private ?string $from = null
) {
}

Expand Down Expand Up @@ -44,7 +45,7 @@ protected function process(SMS $message): string
],
body: \http_build_query([
'text' => $message->getContent(),
'src' => $message->getFrom() ?? 'Plivo',
'src' => $this->from ?? $message->getFrom() ?? 'Plivo',
'dst' => \implode('<', $message->getTo()),
]),
);
Expand Down
5 changes: 3 additions & 2 deletions src/Utopia/Messaging/Adapters/SMS/Seven.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Seven extends SMSAdapter
* @param string $apiKey Seven API token
*/
public function __construct(
private string $apiKey
private string $apiKey,
private ?string $from = null
) {
}

Expand Down Expand Up @@ -42,7 +43,7 @@ protected function process(SMS $message): string
'content-type: application/json',
],
body: \json_encode([
'from' => $message->getFrom(),
'from' => $this->from ?? $message->getFrom(),
'to' => \implode(',', $message->getTo()),
'text' => $message->getContent(),
]),
Expand Down
5 changes: 3 additions & 2 deletions src/Utopia/Messaging/Adapters/SMS/Sinch.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Sinch extends SMSAdapter
*/
public function __construct(
private string $servicePlanId,
private string $apiToken
private string $apiToken,
private ?string $from = null
) {
}

Expand Down Expand Up @@ -46,7 +47,7 @@ protected function process(SMS $message): string
'content-type: application/json',
],
body: \json_encode([
'from' => $message->getFrom(),
'from' => $this->from ?? $message->getFrom(),
'to' => $to,
'body' => $message->getContent(),
]),
Expand Down
3 changes: 2 additions & 1 deletion src/Utopia/Messaging/Adapters/SMS/Telnyx.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Telnyx extends SMSAdapter
*/
public function __construct(
private string $apiKey,
private ?string $from = null
) {
}

Expand Down Expand Up @@ -41,7 +42,7 @@ protected function process(SMS $message): string
],
body: \json_encode([
'text' => $message->getContent(),
'from' => $message->getFrom(),
'from' => $this->from ?? $message->getFrom(),
'to' => $message->getTo()[0],
]),
);
Expand Down
5 changes: 3 additions & 2 deletions src/Utopia/Messaging/Adapters/SMS/TextMagic.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class TextMagic extends SMSAdapter
*/
public function __construct(
private string $username,
private string $apiKey
private string $apiKey,
private ?string $from = null
) {
}

Expand Down Expand Up @@ -51,7 +52,7 @@ protected function process(SMS $message): string
],
body: \http_build_query([
'text' => $message->getContent(),
'from' => \ltrim($message->getFrom(), '+'),
'from' => \ltrim($this->from ?? $message->getFrom(), '+'),
'phones' => \implode(',', $to),
]),
);
Expand Down
5 changes: 3 additions & 2 deletions src/Utopia/Messaging/Adapters/SMS/Twilio.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Twilio extends SMSAdapter
*/
public function __construct(
private string $accountSid,
private string $authToken
private string $authToken,
private ?string $from = null
) {
}

Expand Down Expand Up @@ -42,7 +43,7 @@ protected function process(SMS $message): string
],
body: \http_build_query([
'Body' => $message->getContent(),
'From' => $message->getFrom(),
'From' => $this->from ?? $message->getFrom(),
'To' => $message->getTo()[0],
]),
);
Expand Down
5 changes: 3 additions & 2 deletions src/Utopia/Messaging/Adapters/SMS/Vonage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Vonage extends SMSAdapter
*/
public function __construct(
private string $apiKey,
private string $apiSecret
private string $apiSecret,
private ?string $from = null
) {
}

Expand Down Expand Up @@ -47,7 +48,7 @@ protected function process(SMS $message): string
url: 'https://rest.nexmo.com/sms/json',
body: \http_build_query([
'text' => $message->getContent(),
'from' => $message->getFrom(),
'from' => $this->from ?? $message->getFrom(),
'to' => $to[0], //\implode(',', $to),
'api_key' => $this->apiKey,
'api_secret' => $this->apiSecret,
Expand Down
Loading