From ef2caf9212c4aa51bd0a6b58102d7e50a774a475 Mon Sep 17 00:00:00 2001 From: wess Date: Tue, 24 Oct 2023 15:47:46 -0400 Subject: [PATCH 01/14] Fixes issue with to grouping --- src/Utopia/Messaging/Adapters/SMS/Msg91.php | 10 +++++---- tests/e2e/SMS/Msg91Test.php | 23 ++++++++++++--------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Msg91.php b/src/Utopia/Messaging/Adapters/SMS/Msg91.php index 766832f8..bdf3b014 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Msg91.php +++ b/src/Utopia/Messaging/Adapters/SMS/Msg91.php @@ -38,10 +38,12 @@ public function getMaxMessagesPerRequest(): int */ protected function process(SMS $message): string { - $to = \array_map( - fn ($to) => ['mobiles' => \ltrim($to, '+')], - $message->getTo() - ); + // $to = \array_map( + // fn ($to) => ['mobiles' => \ltrim($to, '+')], + // $message->getTo() + // ); + + $to = ['mobiles' => $message->getTo()]; return $this->request( method: 'POST', diff --git a/tests/e2e/SMS/Msg91Test.php b/tests/e2e/SMS/Msg91Test.php index df90f4c4..55ce9c3e 100644 --- a/tests/e2e/SMS/Msg91Test.php +++ b/tests/e2e/SMS/Msg91Test.php @@ -12,19 +12,22 @@ class Msg91Test extends Base */ public function testSendSMS() { - // $sender = new Msg91(getenv('MSG_91_SENDER_ID'), getenv('MSG_91_AUTH_KEY')); + $sender = new Msg91(getenv('MSG_91_SENDER_ID'), getenv('MSG_91_AUTH_KEY')); - // $message = new SMS( - // to: [getenv('MSG_91_TO')], - // content: 'Test Content', - // from: getenv('MSG_91_FROM') - // ); + $message = new SMS( + to: [getenv('MSG_91_TO')], + content: 'Test Content', + from: getenv('MSG_91_FROM') + ); - // $response = $sender->send($message); - // $result = \json_decode($response, true); + $response = $sender->send($message); + $result = \json_decode($response, true); - // $this->assertEquals('success', $result['type']); + var_dump($result); + die; + + $this->assertEquals('success', $result['type']); - $this->markTestSkipped('Msg91 requires business verification to use template and SMS api.'); + // $this->markTestSkipped('Msg91 requires business verification to use template and SMS api.'); } } From 0ee2ebeaac9da307f418bfa5efa900c0d762a88a Mon Sep 17 00:00:00 2001 From: wess Date: Wed, 25 Oct 2023 11:14:48 -0400 Subject: [PATCH 02/14] Fixing Msg91 delivery --- src/Utopia/Messaging/Adapters/SMS/Msg91.php | 7 +------ tests/e2e/SMS/Msg91Test.php | 3 --- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Msg91.php b/src/Utopia/Messaging/Adapters/SMS/Msg91.php index bdf3b014..2c51450c 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Msg91.php +++ b/src/Utopia/Messaging/Adapters/SMS/Msg91.php @@ -38,12 +38,7 @@ public function getMaxMessagesPerRequest(): int */ protected function process(SMS $message): string { - // $to = \array_map( - // fn ($to) => ['mobiles' => \ltrim($to, '+')], - // $message->getTo() - // ); - - $to = ['mobiles' => $message->getTo()]; + $to = ['mobiles' => \implode($message->getTo())]; return $this->request( method: 'POST', diff --git a/tests/e2e/SMS/Msg91Test.php b/tests/e2e/SMS/Msg91Test.php index 55ce9c3e..33fad69f 100644 --- a/tests/e2e/SMS/Msg91Test.php +++ b/tests/e2e/SMS/Msg91Test.php @@ -23,9 +23,6 @@ public function testSendSMS() $response = $sender->send($message); $result = \json_decode($response, true); - var_dump($result); - die; - $this->assertEquals('success', $result['type']); // $this->markTestSkipped('Msg91 requires business verification to use template and SMS api.'); From ae5aed1a0a24d75644255ac4dba90dbf3c21c51a Mon Sep 17 00:00:00 2001 From: wess Date: Wed, 25 Oct 2023 12:04:57 -0400 Subject: [PATCH 03/14] Updates $to for Msg91 recipents Updates tests --- src/Utopia/Messaging/Adapters/SMS/Msg91.php | 4 ++-- tests/e2e/SMS/Msg91Test.php | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Msg91.php b/src/Utopia/Messaging/Adapters/SMS/Msg91.php index 2c51450c..3cd1f081 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Msg91.php +++ b/src/Utopia/Messaging/Adapters/SMS/Msg91.php @@ -38,7 +38,7 @@ public function getMaxMessagesPerRequest(): int */ protected function process(SMS $message): string { - $to = ['mobiles' => \implode($message->getTo())]; + $to = ['mobiles' => \implode(",", $message->getTo())]; return $this->request( method: 'POST', @@ -69,7 +69,7 @@ private function addTemplate(string $content, string $senderId, string $template 'template' => $content, 'sender_id' => $senderId, 'template_name' => $templateName, - 'smsType' => 'NORMAL', + 'smsType' => $smsType, ]) ); } diff --git a/tests/e2e/SMS/Msg91Test.php b/tests/e2e/SMS/Msg91Test.php index 33fad69f..55ce9c3e 100644 --- a/tests/e2e/SMS/Msg91Test.php +++ b/tests/e2e/SMS/Msg91Test.php @@ -23,6 +23,9 @@ public function testSendSMS() $response = $sender->send($message); $result = \json_decode($response, true); + var_dump($result); + die; + $this->assertEquals('success', $result['type']); // $this->markTestSkipped('Msg91 requires business verification to use template and SMS api.'); From b5b64c32003beec3ac3902fbb625bcc513abb19b Mon Sep 17 00:00:00 2001 From: wess Date: Wed, 8 Nov 2023 18:44:43 -0800 Subject: [PATCH 04/14] Formatting --- src/Utopia/Messaging/Adapters/SMS/Msg91.php | 2 +- tests/e2e/SMS/Msg91Test.php | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Msg91.php b/src/Utopia/Messaging/Adapters/SMS/Msg91.php index 3cd1f081..32bac4ec 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Msg91.php +++ b/src/Utopia/Messaging/Adapters/SMS/Msg91.php @@ -38,7 +38,7 @@ public function getMaxMessagesPerRequest(): int */ protected function process(SMS $message): string { - $to = ['mobiles' => \implode(",", $message->getTo())]; + $to = ['mobiles' => \implode(',', $message->getTo())]; return $this->request( method: 'POST', diff --git a/tests/e2e/SMS/Msg91Test.php b/tests/e2e/SMS/Msg91Test.php index 55ce9c3e..33fad69f 100644 --- a/tests/e2e/SMS/Msg91Test.php +++ b/tests/e2e/SMS/Msg91Test.php @@ -23,9 +23,6 @@ public function testSendSMS() $response = $sender->send($message); $result = \json_decode($response, true); - var_dump($result); - die; - $this->assertEquals('success', $result['type']); // $this->markTestSkipped('Msg91 requires business verification to use template and SMS api.'); From c40274d078cb90c9dbd14b91c248ff972d17612a Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 9 Nov 2023 12:20:03 +0000 Subject: [PATCH 05/14] fix: msg91 payload --- src/Utopia/Messaging/Adapters/SMS/Msg91.php | 40 ++++++++++----------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Msg91.php b/src/Utopia/Messaging/Adapters/SMS/Msg91.php index 32bac4ec..c2ce2ff0 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Msg91.php +++ b/src/Utopia/Messaging/Adapters/SMS/Msg91.php @@ -10,6 +10,8 @@ class Msg91 extends SMSAdapter { + private $templateId; + /** * @param string $senderId Msg91 Sender ID * @param string $authKey Msg91 Auth Key @@ -31,6 +33,13 @@ public function getMaxMessagesPerRequest(): int return 1000; } + public function setTemplate(string $templateId): self + { + $this->templateId = $templateId; + + return $this; + } + /** * {@inheritdoc} * @@ -38,7 +47,13 @@ public function getMaxMessagesPerRequest(): int */ protected function process(SMS $message): string { - $to = ['mobiles' => \implode(',', $message->getTo())]; + $recipients = []; + foreach ($message->getTo() as $recipient) { + $recipients[] = [ + 'mobiles' => $recipient, + 'content' => $message->getContent(), + ]; + } return $this->request( method: 'POST', @@ -49,28 +64,9 @@ protected function process(SMS $message): string ], body: \json_encode([ 'sender' => $this->senderId, - 'otp' => $message->getContent(), - 'flow_id' => $message->getFrom(), - 'recipients' => [$to], + 'template_id' => $this->templateId, + 'recipients' => $recipients, ]), ); } - - private function addTemplate(string $content, string $senderId, string $templateName, string $smsType = 'NORMAL') - { - return $this->request( - method: 'POST', - url: 'https://control.msg91.com/api/v5/sms/addTemplate', - headers: [ - 'content-type: application/json', - "authkey: {$this->authKey}", - ], - body: \json_encode([ - 'template' => $content, - 'sender_id' => $senderId, - 'template_name' => $templateName, - 'smsType' => $smsType, - ]) - ); - } } From fd88522db3cb852aa62af3b60790510cef9f8f89 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 9 Nov 2023 12:24:48 +0000 Subject: [PATCH 06/14] test: fix msg91 --- tests/e2e/SMS/Msg91Test.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/e2e/SMS/Msg91Test.php b/tests/e2e/SMS/Msg91Test.php index 33fad69f..6849b061 100644 --- a/tests/e2e/SMS/Msg91Test.php +++ b/tests/e2e/SMS/Msg91Test.php @@ -13,18 +13,17 @@ class Msg91Test extends Base public function testSendSMS() { $sender = new Msg91(getenv('MSG_91_SENDER_ID'), getenv('MSG_91_AUTH_KEY')); + $sender->setTemplate(getenv('MSG_91_FROM')); $message = new SMS( to: [getenv('MSG_91_TO')], content: 'Test Content', - from: getenv('MSG_91_FROM') ); $response = $sender->send($message); $result = \json_decode($response, true); $this->assertEquals('success', $result['type']); - - // $this->markTestSkipped('Msg91 requires business verification to use template and SMS api.'); + $this->assertNotEmpty($result['message']); } } From fee654ef61160e92350551e0081baac857a6a268 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:17:55 +0000 Subject: [PATCH 07/14] feat: add otp variable --- src/Utopia/Messaging/Adapters/SMS/Msg91.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Utopia/Messaging/Adapters/SMS/Msg91.php b/src/Utopia/Messaging/Adapters/SMS/Msg91.php index c2ce2ff0..f21ddbf6 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Msg91.php +++ b/src/Utopia/Messaging/Adapters/SMS/Msg91.php @@ -52,6 +52,7 @@ protected function process(SMS $message): string $recipients[] = [ 'mobiles' => $recipient, 'content' => $message->getContent(), + 'otp' => $message->getContent(), ]; } From d327e235e9faf5477995363b3d8392e7afca5d30 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 10 Nov 2023 09:46:30 +0000 Subject: [PATCH 08/14] feat: trim + from msg91 numbers --- src/Utopia/Messaging/Adapters/SMS/Msg91.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Msg91.php b/src/Utopia/Messaging/Adapters/SMS/Msg91.php index f21ddbf6..5a217a30 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Msg91.php +++ b/src/Utopia/Messaging/Adapters/SMS/Msg91.php @@ -50,7 +50,7 @@ protected function process(SMS $message): string $recipients = []; foreach ($message->getTo() as $recipient) { $recipients[] = [ - 'mobiles' => $recipient, + 'mobiles' => \ltrim($recipient, '+'), 'content' => $message->getContent(), 'otp' => $message->getContent(), ]; From b4d370475cd3afdf4b5570572047f83eace4e1fa Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 14 Nov 2023 13:04:26 +1300 Subject: [PATCH 09/14] Update src/Utopia/Messaging/Adapters/SMS/Msg91.php --- src/Utopia/Messaging/Adapters/SMS/Msg91.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Msg91.php b/src/Utopia/Messaging/Adapters/SMS/Msg91.php index 5a217a30..ed89ccb2 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Msg91.php +++ b/src/Utopia/Messaging/Adapters/SMS/Msg91.php @@ -10,7 +10,7 @@ class Msg91 extends SMSAdapter { - private $templateId; + private string $templateId; /** * @param string $senderId Msg91 Sender ID From b0a314f743d5b0ea5604c6b86ef7cf3c6eedf8e4 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Mon, 20 Nov 2023 10:03:47 +0000 Subject: [PATCH 10/14] feat: add sms from override to constructor --- src/Utopia/Messaging/Adapters/SMS/Clickatell.php | 3 ++- src/Utopia/Messaging/Adapters/SMS/Infobip.php | 5 +++-- src/Utopia/Messaging/Adapters/SMS/Plivo.php | 5 +++-- src/Utopia/Messaging/Adapters/SMS/Seven.php | 5 +++-- src/Utopia/Messaging/Adapters/SMS/Sinch.php | 5 +++-- src/Utopia/Messaging/Adapters/SMS/Telnyx.php | 3 ++- src/Utopia/Messaging/Adapters/SMS/TextMagic.php | 5 +++-- src/Utopia/Messaging/Adapters/SMS/Twilio.php | 5 +++-- src/Utopia/Messaging/Adapters/SMS/Vonage.php | 5 +++-- 9 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Clickatell.php b/src/Utopia/Messaging/Adapters/SMS/Clickatell.php index 4e302b32..1d004713 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Clickatell.php +++ b/src/Utopia/Messaging/Adapters/SMS/Clickatell.php @@ -14,6 +14,7 @@ class Clickatell extends SMSAdapter */ public function __construct( private string $apiKey, + private ?string $from = null ) { } @@ -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(), ]), ); diff --git a/src/Utopia/Messaging/Adapters/SMS/Infobip.php b/src/Utopia/Messaging/Adapters/SMS/Infobip.php index 9d1a584b..f18a62f2 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Infobip.php +++ b/src/Utopia/Messaging/Adapters/SMS/Infobip.php @@ -15,7 +15,8 @@ class Infobip extends SMSAdapter */ public function __construct( private string $apiBaseUrl, - private string $apiKey + private string $apiKey, + private ?string $from = null ) { } @@ -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, ], ]), diff --git a/src/Utopia/Messaging/Adapters/SMS/Plivo.php b/src/Utopia/Messaging/Adapters/SMS/Plivo.php index 4f923fdf..b16642a2 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Plivo.php +++ b/src/Utopia/Messaging/Adapters/SMS/Plivo.php @@ -15,7 +15,8 @@ class Plivo extends SMSAdapter */ public function __construct( private string $authId, - private string $authToken + private string $authToken, + private ?string $from = null ) { } @@ -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()), ]), ); diff --git a/src/Utopia/Messaging/Adapters/SMS/Seven.php b/src/Utopia/Messaging/Adapters/SMS/Seven.php index 383bdf94..2b3af28e 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Seven.php +++ b/src/Utopia/Messaging/Adapters/SMS/Seven.php @@ -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 ) { } @@ -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(), ]), diff --git a/src/Utopia/Messaging/Adapters/SMS/Sinch.php b/src/Utopia/Messaging/Adapters/SMS/Sinch.php index ac0dc0b3..7c30b363 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Sinch.php +++ b/src/Utopia/Messaging/Adapters/SMS/Sinch.php @@ -15,7 +15,8 @@ class Sinch extends SMSAdapter */ public function __construct( private string $servicePlanId, - private string $apiToken + private string $apiToken, + private ?string $from = null ) { } @@ -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(), ]), diff --git a/src/Utopia/Messaging/Adapters/SMS/Telnyx.php b/src/Utopia/Messaging/Adapters/SMS/Telnyx.php index 431736b5..06b262d2 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Telnyx.php +++ b/src/Utopia/Messaging/Adapters/SMS/Telnyx.php @@ -12,6 +12,7 @@ class Telnyx extends SMSAdapter */ public function __construct( private string $apiKey, + private ?string $from = null ) { } @@ -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], ]), ); diff --git a/src/Utopia/Messaging/Adapters/SMS/TextMagic.php b/src/Utopia/Messaging/Adapters/SMS/TextMagic.php index 68fb4e37..bd74102c 100644 --- a/src/Utopia/Messaging/Adapters/SMS/TextMagic.php +++ b/src/Utopia/Messaging/Adapters/SMS/TextMagic.php @@ -16,7 +16,8 @@ class TextMagic extends SMSAdapter */ public function __construct( private string $username, - private string $apiKey + private string $apiKey, + private ?string $from = null ) { } @@ -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), ]), ); diff --git a/src/Utopia/Messaging/Adapters/SMS/Twilio.php b/src/Utopia/Messaging/Adapters/SMS/Twilio.php index 9f28ff2c..bbcdd854 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Twilio.php +++ b/src/Utopia/Messaging/Adapters/SMS/Twilio.php @@ -13,7 +13,8 @@ class Twilio extends SMSAdapter */ public function __construct( private string $accountSid, - private string $authToken + private string $authToken, + private ?string $from = null ) { } @@ -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], ]), ); diff --git a/src/Utopia/Messaging/Adapters/SMS/Vonage.php b/src/Utopia/Messaging/Adapters/SMS/Vonage.php index 7ed16714..cdb58c42 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Vonage.php +++ b/src/Utopia/Messaging/Adapters/SMS/Vonage.php @@ -16,7 +16,8 @@ class Vonage extends SMSAdapter */ public function __construct( private string $apiKey, - private string $apiSecret + private string $apiSecret, + private ?string $from = null ) { } @@ -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, From 7223f34ec951df85eab1bd8802141154b4f1160e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 21 Nov 2023 18:50:12 +1300 Subject: [PATCH 11/14] Use default false bool sandbox instead of endpoint param --- src/Utopia/Messaging/Adapters/Push/APNS.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/Push/APNS.php b/src/Utopia/Messaging/Adapters/Push/APNS.php index 56282d83..30fa0368 100644 --- a/src/Utopia/Messaging/Adapters/Push/APNS.php +++ b/src/Utopia/Messaging/Adapters/Push/APNS.php @@ -13,7 +13,7 @@ class APNS extends PushAdapter * @param string $authKeyId * @param string $teamId * @param string $bundleId - * @param string $endpoint + * @param bool $sandbox * @return void */ public function __construct( @@ -21,7 +21,7 @@ public function __construct( private string $authKeyId, private string $teamId, private string $bundleId, - private string $endpoint + private bool $sandbox = false ) { } @@ -98,13 +98,18 @@ private function notify(array $to, array $payload): array ]); $response = ''; + $endpoint = 'api.push.apple.com'; + + if ($this->sandbox) { + $endpoint = 'api.development.push.apple.com'; + } $mh = curl_multi_init(); $handles = []; // Create a handle for each request foreach ($to as $token) { - curl_setopt($ch, CURLOPT_URL, $this->endpoint.'/3/device/'.$token); + curl_setopt($ch, CURLOPT_URL, $endpoint.'/3/device/'.$token); $handle = curl_copy_handle($ch); curl_multi_add_handle($mh, $handle); From 4ba7e302486cf7e1f734d93930566895ebf5c0c1 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 21 Nov 2023 18:53:48 +1300 Subject: [PATCH 12/14] Add https scheme --- src/Utopia/Messaging/Adapters/Push/APNS.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/Push/APNS.php b/src/Utopia/Messaging/Adapters/Push/APNS.php index 30fa0368..6c2d0f38 100644 --- a/src/Utopia/Messaging/Adapters/Push/APNS.php +++ b/src/Utopia/Messaging/Adapters/Push/APNS.php @@ -98,10 +98,10 @@ private function notify(array $to, array $payload): array ]); $response = ''; - $endpoint = 'api.push.apple.com'; + $endpoint = 'https://api.push.apple.com'; if ($this->sandbox) { - $endpoint = 'api.development.push.apple.com'; + $endpoint = 'https://api.development.push.apple.com'; } $mh = curl_multi_init(); From 8e49773b7395c7ad74ba572a2148068891aa0968 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 21 Nov 2023 19:03:46 +1300 Subject: [PATCH 13/14] Format --- composer.json | 2 +- composer.lock | 30 +++++++++---------- src/Utopia/Messaging/Adapter.php | 10 +------ .../Messaging/Adapters/Email/Mailgun.php | 4 --- .../Messaging/Adapters/Email/Sendgrid.php | 6 ---- src/Utopia/Messaging/Adapters/Push/APNS.php | 22 ++++---------- src/Utopia/Messaging/Adapters/Push/FCM.php | 4 --- src/Utopia/Messaging/Messages/Email.php | 18 ----------- src/Utopia/Messaging/Messages/Push.php | 30 ------------------- src/Utopia/Messaging/Messages/SMS.php | 12 -------- tests/e2e/Email/EmailTest.php | 3 +- tests/e2e/Email/MailgunTest.php | 3 +- tests/e2e/Email/SendgridTest.php | 2 +- tests/e2e/Push/APNSTest.php | 2 +- tests/e2e/Push/FCMTest.php | 3 +- tests/e2e/SMS/GEOSMS/CallingCodeTest.php | 3 +- tests/e2e/SMS/GEOSMSTest.php | 3 +- tests/e2e/SMS/Msg91Test.php | 3 +- tests/e2e/SMS/SMSTest.php | 3 +- tests/e2e/SMS/TelesignTest.php | 4 ++- tests/e2e/SMS/TelnyxTest.php | 3 +- tests/e2e/SMS/TwilioTest.php | 3 +- tests/e2e/SMS/VonageTest.php | 3 +- 23 files changed, 47 insertions(+), 129 deletions(-) diff --git a/composer.json b/composer.json index bac108a5..8f77b494 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "require-dev": { "phpunit/phpunit": "9.6.*", "phpmailer/phpmailer": "6.8.*", - "laravel/pint": "^1.2" + "laravel/pint": "1.13.*" }, "config": { "platform": { diff --git a/composer.lock b/composer.lock index 9f6b978b..835860e3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5ecbd865cbd7f14e7819fb79643573be", + "content-hash": "31345eedeb45973edbfc61a2c6b722b6", "packages": [], "packages-dev": [ { @@ -79,16 +79,16 @@ }, { "name": "laravel/pint", - "version": "v1.2.0", + "version": "v1.13.6", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "1d276e4c803397a26cc337df908f55c2a4e90d86" + "reference": "3e3d2ab01c7d8b484c18e6100ecf53639c744fa7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/1d276e4c803397a26cc337df908f55c2a4e90d86", - "reference": "1d276e4c803397a26cc337df908f55c2a4e90d86", + "url": "https://api.github.com/repos/laravel/pint/zipball/3e3d2ab01c7d8b484c18e6100ecf53639c744fa7", + "reference": "3e3d2ab01c7d8b484c18e6100ecf53639c744fa7", "shasum": "" }, "require": { @@ -96,16 +96,16 @@ "ext-mbstring": "*", "ext-tokenizer": "*", "ext-xml": "*", - "php": "^8.0" + "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.11.0", - "illuminate/view": "^9.27", - "laravel-zero/framework": "^9.1.3", - "mockery/mockery": "^1.5.0", - "nunomaduro/larastan": "^2.2", - "nunomaduro/termwind": "^1.14.0", - "pestphp/pest": "^1.22.1" + "friendsofphp/php-cs-fixer": "^3.38.0", + "illuminate/view": "^10.30.1", + "laravel-zero/framework": "^10.3.0", + "mockery/mockery": "^1.6.6", + "nunomaduro/larastan": "^2.6.4", + "nunomaduro/termwind": "^1.15.1", + "pestphp/pest": "^2.24.2" }, "bin": [ "builds/pint" @@ -141,7 +141,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2022-09-13T15:07:15+00:00" + "time": "2023-11-07T17:59:57+00:00" }, { "name": "myclabs/deep-copy", @@ -1898,5 +1898,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/Utopia/Messaging/Adapter.php b/src/Utopia/Messaging/Adapter.php index 60a909ef..f616600b 100644 --- a/src/Utopia/Messaging/Adapter.php +++ b/src/Utopia/Messaging/Adapter.php @@ -6,29 +6,21 @@ abstract class Adapter { /** * Get the name of the adapter. - * - * @return string */ abstract public function getName(): string; /** * Get the type of the adapter. - * - * @return string */ abstract public function getType(): string; /** * Get the type of the message the adapter can send. - * - * @return string */ abstract public function getMessageType(): string; /** * Get the maximum number of messages that can be sent in a single request. - * - * @return int */ abstract public function getMaxMessagesPerRequest(): int; @@ -55,7 +47,7 @@ protected function request( string $method, string $url, array $headers = [], - ?string $body = null, + string $body = null, ): string { $ch = \curl_init(); diff --git a/src/Utopia/Messaging/Adapters/Email/Mailgun.php b/src/Utopia/Messaging/Adapters/Email/Mailgun.php index 4e3882e8..09ad8895 100644 --- a/src/Utopia/Messaging/Adapters/Email/Mailgun.php +++ b/src/Utopia/Messaging/Adapters/Email/Mailgun.php @@ -20,8 +20,6 @@ public function __construct( /** * Get adapter name. - * - * @return string */ public function getName(): string { @@ -30,8 +28,6 @@ public function getName(): string /** * Get adapter description. - * - * @return int */ public function getMaxMessagesPerRequest(): int { diff --git a/src/Utopia/Messaging/Adapters/Email/Sendgrid.php b/src/Utopia/Messaging/Adapters/Email/Sendgrid.php index e91c31cc..18dccc20 100644 --- a/src/Utopia/Messaging/Adapters/Email/Sendgrid.php +++ b/src/Utopia/Messaging/Adapters/Email/Sendgrid.php @@ -17,8 +17,6 @@ public function __construct(private string $apiKey) /** * Get adapter name. - * - * @return string */ public function getName(): string { @@ -27,8 +25,6 @@ public function getName(): string /** * Get max messages per request. - * - * @return int */ public function getMaxMessagesPerRequest(): int { @@ -38,8 +34,6 @@ public function getMaxMessagesPerRequest(): int /** * {@inheritdoc} * - * @param Email $message - * @return string * * @throws Exception */ diff --git a/src/Utopia/Messaging/Adapters/Push/APNS.php b/src/Utopia/Messaging/Adapters/Push/APNS.php index 6c2d0f38..f501daab 100644 --- a/src/Utopia/Messaging/Adapters/Push/APNS.php +++ b/src/Utopia/Messaging/Adapters/Push/APNS.php @@ -9,26 +9,19 @@ class APNS extends PushAdapter { /** - * @param string $authKey - * @param string $authKeyId - * @param string $teamId - * @param string $bundleId - * @param bool $sandbox * @return void */ public function __construct( - private string $authKey, - private string $authKeyId, - private string $teamId, - private string $bundleId, - private bool $sandbox = false + private string $authKey, + private string $authKeyId, + private string $teamId, + private string $bundleId, + private bool $sandbox = false ) { } /** * Get adapter name. - * - * @return string */ public function getName(): string { @@ -37,8 +30,6 @@ public function getName(): string /** * Get max messages per request. - * - * @return int */ public function getMaxMessagesPerRequest(): int { @@ -48,8 +39,6 @@ public function getMaxMessagesPerRequest(): int /** * {@inheritdoc} * - * @param Push $message - * @return string * * @throws Exception */ @@ -184,7 +173,6 @@ function ($value) { /** * Generate JWT. * - * @return string * * @throws Exception */ diff --git a/src/Utopia/Messaging/Adapters/Push/FCM.php b/src/Utopia/Messaging/Adapters/Push/FCM.php index 8a4d8ac2..4a028f62 100644 --- a/src/Utopia/Messaging/Adapters/Push/FCM.php +++ b/src/Utopia/Messaging/Adapters/Push/FCM.php @@ -17,8 +17,6 @@ public function __construct( /** * Get adapter name. - * - * @return string */ public function getName(): string { @@ -27,8 +25,6 @@ public function getName(): string /** * Get max messages per request. - * - * @return int */ public function getMaxMessagesPerRequest(): int { diff --git a/src/Utopia/Messaging/Messages/Email.php b/src/Utopia/Messaging/Messages/Email.php index 21fedeea..545b1d54 100644 --- a/src/Utopia/Messaging/Messages/Email.php +++ b/src/Utopia/Messaging/Messages/Email.php @@ -24,49 +24,31 @@ public function __construct( ) { } - /** - * @return array - */ public function getTo(): array { return $this->to; } - /** - * @return string - */ public function getSubject(): string { return $this->subject; } - /** - * @return string - */ public function getContent(): string { return $this->content; } - /** - * @return string|null - */ public function getFrom(): ?string { return $this->from; } - /** - * @return array|null - */ public function getAttachments(): ?array { return $this->attachments; } - /** - * @return bool - */ public function isHtml(): bool { return $this->html; diff --git a/src/Utopia/Messaging/Messages/Push.php b/src/Utopia/Messaging/Messages/Push.php index 93b8f5d7..337d0fbd 100644 --- a/src/Utopia/Messaging/Messages/Push.php +++ b/src/Utopia/Messaging/Messages/Push.php @@ -32,9 +32,6 @@ public function __construct( ) { } - /** - * @return array - */ public function getTo(): array { return $this->to; @@ -45,73 +42,46 @@ public function getFrom(): ?string return null; } - /** - * @return string - */ public function getTitle(): string { return $this->title; } - /** - * @return string - */ public function getBody(): string { return $this->body; } - /** - * @return array|null - */ public function getData(): ?array { return $this->data; } - /** - * @return string|null - */ public function getAction(): ?string { return $this->action; } - /** - * @return string|null - */ public function getSound(): ?string { return $this->sound; } - /** - * @return string|null - */ public function getIcon(): ?string { return $this->icon; } - /** - * @return string|null - */ public function getColor(): ?string { return $this->color; } - /** - * @return string|null - */ public function getTag(): ?string { return $this->tag; } - /** - * @return string|null - */ public function getBadge(): ?string { return $this->badge; diff --git a/src/Utopia/Messaging/Messages/SMS.php b/src/Utopia/Messaging/Messages/SMS.php index bcb913c0..31be8d99 100644 --- a/src/Utopia/Messaging/Messages/SMS.php +++ b/src/Utopia/Messaging/Messages/SMS.php @@ -14,33 +14,21 @@ public function __construct( ) { } - /** - * @return array - */ public function getTo(): array { return $this->to; } - /** - * @return string - */ public function getContent(): string { return $this->content; } - /** - * @return string|null - */ public function getFrom(): ?string { return $this->from; } - /** - * @return array|null - */ public function getAttachments(): ?array { return $this->attachments; diff --git a/tests/e2e/Email/EmailTest.php b/tests/e2e/Email/EmailTest.php index 40606255..f72fe37e 100644 --- a/tests/e2e/Email/EmailTest.php +++ b/tests/e2e/Email/EmailTest.php @@ -1,7 +1,8 @@ Date: Tue, 21 Nov 2023 23:11:22 +1300 Subject: [PATCH 14/14] Fix missing base imports --- tests/e2e/Email/SendgridTest.php | 1 + tests/e2e/Push/APNSTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/e2e/Email/SendgridTest.php b/tests/e2e/Email/SendgridTest.php index 5924992d..d2b5ea00 100644 --- a/tests/e2e/Email/SendgridTest.php +++ b/tests/e2e/Email/SendgridTest.php @@ -2,6 +2,7 @@ namespace Tests\E2E\Email; +use Tests\E2E\Base; use Utopia\Messaging\Adapters\Email\Sendgrid; use Utopia\Messaging\Messages\Email; diff --git a/tests/e2e/Push/APNSTest.php b/tests/e2e/Push/APNSTest.php index 4a066132..335449ca 100644 --- a/tests/e2e/Push/APNSTest.php +++ b/tests/e2e/Push/APNSTest.php @@ -2,6 +2,7 @@ namespace Tests\E2E\Push; +use Tests\E2E\Base; use Utopia\Messaging\Adapters\Push\APNS as APNSAdapter; use Utopia\Messaging\Messages\Push;