diff --git a/src/Utopia/Messaging/Adapter/SMS/SmsRu.php b/src/Utopia/Messaging/Adapter/SMS/SmsRu.php new file mode 100644 index 0000000..c33b30d --- /dev/null +++ b/src/Utopia/Messaging/Adapter/SMS/SmsRu.php @@ -0,0 +1,82 @@ + \ltrim($to, '+'), + $message->getTo() + ); + + $response = new Response($this->getType()); + $result = $this->request( + method: 'POST', + url: 'https://rest.textmagic.com/api/v2/messages', + headers: [ + 'Content-Type: application/x-www-form-urlencoded', + 'X-TM-Username: ' . $this->username, + 'X-TM-Key: '. $this->apiKey, + ], + body: [ + 'text' => $message->getContent(), + 'from' => \ltrim($this->from ?? $message->getFrom(), '+'), + 'phones' => \implode(',', $to), + ], + ); + + 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(); + } +}