From 5170f3c05a36d6bd742a3f3de2e1f1e24de65a9b Mon Sep 17 00:00:00 2001 From: byawitz Date: Tue, 28 Mar 2023 23:45:14 -0400 Subject: [PATCH 01/13] Add Plivo SMS adapter --- README.md | 2 +- src/Utopia/Messaging/Adapters/SMS/Plivo.php | 49 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/Utopia/Messaging/Adapters/SMS/Plivo.php diff --git a/README.md b/README.md index 445406d1..e268cd77 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ $messaging->send($message); - [x] [TextMagic](https://www.textmagic.com/) - [x] [Msg91](https://msg91.com/) - [x] [Vonage](https://www.vonage.com/) -- [ ] [Plivo](https://www.plivo.com/) +- [x] [Plivo](https://www.plivo.com/) - [ ] [Infobip](https://www.infobip.com/) - [ ] [Clickatell](https://www.clickatell.com/) - [ ] [AfricasTalking](https://africastalking.com/) diff --git a/src/Utopia/Messaging/Adapters/SMS/Plivo.php b/src/Utopia/Messaging/Adapters/SMS/Plivo.php new file mode 100644 index 00000000..b53c9df2 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/SMS/Plivo.php @@ -0,0 +1,49 @@ +request( + method: 'POST', + url: "https://api.plivo.com/v1/Account/{$this->authId}/Message/", + headers: [ + 'Authorization: Basic ' . base64_encode("{$this->authId}:{$this->authToken}"), + ], + body: \http_build_query([ + 'text' => $message->getContent(), + 'src' => $message->getFrom(), + 'dst' => \implode('<', $message->getTo()), + ]), + ); + } +} From 5aeadafd663af40f4820c0e6a20c593da71d1c5f Mon Sep 17 00:00:00 2001 From: byawitz Date: Wed, 29 Mar 2023 00:08:31 -0400 Subject: [PATCH 02/13] Add Clickatell SMS adapter --- README.md | 2 +- .../Messaging/Adapters/SMS/Clickatell.php | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/Utopia/Messaging/Adapters/SMS/Clickatell.php diff --git a/README.md b/README.md index e268cd77..9c961367 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ $messaging->send($message); - [x] [Vonage](https://www.vonage.com/) - [x] [Plivo](https://www.plivo.com/) - [ ] [Infobip](https://www.infobip.com/) -- [ ] [Clickatell](https://www.clickatell.com/) +- [x] [Clickatell](https://www.clickatell.com/) - [ ] [AfricasTalking](https://africastalking.com/) - [ ] [Sinch](https://www.sinch.com/) - [ ] [Sms77](https://www.sms77.io/) diff --git a/src/Utopia/Messaging/Adapters/SMS/Clickatell.php b/src/Utopia/Messaging/Adapters/SMS/Clickatell.php new file mode 100644 index 00000000..b8edb612 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/SMS/Clickatell.php @@ -0,0 +1,49 @@ +request( + method: 'POST', + url: "https://platform.clickatell.com/messages", + headers: [ + 'content-type: application/json', + 'Authorization: ' . $this->apiKey, + ], + body: \json_encode([ + 'content' => $message->getContent(), + 'from' => $message->getFrom(), + 'to' => $message->getTo(), + ]), + ); + } +} From 72ae558d7fbf481b6a149097aa72f8604387e42a Mon Sep 17 00:00:00 2001 From: byawitz Date: Wed, 29 Mar 2023 00:26:59 -0400 Subject: [PATCH 03/13] Add Infobip SMS adapter --- README.md | 2 +- src/Utopia/Messaging/Adapters/SMS/Infobip.php | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/Utopia/Messaging/Adapters/SMS/Infobip.php diff --git a/README.md b/README.md index 9c961367..5e6d0ec0 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ $messaging->send($message); - [x] [Msg91](https://msg91.com/) - [x] [Vonage](https://www.vonage.com/) - [x] [Plivo](https://www.plivo.com/) -- [ ] [Infobip](https://www.infobip.com/) +- [x] [Infobip](https://www.infobip.com/) - [x] [Clickatell](https://www.clickatell.com/) - [ ] [AfricasTalking](https://africastalking.com/) - [ ] [Sinch](https://www.sinch.com/) diff --git a/src/Utopia/Messaging/Adapters/SMS/Infobip.php b/src/Utopia/Messaging/Adapters/SMS/Infobip.php new file mode 100644 index 00000000..b13e452f --- /dev/null +++ b/src/Utopia/Messaging/Adapters/SMS/Infobip.php @@ -0,0 +1,54 @@ + ['to' => \ltrim($number, '+')], $message->getTo()); + + return $this->request( + method: 'POST', + url: "https://{$this->apiBaseUrl}/sms/2/text/advanced", + headers: [ + 'Authorization: App ' . $this->apiKey, + 'content-type: application/json', + ], + body: \json_encode([ + 'messages' => [ + 'text' => $message->getContent(), + 'from' => $message->getFrom(), + 'destinations' => $to, + ], + ]), + ); + } +} From 86d1771a927be8ed7d984881208a1a9aeaba0955 Mon Sep 17 00:00:00 2001 From: byawitz Date: Wed, 29 Mar 2023 00:41:09 -0400 Subject: [PATCH 04/13] Add Sinch SMS adapter --- src/Utopia/Messaging/Adapters/SMS/Sinch.php | 52 +++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/Utopia/Messaging/Adapters/SMS/Sinch.php diff --git a/src/Utopia/Messaging/Adapters/SMS/Sinch.php b/src/Utopia/Messaging/Adapters/SMS/Sinch.php new file mode 100644 index 00000000..57c8eb4c --- /dev/null +++ b/src/Utopia/Messaging/Adapters/SMS/Sinch.php @@ -0,0 +1,52 @@ + \ltrim($number, '+'), $message->getTo()); + + return $this->request( + method: 'POST', + url: "https://sms.api.sinch.com/xms/v1/{$this->servicePlanId}/batches", + headers: [ + 'Authorization: Bearer ' . $this->apiToken, + 'content-type: application/json', + ], + body: \json_encode([ + 'from' => $message->getFrom(), + 'to' => $to, + 'body' => $message->getContent(), + ]), + ); + } +} From a1ff7b7f2e337c3e63794761f1bb940ac00dcf0f Mon Sep 17 00:00:00 2001 From: byawitz Date: Wed, 29 Mar 2023 00:41:21 -0400 Subject: [PATCH 05/13] Add Sinch SMS adapter --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e6d0ec0..110675a9 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ $messaging->send($message); - [x] [Infobip](https://www.infobip.com/) - [x] [Clickatell](https://www.clickatell.com/) - [ ] [AfricasTalking](https://africastalking.com/) -- [ ] [Sinch](https://www.sinch.com/) +- [x] [Sinch](https://www.sinch.com/) - [ ] [Sms77](https://www.sms77.io/) - [ ] [SmsGlobal](https://www.smsglobal.com/) From 83dd057a68ba6a89d5ed25b3b12576be1c038d92 Mon Sep 17 00:00:00 2001 From: byawitz Date: Wed, 29 Mar 2023 00:50:34 -0400 Subject: [PATCH 06/13] Add Seven (Formally sms77) SMS adapter --- README.md | 2 +- src/Utopia/Messaging/Adapters/SMS/Seven.php | 49 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/Utopia/Messaging/Adapters/SMS/Seven.php diff --git a/README.md b/README.md index 110675a9..f04d8969 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ $messaging->send($message); - [x] [Clickatell](https://www.clickatell.com/) - [ ] [AfricasTalking](https://africastalking.com/) - [x] [Sinch](https://www.sinch.com/) -- [ ] [Sms77](https://www.sms77.io/) +- [x] [Seven](https://www.seven.io/) - [ ] [SmsGlobal](https://www.smsglobal.com/) ### Push diff --git a/src/Utopia/Messaging/Adapters/SMS/Seven.php b/src/Utopia/Messaging/Adapters/SMS/Seven.php new file mode 100644 index 00000000..beaf0a6f --- /dev/null +++ b/src/Utopia/Messaging/Adapters/SMS/Seven.php @@ -0,0 +1,49 @@ +request( + method: 'POST', + url: "https://gateway.sms77.io/api/sms", + headers: [ + 'Authorization: Basic ' . $this->apiKey, + 'content-type: application/json', + ], + body: \json_encode([ + 'from' => $message->getFrom(), + 'to' => \implode(',', $message->getTo()), + 'text' => $message->getContent(), + ]), + ); + } +} From 1444cc16e4f1eb34303b60dfc9b7082e974714f9 Mon Sep 17 00:00:00 2001 From: byawitz Date: Wed, 29 Mar 2023 01:15:16 -0400 Subject: [PATCH 07/13] Implemented providers pricing compare table --- docs/sms-pricing.md | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 docs/sms-pricing.md diff --git a/docs/sms-pricing.md b/docs/sms-pricing.md new file mode 100644 index 00000000..8a734fb6 --- /dev/null +++ b/docs/sms-pricing.md @@ -0,0 +1,63 @@ +# SMS Provider pricing + +### In case you wonder which provider will suite you with best price + +_This list includes only implemented providers_ + +## SMS Target + +_You can add your country with a full pricing table_ + +- [United States](#united-states) +- [India](#india) +- [Israel](#israel) + +## United States + +_In most providers when you're sending SMS to US numbers you must own a US phone number to provide it in the `from` field. Other might add random phone number they have_ + +| Provider | Unit Price | 10K | +|------------|------------|-------| +| Twilio | 0.0079 | 79 $ | +| Telesign | 0.0062 | 62 $ | +| TextMagic | 0.0400 | 400 $ | +| Msg91 | 0.0067 | 67 $ | +| Vonage | 0.0067 | 67 $ | +| Plivo | 0.0050 | 50 $ | +| Infobip | 0.0070 | 70 $ | +| Clickatell | 0.0075 | 75 $ | +| Seven | 0.0810 | 810 $ | +| Sinch | 0.0120 | 120 $ | +| Telnyx | 0.0440 | 440 $ | + +## India + +| Provider | Unit Price | 10K | +|------------|------------|----------| +| Twilio | 0.0490 | 490 $ | +| Telesign | 0.0485 | 485 $ | +| TextMagic | n/a | | +| Msg91 | 0.0030 | 30 $ | +| Vonage | 0.0449 | 449 $ | +| Plivo | 0.0560 | 560 $ | +| Infobip | n/a | | +| Clickatell | 0.0426 | 426.2 $ | +| Seven | 0.0800 | 81 $ | +| Sinch | n/a | | +| Telnyx | 0.0490 | 490 $ | + +## Israel + +| Provider | Unit Price | 10K | +|------------|------------|----------| +| Twilio | 0.112 | 1120 $ | +| Telesign | 0.0768 | 768 $ | +| TextMagic | n/a | | +| Msg91 | 0.0845 | 845 $ | +| Vonage | 0.1019 | 1019 $ | +| Plivo | 0.101 | 1010 $ | +| Infobip | 0.106 | 1060 $ | +| Clickatell | 0.13144 | 1314.4 $ | +| Seven | 0.08 | 81 $ | +| Sinch | n/a | | +| Telnyx | 0.1100 | 1100 $ | From a06462637e0f635cf6d7145a38ec68314eedca0f Mon Sep 17 00:00:00 2001 From: byawitz Date: Wed, 29 Mar 2023 01:23:56 -0400 Subject: [PATCH 08/13] Fixing small miss priced rows --- docs/sms-pricing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sms-pricing.md b/docs/sms-pricing.md index 8a734fb6..bd717b3c 100644 --- a/docs/sms-pricing.md +++ b/docs/sms-pricing.md @@ -42,7 +42,7 @@ _In most providers when you're sending SMS to US numbers you must own a US phone | Plivo | 0.0560 | 560 $ | | Infobip | n/a | | | Clickatell | 0.0426 | 426.2 $ | -| Seven | 0.0800 | 81 $ | +| Seven | 0.0810 | 810 $ | | Sinch | n/a | | | Telnyx | 0.0490 | 490 $ | @@ -58,6 +58,6 @@ _In most providers when you're sending SMS to US numbers you must own a US phone | Plivo | 0.101 | 1010 $ | | Infobip | 0.106 | 1060 $ | | Clickatell | 0.13144 | 1314.4 $ | -| Seven | 0.08 | 81 $ | +| Seven | 0.0810 | 810 $ | | Sinch | n/a | | | Telnyx | 0.1100 | 1100 $ | From 2c75453fb86ff522cae19a3fb027321a6b0918cf Mon Sep 17 00:00:00 2001 From: byawitz Date: Wed, 29 Mar 2023 01:35:22 -0400 Subject: [PATCH 09/13] Update documentation link --- src/Utopia/Messaging/Adapters/SMS/Seven.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Seven.php b/src/Utopia/Messaging/Adapters/SMS/Seven.php index beaf0a6f..6bae118f 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Seven.php +++ b/src/Utopia/Messaging/Adapters/SMS/Seven.php @@ -7,7 +7,7 @@ use Utopia\Messaging\Messages\SMS; // Reference Material -// https://developers.sinch.com/docs/sms/api-reference/ +// https://www.seven.io/en/docs/gateway/http-api/sms-dispatch/ class Seven extends SMSAdapter { /** * @param string $apiKey Seven API token From 2b69b48ac2b2b41eaba6bc8d17bc52c178cdae2a Mon Sep 17 00:00:00 2001 From: byawitz Date: Thu, 30 Mar 2023 09:52:57 -0400 Subject: [PATCH 10/13] Update sms pricing to be sorted by price --- docs/sms-pricing.md | 49 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/docs/sms-pricing.md b/docs/sms-pricing.md index bd717b3c..6f86f36b 100644 --- a/docs/sms-pricing.md +++ b/docs/sms-pricing.md @@ -2,11 +2,12 @@ ### In case you wonder which provider will suite you with best price -_This list includes only implemented providers_ +- _The list includes only implemented providers_ +- _The list is sorted by unit price low -> high_ ## SMS Target -_You can add your country with a full pricing table_ +_You can add your country with a full pricing table._ - [United States](#united-states) - [India](#india) @@ -18,46 +19,46 @@ _In most providers when you're sending SMS to US numbers you must own a US phone | Provider | Unit Price | 10K | |------------|------------|-------| -| Twilio | 0.0079 | 79 $ | +| Plivo | 0.0050 | 50 $ | | Telesign | 0.0062 | 62 $ | -| TextMagic | 0.0400 | 400 $ | | Msg91 | 0.0067 | 67 $ | | Vonage | 0.0067 | 67 $ | -| Plivo | 0.0050 | 50 $ | | Infobip | 0.0070 | 70 $ | | Clickatell | 0.0075 | 75 $ | -| Seven | 0.0810 | 810 $ | +| Twilio | 0.0079 | 79 $ | | Sinch | 0.0120 | 120 $ | +| TextMagic | 0.0400 | 400 $ | | Telnyx | 0.0440 | 440 $ | +| Seven | 0.0810 | 810 $ | ## India -| Provider | Unit Price | 10K | -|------------|------------|----------| -| Twilio | 0.0490 | 490 $ | -| Telesign | 0.0485 | 485 $ | -| TextMagic | n/a | | -| Msg91 | 0.0030 | 30 $ | -| Vonage | 0.0449 | 449 $ | -| Plivo | 0.0560 | 560 $ | -| Infobip | n/a | | -| Clickatell | 0.0426 | 426.2 $ | -| Seven | 0.0810 | 810 $ | -| Sinch | n/a | | -| Telnyx | 0.0490 | 490 $ | +| Provider | Unit Price | 10K | +|------------|------------|-------| +| Msg91 | 0.0030 | 30 $ | +| Clickatell | 0.0426 | 426 $ | +| Vonage | 0.0449 | 449 $ | +| Telesign | 0.0485 | 485 $ | +| Telnyx | 0.0490 | 490 $ | +| Twilio | 0.0490 | 490 $ | +| Plivo | 0.0560 | 560 $ | +| Seven | 0.0810 | 810 $ | +| Infobip | n/a | | +| Sinch | n/a | | +| TextMagic | n/a | | ## Israel | Provider | Unit Price | 10K | |------------|------------|----------| -| Twilio | 0.112 | 1120 $ | | Telesign | 0.0768 | 768 $ | -| TextMagic | n/a | | +| Seven | 0.0810 | 810 $ | | Msg91 | 0.0845 | 845 $ | -| Vonage | 0.1019 | 1019 $ | | Plivo | 0.101 | 1010 $ | +| Vonage | 0.1019 | 1019 $ | | Infobip | 0.106 | 1060 $ | +| Telnyx | 0.1100 | 1100 $ | +| Twilio | 0.112 | 1120 $ | | Clickatell | 0.13144 | 1314.4 $ | -| Seven | 0.0810 | 810 $ | | Sinch | n/a | | -| Telnyx | 0.1100 | 1100 $ | +| TextMagic | n/a | | From 43cc0067f5f41afd8d9e6806b36657fefe87c53a Mon Sep 17 00:00:00 2001 From: byawitz Date: Mon, 3 Apr 2023 15:48:17 -0400 Subject: [PATCH 11/13] Formatting & linting --- .../Messaging/Adapters/SMS/Clickatell.php | 76 +++++++++-------- src/Utopia/Messaging/Adapters/SMS/Infobip.php | 85 ++++++++++--------- src/Utopia/Messaging/Adapters/SMS/Plivo.php | 69 ++++++++------- src/Utopia/Messaging/Adapters/SMS/Seven.php | 76 +++++++++-------- src/Utopia/Messaging/Adapters/SMS/Sinch.php | 81 +++++++++--------- 5 files changed, 200 insertions(+), 187 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Clickatell.php b/src/Utopia/Messaging/Adapters/SMS/Clickatell.php index b8edb612..c454137b 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Clickatell.php +++ b/src/Utopia/Messaging/Adapters/SMS/Clickatell.php @@ -1,6 +1,5 @@ request( - method: 'POST', - url: "https://platform.clickatell.com/messages", - headers: [ - 'content-type: application/json', - 'Authorization: ' . $this->apiKey, - ], - body: \json_encode([ - 'content' => $message->getContent(), - 'from' => $message->getFrom(), - 'to' => $message->getTo(), - ]), - ); - } + } + + public function getName(): string + { + return 'Clickatell'; + } + + public function getMaxMessagesPerRequest(): int + { + return 1000; + } + + /** + * {@inheritdoc} + * + * @throws \Exception + */ + protected function process(SMS $message): string + { + return $this->request( + method: 'POST', + url: 'https://platform.clickatell.com/messages', + headers: [ + 'content-type: application/json', + 'Authorization: '.$this->apiKey, + ], + body: \json_encode([ + 'content' => $message->getContent(), + '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 b13e452f..68e8f03a 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Infobip.php +++ b/src/Utopia/Messaging/Adapters/SMS/Infobip.php @@ -1,6 +1,5 @@ ['to' => \ltrim($number, '+')], $message->getTo()); - - return $this->request( - method: 'POST', - url: "https://{$this->apiBaseUrl}/sms/2/text/advanced", - headers: [ - 'Authorization: App ' . $this->apiKey, - 'content-type: application/json', - ], - body: \json_encode([ - 'messages' => [ - 'text' => $message->getContent(), - 'from' => $message->getFrom(), - 'destinations' => $to, - ], - ]), - ); - } + } + + public function getName(): string + { + return 'Infobip'; + } + + public function getMaxMessagesPerRequest(): int + { + return 1000; + } + + /** + * {@inheritdoc} + * + * @throws \Exception + */ + protected function process(SMS $message): string + { + $to = \array_map(fn ($number) => ['to' => \ltrim($number, '+')], $message->getTo()); + + return $this->request( + method: 'POST', + url: "https://{$this->apiBaseUrl}/sms/2/text/advanced", + headers: [ + 'Authorization: App '.$this->apiKey, + 'content-type: application/json', + ], + body: \json_encode([ + 'messages' => [ + 'text' => $message->getContent(), + 'from' => $message->getFrom(), + 'destinations' => $to, + ], + ]), + ); + } } diff --git a/src/Utopia/Messaging/Adapters/SMS/Plivo.php b/src/Utopia/Messaging/Adapters/SMS/Plivo.php index b53c9df2..009dafd6 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Plivo.php +++ b/src/Utopia/Messaging/Adapters/SMS/Plivo.php @@ -1,6 +1,5 @@ request( - method: 'POST', - url: "https://api.plivo.com/v1/Account/{$this->authId}/Message/", - headers: [ - 'Authorization: Basic ' . base64_encode("{$this->authId}:{$this->authToken}"), - ], - body: \http_build_query([ - 'text' => $message->getContent(), - 'src' => $message->getFrom(), - 'dst' => \implode('<', $message->getTo()), - ]), - ); - } + /** + * {@inheritdoc} + * + * @throws \Exception + */ + protected function process(SMS $message): string + { + return $this->request( + method: 'POST', + url: "https://api.plivo.com/v1/Account/{$this->authId}/Message/", + headers: [ + 'Authorization: Basic '.base64_encode("{$this->authId}:{$this->authToken}"), + ], + body: \http_build_query([ + 'text' => $message->getContent(), + 'src' => $message->getFrom(), + 'dst' => \implode('<', $message->getTo()), + ]), + ); + } } diff --git a/src/Utopia/Messaging/Adapters/SMS/Seven.php b/src/Utopia/Messaging/Adapters/SMS/Seven.php index 6bae118f..bdde00a4 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Seven.php +++ b/src/Utopia/Messaging/Adapters/SMS/Seven.php @@ -1,6 +1,5 @@ request( - method: 'POST', - url: "https://gateway.sms77.io/api/sms", - headers: [ - 'Authorization: Basic ' . $this->apiKey, - 'content-type: application/json', - ], - body: \json_encode([ - 'from' => $message->getFrom(), - 'to' => \implode(',', $message->getTo()), - 'text' => $message->getContent(), - ]), - ); - } + } + + public function getName(): string + { + return 'Seven'; + } + + public function getMaxMessagesPerRequest(): int + { + return 1000; + } + + /** + * {@inheritdoc} + * + * @throws \Exception + */ + protected function process(SMS $message): string + { + return $this->request( + method: 'POST', + url: 'https://gateway.sms77.io/api/sms', + headers: [ + 'Authorization: Basic '.$this->apiKey, + 'content-type: application/json', + ], + body: \json_encode([ + '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 57c8eb4c..65f769eb 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Sinch.php +++ b/src/Utopia/Messaging/Adapters/SMS/Sinch.php @@ -1,6 +1,5 @@ \ltrim($number, '+'), $message->getTo()); - - return $this->request( - method: 'POST', - url: "https://sms.api.sinch.com/xms/v1/{$this->servicePlanId}/batches", - headers: [ - 'Authorization: Bearer ' . $this->apiToken, - 'content-type: application/json', - ], - body: \json_encode([ - 'from' => $message->getFrom(), - 'to' => $to, - 'body' => $message->getContent(), - ]), - ); - } + } + + public function getName(): string + { + return 'Sinch'; + } + + public function getMaxMessagesPerRequest(): int + { + return 1000; + } + + /** + * {@inheritdoc} + * + * @throws \Exception + */ + protected function process(SMS $message): string + { + $to = \array_map(fn ($number) => \ltrim($number, '+'), $message->getTo()); + + return $this->request( + method: 'POST', + url: "https://sms.api.sinch.com/xms/v1/{$this->servicePlanId}/batches", + headers: [ + 'Authorization: Bearer '.$this->apiToken, + 'content-type: application/json', + ], + body: \json_encode([ + 'from' => $message->getFrom(), + 'to' => $to, + 'body' => $message->getContent(), + ]), + ); + } } From 0f4033a528b28c821e9737f3b5d932101a41bb17 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz Date: Tue, 30 May 2023 20:29:41 -0400 Subject: [PATCH 12/13] [Correct] Formatting & linting --- src/Utopia/Messaging/Adapters/SMS/Clickatell.php | 4 ++-- src/Utopia/Messaging/Adapters/SMS/Infobip.php | 8 ++++---- src/Utopia/Messaging/Adapters/SMS/Plivo.php | 10 +++++----- src/Utopia/Messaging/Adapters/SMS/Seven.php | 4 ++-- src/Utopia/Messaging/Adapters/SMS/Sinch.php | 8 ++++---- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Clickatell.php b/src/Utopia/Messaging/Adapters/SMS/Clickatell.php index c454137b..6b3ee1ee 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Clickatell.php +++ b/src/Utopia/Messaging/Adapters/SMS/Clickatell.php @@ -13,8 +13,8 @@ class Clickatell extends SMSAdapter * @param string $apiKey Clickatell API Key */ public function __construct( - private string $apiKey, - ) { + private string $apiKey, + ) { } public function getName(): string diff --git a/src/Utopia/Messaging/Adapters/SMS/Infobip.php b/src/Utopia/Messaging/Adapters/SMS/Infobip.php index 68e8f03a..9d1a584b 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Infobip.php +++ b/src/Utopia/Messaging/Adapters/SMS/Infobip.php @@ -11,12 +11,12 @@ class Infobip extends SMSAdapter { /** * @param string $apiBaseUrl Infobip API Base Url - * @param string $apiKey Infobip API Key + * @param string $apiKey Infobip API Key */ public function __construct( - private string $apiBaseUrl, - private string $apiKey - ) { + private string $apiBaseUrl, + private string $apiKey + ) { } public function getName(): string diff --git a/src/Utopia/Messaging/Adapters/SMS/Plivo.php b/src/Utopia/Messaging/Adapters/SMS/Plivo.php index 009dafd6..4f923fdf 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Plivo.php +++ b/src/Utopia/Messaging/Adapters/SMS/Plivo.php @@ -10,13 +10,13 @@ class Plivo extends SMSAdapter { /** - * @param string $authId Plivo Auth ID + * @param string $authId Plivo Auth ID * @param string $authToken Plivo Auth Token */ public function __construct( - private string $authId, - private string $authToken - ) { + private string $authId, + private string $authToken + ) { } public function getName(): string @@ -44,7 +44,7 @@ protected function process(SMS $message): string ], body: \http_build_query([ 'text' => $message->getContent(), - 'src' => $message->getFrom(), + 'src' => $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 bdde00a4..383bdf94 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Seven.php +++ b/src/Utopia/Messaging/Adapters/SMS/Seven.php @@ -13,8 +13,8 @@ class Seven extends SMSAdapter * @param string $apiKey Seven API token */ public function __construct( - private string $apiKey - ) { + private string $apiKey + ) { } public function getName(): string diff --git a/src/Utopia/Messaging/Adapters/SMS/Sinch.php b/src/Utopia/Messaging/Adapters/SMS/Sinch.php index 65f769eb..ac0dc0b3 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Sinch.php +++ b/src/Utopia/Messaging/Adapters/SMS/Sinch.php @@ -11,12 +11,12 @@ class Sinch extends SMSAdapter { /** * @param string $servicePlanId Sinch Service plan ID - * @param string $apiToken Sinch API token + * @param string $apiToken Sinch API token */ public function __construct( - private string $servicePlanId, - private string $apiToken - ) { + private string $servicePlanId, + private string $apiToken + ) { } public function getName(): string From 0aef44f2bf934a311fd810a5a9c094b39a59f466 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz Date: Tue, 30 May 2023 21:03:38 -0400 Subject: [PATCH 13/13] Verify max messages --- src/Utopia/Messaging/Adapters/SMS/Clickatell.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Clickatell.php b/src/Utopia/Messaging/Adapters/SMS/Clickatell.php index 6b3ee1ee..4e302b32 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Clickatell.php +++ b/src/Utopia/Messaging/Adapters/SMS/Clickatell.php @@ -24,7 +24,7 @@ public function getName(): string public function getMaxMessagesPerRequest(): int { - return 1000; + return 500; } /**