From 2c0ea108130e67e9e2808afc1fbbc6d8de575ff5 Mon Sep 17 00:00:00 2001 From: Vividh Pandey Date: Tue, 17 Oct 2023 22:19:39 +0530 Subject: [PATCH 1/2] Feat: Added CM SMS Adapter Signed-off-by: Vividh Pandey --- .github/workflows/tests.yml | 3 ++ README.md | 1 + docker-compose.yml | 3 ++ src/Utopia/Messaging/Adapters/SMS/CM.php | 49 ++++++++++++++++++++++++ tests/e2e/SMS/CM.php | 35 +++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 src/Utopia/Messaging/Adapters/SMS/CM.php create mode 100644 tests/e2e/SMS/CM.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 552b207d..553ffe74 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,6 +40,9 @@ jobs: VONAGE_API_SECRET: ${{ secrets.VONAGE_API_SECRET }} VONAGE_TO: ${{ secrets.VONAGE_TO }} VONAGE_FROM: ${{ secrets.VONAGE_FROM }} + CM_API_KEY: ${{ secrets.CM_API_KEY }} + CM_TO: ${{ secrets.CM_TO }} + CM_FROM: ${{ secrets.CM_FROM }} run: | docker compose up -d --build sleep 5 diff --git a/README.md b/README.md index d745b630..75330ef3 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ $messaging->send($message); - [x] [Sinch](https://www.sinch.com/) - [x] [Seven](https://www.seven.io/) - [ ] [SmsGlobal](https://www.smsglobal.com/) +- [ ] [CM](https://www.cm.com/) ### Push - [x] [FCM](https://firebase.google.com/docs/cloud-messaging) diff --git a/docker-compose.yml b/docker-compose.yml index 80d626d9..97bfa252 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,6 +29,9 @@ services: - VONAGE_API_SECRET - VONAGE_TO - VONAGE_FROM + - CM_API_KEY + - CM_TO + - CM_FROM build: context: . volumes: diff --git a/src/Utopia/Messaging/Adapters/SMS/CM.php b/src/Utopia/Messaging/Adapters/SMS/CM.php new file mode 100644 index 00000000..f87a9040 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/SMS/CM.php @@ -0,0 +1,49 @@ +request( + method: 'POST', + url: 'https://api.cmtelecom.com/v1.0/message', + headers: [ + 'Content-Type: application/json', + 'Authorization: Bearer ' . $this->apiKey, + ], + body: json_encode([ + 'from' => $message->getFrom(), + 'to' => $message->getTo()[0], + 'body' => $message->getContent(), + ]), + ); + } +} \ No newline at end of file diff --git a/tests/e2e/SMS/CM.php b/tests/e2e/SMS/CM.php new file mode 100644 index 00000000..454cfb92 --- /dev/null +++ b/tests/e2e/SMS/CM.php @@ -0,0 +1,35 @@ +send($message); + $result = \json_decode($response, true); + + $this->assertArrayNotHasKey('errors', $result); + $this->assertArrayHasKey('message_id', $result); + $this->assertArrayHasKey('message', $result); + $this->assertArrayHasKey('balance', $result); + } +} \ No newline at end of file From c768543e42f992f489eb469454dfac633179482a Mon Sep 17 00:00:00 2001 From: Vividh Pandey Date: Thu, 16 Nov 2023 02:02:09 +0530 Subject: [PATCH 2/2] Fixed PSR12 Linting Signed-off-by: Vividh Pandey --- src/Utopia/Messaging/Adapters/SMS/CM.php | 6 +++--- tests/e2e/SMS/CM.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/CM.php b/src/Utopia/Messaging/Adapters/SMS/CM.php index f87a9040..2c606a25 100644 --- a/src/Utopia/Messaging/Adapters/SMS/CM.php +++ b/src/Utopia/Messaging/Adapters/SMS/CM.php @@ -8,7 +8,7 @@ class CM extends SMSAdapter { /** - * @param string $apiKey CM API Key + * @param string $apiKey CM API Key */ public function __construct( private string $apiKey @@ -37,7 +37,7 @@ protected function process(SMS $message): string url: 'https://api.cmtelecom.com/v1.0/message', headers: [ 'Content-Type: application/json', - 'Authorization: Bearer ' . $this->apiKey, + 'Authorization: Bearer '.$this->apiKey, ], body: json_encode([ 'from' => $message->getFrom(), @@ -46,4 +46,4 @@ protected function process(SMS $message): string ]), ); } -} \ No newline at end of file +} diff --git a/tests/e2e/SMS/CM.php b/tests/e2e/SMS/CM.php index 454cfb92..ed36025f 100644 --- a/tests/e2e/SMS/CM.php +++ b/tests/e2e/SMS/CM.php @@ -32,4 +32,4 @@ public function testSendSMS() $this->assertArrayHasKey('message', $result); $this->assertArrayHasKey('balance', $result); } -} \ No newline at end of file +}