From d77ce037e276cbca8c262fdacafcfc3697ba5735 Mon Sep 17 00:00:00 2001 From: deepshekhardas Date: Thu, 23 Jul 2026 12:31:04 +0530 Subject: [PATCH] fix: rebase PR #84 - SmsGatewayHub SMS adapter Original by @kevinjosephjohn. Fixed: - Added parent::__construct() call - Made properties private readonly - Removed error_log debugging calls - Fixed test to use env vars with skippable check - Aligned with v2.0.0 conventions --- .../Messaging/Adapter/SMS/SmsGatewayHub.php | 77 +++++++++++++++++++ .../Adapter/SMS/SmsGatewayHubTest.php | 41 ++++++++++ 2 files changed, 118 insertions(+) create mode 100644 src/Utopia/Messaging/Adapter/SMS/SmsGatewayHub.php create mode 100644 tests/Messaging/Adapter/SMS/SmsGatewayHubTest.php diff --git a/src/Utopia/Messaging/Adapter/SMS/SmsGatewayHub.php b/src/Utopia/Messaging/Adapter/SMS/SmsGatewayHub.php new file mode 100644 index 00000000..67d168da --- /dev/null +++ b/src/Utopia/Messaging/Adapter/SMS/SmsGatewayHub.php @@ -0,0 +1,77 @@ +getTo() as $recipient) { + $recipients[] = \ltrim($recipient, '+'); + } + + $response = new Response($this->getType()); + + $queryParams = \http_build_query([ + 'apiKey' => $this->apiKey, + 'senderid' => $this->senderId, + 'channel' => 'Trans', + 'DCS' => '0', + 'flashsms' => '0', + 'number' => \implode(',', $recipients), + 'text' => $message->getContent(), + 'route' => $this->route, + 'DLTTemplateId' => $this->dltTemplateId, + 'PEID' => $this->peId, + ]); + + $url = 'https://login.smsgatewayhub.com/api/mt/SendSMS?' . $queryParams; + $result = $this->request( + 'GET', + $url, + [ + 'Content-Type: application/json', + ] + ); + + if ($result['statusCode'] === 200) { + $response->setDeliveredTo(\count($message->getTo())); + foreach ($message->getTo() as $to) { + $response->addResult($to); + } + } else { + foreach ($message->getTo() as $to) { + $response->addResult($to, 'Unknown error'); + } + } + + return $response->toArray(); + } +} diff --git a/tests/Messaging/Adapter/SMS/SmsGatewayHubTest.php b/tests/Messaging/Adapter/SMS/SmsGatewayHubTest.php new file mode 100644 index 00000000..e0061271 --- /dev/null +++ b/tests/Messaging/Adapter/SMS/SmsGatewayHubTest.php @@ -0,0 +1,41 @@ +markTestSkipped('SMSGatewayHub credentials not configured'); + } + + $sender = new SmsGatewayHub( + apiKey: $apiKey, + senderId: $senderId, + route: $route, + dltTemplateId: $dltTemplateId, + peId: $peId, + ); + + $message = new SMS( + to: [$to], + content: 'Your login OTP is 789456.', + ); + + $response = $sender->send($message); + + $this->assertResponse($response); + } +}