From 0be2c82efd5f111c5f6a930951af841c86418d74 Mon Sep 17 00:00:00 2001 From: deepshekhardas Date: Thu, 23 Jul 2026 12:30:16 +0530 Subject: [PATCH] fix: rebase PR #99 - SMSGateApp SMS adapter Original by @capcom6. Fixed: - Added parent::__construct() call - Made properties private readonly - Moved apiEndpoint default to constructor parameter default - Aligned with v2.0.0 conventions --- .../Messaging/Adapter/SMS/SMSGateApp.php | 73 +++++++++++++++++++ .../Messaging/Adapter/SMS/SMSGateAppTest.php | 34 +++++++++ 2 files changed, 107 insertions(+) create mode 100644 src/Utopia/Messaging/Adapter/SMS/SMSGateApp.php create mode 100644 tests/Messaging/Adapter/SMS/SMSGateAppTest.php diff --git a/src/Utopia/Messaging/Adapter/SMS/SMSGateApp.php b/src/Utopia/Messaging/Adapter/SMS/SMSGateApp.php new file mode 100644 index 00000000..637e8e33 --- /dev/null +++ b/src/Utopia/Messaging/Adapter/SMS/SMSGateApp.php @@ -0,0 +1,73 @@ +getType()); + + $body = [ + 'textMessage' => [ + 'text' => $message->getContent(), + ], + 'phoneNumbers' => $message->getTo(), + ]; + + $result = $this->request( + method: 'POST', + url: $this->apiEndpoint . '/messages?skipPhoneValidation=true', + headers: [ + 'Content-Type: application/json', + 'Authorization: Basic ' . base64_encode("{$this->apiUsername}:{$this->apiPassword}"), + ], + body: $body, + ); + + if ($result['statusCode'] === 202) { + $success = 0; + foreach ($result['response']['recipients'] as $recipient) { + $response->addResult($recipient['phoneNumber'], $recipient['error'] ?? ''); + + if ($recipient['state'] !== 'Failed') { + $success++; + } + } + + $response->setDeliveredTo($success); + } else { + $errorMessage = $result['response']['message'] ?? 'Unknown error'; + foreach ($message->getTo() as $recipient) { + $response->addResult($recipient, $errorMessage); + } + } + + return $response->toArray(); + } +} diff --git a/tests/Messaging/Adapter/SMS/SMSGateAppTest.php b/tests/Messaging/Adapter/SMS/SMSGateAppTest.php new file mode 100644 index 00000000..b49d106a --- /dev/null +++ b/tests/Messaging/Adapter/SMS/SMSGateAppTest.php @@ -0,0 +1,34 @@ +markTestSkipped('SMSGateApp credentials not configured'); + } + + $endpoint = \getenv('SMSGATEAPP_ENDPOINT') ?: null; + + $sender = new SMSGateApp($username, $password, $endpoint); + + $message = new SMS( + to: [$to], + content: 'Test content from SMSGateApp' + ); + + $response = $sender->send($message); + + $this->assertResponse($response); + } +}