From b9c56c053645b569804f9764b9ec68e0a8005f28 Mon Sep 17 00:00:00 2001 From: deepshekhardas Date: Thu, 23 Jul 2026 12:29:36 +0530 Subject: [PATCH] fix: rebase PR #104 - Taqnyat SMS adapter Original by @ali-alharthi. Fixed: - Added parent::__construct() call - Made properties private readonly - Aligned with v2.0.0 conventions --- src/Utopia/Messaging/Adapter/SMS/Taqnyat.php | 74 ++++++++++++++++++++ tests/Messaging/Adapter/SMS/TaqnyatTest.php | 35 +++++++++ 2 files changed, 109 insertions(+) create mode 100644 src/Utopia/Messaging/Adapter/SMS/Taqnyat.php create mode 100644 tests/Messaging/Adapter/SMS/TaqnyatTest.php diff --git a/src/Utopia/Messaging/Adapter/SMS/Taqnyat.php b/src/Utopia/Messaging/Adapter/SMS/Taqnyat.php new file mode 100644 index 00000000..2e389f0c --- /dev/null +++ b/src/Utopia/Messaging/Adapter/SMS/Taqnyat.php @@ -0,0 +1,74 @@ + \ltrim($to, '+'), + $message->getTo() + ); + + $response = new Response($this->getType()); + + $result = $this->request( + method: 'POST', + url: 'https://api.taqnyat.sa/v1/messages', + headers: [ + 'Content-Type: application/json', + 'Authorization: Bearer ' . $this->apiKey, + ], + body: [ + 'sender' => $this->senderId, + 'recipients' => $to, + 'body' => $message->getContent(), + ], + ); + + if ($result['statusCode'] >= 200 && $result['statusCode'] < 300) { + $response->setDeliveredTo(\count($message->getTo())); + foreach ($message->getTo() as $to) { + $response->addResult($to); + } + } else { + foreach ($message->getTo() as $to) { + if (!\is_null($result['response']['message'] ?? null)) { + $response->addResult($to, $result['response']['message']); + } else { + $response->addResult($to, 'Unknown error'); + } + } + } + + return $response->toArray(); + } +} diff --git a/tests/Messaging/Adapter/SMS/TaqnyatTest.php b/tests/Messaging/Adapter/SMS/TaqnyatTest.php new file mode 100644 index 00000000..526e257c --- /dev/null +++ b/tests/Messaging/Adapter/SMS/TaqnyatTest.php @@ -0,0 +1,35 @@ +markTestSkipped('TAQNYAT credentials not configured'); + } + + $sender = new Taqnyat( + apiKey: $apiKey, + senderId: $senderId + ); + + $message = new SMS( + to: [$to], + content: 'Test Content', + ); + + $response = $sender->send($message); + + $this->assertResponse($response); + } +}