From d0297891999c308d94554c09d7a9dfd0a0fa3b21 Mon Sep 17 00:00:00 2001 From: nooras Date: Sat, 7 Oct 2023 20:17:47 +0530 Subject: [PATCH 1/2] Added SMSApi Messaging Adapter --- .github/workflows/tests.yml | 3 ++ README.md | 1 + docker-compose.yml | 3 ++ src/Utopia/Messaging/Adapters/SMS/SMSApi.php | 51 ++++++++++++++++++++ tests/e2e/SMS/SMSApiTest.php | 30 ++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 src/Utopia/Messaging/Adapters/SMS/SMSApi.php create mode 100644 tests/e2e/SMS/SMSApiTest.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 552b207d..144a8ed4 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 }} + SMSAPI_AUTH_TOKEN: ${{ secrets.SMSAPI_AUTH_TOKEN }} + SMSAPI_TO: ${{ secrets.SMSAPI_TO }} + SMSAPI_FROM: ${{ secrets.SMSAPI_FROM }} run: | docker compose up -d --build sleep 5 diff --git a/README.md b/README.md index d745b630..be172361 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/) +- [x] [SMSApi](https://www.smsapi.com/) ### Push - [x] [FCM](https://firebase.google.com/docs/cloud-messaging) diff --git a/docker-compose.yml b/docker-compose.yml index 80d626d9..35aebcbc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,6 +29,9 @@ services: - VONAGE_API_SECRET - VONAGE_TO - VONAGE_FROM + - SMSAPI_AUTH_TOKEN + - SMSAPI_TO + - SMSAPI_FROM build: context: . volumes: diff --git a/src/Utopia/Messaging/Adapters/SMS/SMSApi.php b/src/Utopia/Messaging/Adapters/SMS/SMSApi.php new file mode 100644 index 00000000..91d9a77a --- /dev/null +++ b/src/Utopia/Messaging/Adapters/SMS/SMSApi.php @@ -0,0 +1,51 @@ +request( + method: 'POST', + url: "https://api.smsapi.com/sms.do", + headers: [ + 'Authorization: Bearer '.$this->apiToken, + 'content-type: application/json', + ], + body: \json_encode([ + 'from' => $message->getFrom(), //sendername made in https://ssl.smsapi.com/sms_settings/sendernames + 'to' => $message->getTo()[0], //destination number + 'message' => $message->getContent(), //message content + ]), + ); + } +} diff --git a/tests/e2e/SMS/SMSApiTest.php b/tests/e2e/SMS/SMSApiTest.php new file mode 100644 index 00000000..e069eb2b --- /dev/null +++ b/tests/e2e/SMS/SMSApiTest.php @@ -0,0 +1,30 @@ +send($message); + // $result = \json_decode($response, true); + + // $this->assertEquals('success', $result['type']); + + $this->markTestSkipped('SMSApi currenlty not available in INDIA.'); + } +} From 839422cf2b2a00b446f4cbf16b8b44dbd787d477 Mon Sep 17 00:00:00 2001 From: nooras Date: Thu, 26 Oct 2023 18:53:37 +0530 Subject: [PATCH 2/2] Double quotes changes to single quotes --- src/Utopia/Messaging/Adapters/SMS/SMSApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/SMSApi.php b/src/Utopia/Messaging/Adapters/SMS/SMSApi.php index 91d9a77a..f4a799c1 100644 --- a/src/Utopia/Messaging/Adapters/SMS/SMSApi.php +++ b/src/Utopia/Messaging/Adapters/SMS/SMSApi.php @@ -36,7 +36,7 @@ protected function process(SMS $message): string { return $this->request( method: 'POST', - url: "https://api.smsapi.com/sms.do", + url: 'https://api.smsapi.com/sms.do', headers: [ 'Authorization: Bearer '.$this->apiToken, 'content-type: application/json',