Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ DISCORD_WEBHOOK_TOKEN=
FAST2SMS_API_KEY=
FAST2SMS_SENDER_ID=
FAST2SMS_MESSAGE_ID=
FAST2SMS_TO=
FAST2SMS_TO=
INFORU_API_TOKEN=
INFORU_SENDER_ID=
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 81 additions & 0 deletions src/Utopia/Messaging/Adapter/SMS/Inforu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Utopia\Messaging\Adapter\SMS;

use Utopia\Messaging\Adapter\SMS as SMSAdapter;
use Utopia\Messaging\Messages\SMS as SMSMessage;
use Utopia\Messaging\Response;

// Reference Material
// https://apidoc.inforu.co.il/#d7b3f69d-7422-44b4-b7d1-0959f8a08881
class Inforu extends SMSAdapter
{
protected const NAME = 'Inforu';

/**
* @param string $apiToken Inforu API token
* @param string $senderId Sender ID
*/
public function __construct(
private string $senderId,
private string $apiToken,
) {
}

public function getName(): string
{
return static::NAME;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why static? Why not self::name ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2025-05-12 at 9 23 43 PM

thats what we do for Fast2SMS and others

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self::NAME will return the base class value even in child classes, better to use static in most cases

}

public function getMaxMessagesPerRequest(): int
{
return 100; // Setting a conservative limit, adjust if needed
}

/**
* {@inheritdoc}
*
* @throws \Exception
*/
protected function process(SMSMessage $message): array
{
$response = new Response($this->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();
}
}
30 changes: 30 additions & 0 deletions tests/Messaging/Adapter/SMS/InforuTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Utopia\Tests\Adapter\SMS;

use Utopia\Messaging\Adapter\SMS\Inforu;
use Utopia\Messaging\Messages\SMS;
use Utopia\Tests\Adapter\Base;

class InforuTest extends Base
{
/**
* @throws \Exception
*/
public function testSendSMS(): void
{
$sender = new Inforu(
senderId: \getenv('INFORU_SENDER_ID'),
apiToken: \getenv('INFORU_API_TOKEN'),
);

$message = new SMS(
to: ['0541234567'],
content: 'Test Content',
);

$response = $sender->send($message);

$this->assertResponse($response);
}
}
Loading