diff --git a/.env.dev b/.env.dev index 36923f8..50d4c55 100644 --- a/.env.dev +++ b/.env.dev @@ -32,4 +32,6 @@ DISCORD_WEBHOOK_TOKEN= FAST2SMS_API_KEY= FAST2SMS_SENDER_ID= FAST2SMS_MESSAGE_ID= -FAST2SMS_TO= \ No newline at end of file +FAST2SMS_TO= +INFORU_API_TOKEN= +INFORU_SENDER_ID= diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9df4bf4..9e16686 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,6 +49,8 @@ jobs: FAST2SMS_SENDER_ID: ${{ secrets.FAST2SMS_SENDER_ID }} FAST2SMS_MESSAGE_ID: ${{ secrets.FAST2SMS_MESSAGE_ID }} FAST2SMS_TO: ${{ secrets.FAST2SMS_TO }} + INFORU_API_TOKEN: ${{ secrets.INFORU_API_TOKEN }} + INFORU_SENDER_ID: ${{ secrets.INFORU_SENDER_ID }} run: | docker compose up -d --build sleep 5 diff --git a/README.md b/README.md index def239e..110842b 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] [Inforu](https://www.inforu.co.il/) ### Push - [x] [FCM](https://firebase.google.com/docs/cloud-messaging) diff --git a/docker-compose.yml b/docker-compose.yml index 1756221..fc7b7cc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -42,6 +42,8 @@ services: - FAST2SMS_SENDER_ID - FAST2SMS_MESSAGE_ID - FAST2SMS_TO + - INFORU_API_TOKEN + - INFORU_SENDER_ID maildev: image: appwrite/mailcatcher:1.0.0 diff --git a/src/Utopia/Messaging/Adapter/SMS/Inforu.php b/src/Utopia/Messaging/Adapter/SMS/Inforu.php new file mode 100644 index 0000000..54b8dcc --- /dev/null +++ b/src/Utopia/Messaging/Adapter/SMS/Inforu.php @@ -0,0 +1,81 @@ +getType()); + + $recipients = array_map( + fn ($number) => ['Phone' => ltrim($number, '+')], + $message->getTo() + ); + + $result = $this->request( + method: 'POST', + url: 'https://capi.inforu.co.il/api/v2/SMS/SendSms', + headers: [ + 'Content-Type: application/json', + 'Authorization: Basic ' . $this->apiToken, + ], + body: [ + 'Data' => [ + 'Message' => $message->getContent(), + 'Recipients' => $recipients, + 'Settings' => [ + 'Sender' => $this->senderId, + ], + ], + ], + ); + + if ($result['statusCode'] === 200 && ($result['response']['StatusId'] ?? 0) === 1) { + $response->setDeliveredTo(count($message->getTo())); + foreach ($message->getTo() as $to) { + $response->addResult($to); + } + } else { + $errorMessage = $result['response']['StatusDescription'] ?? 'Unknown error'; + foreach ($message->getTo() as $to) { + $response->addResult($to, $errorMessage); + } + } + + return $response->toArray(); + } +} diff --git a/tests/Messaging/Adapter/SMS/InforuTest.php b/tests/Messaging/Adapter/SMS/InforuTest.php new file mode 100644 index 0000000..206cbde --- /dev/null +++ b/tests/Messaging/Adapter/SMS/InforuTest.php @@ -0,0 +1,30 @@ +send($message); + + $this->assertResponse($response); + } +}