Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SMSApi Messaging Adapter #44

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ jobs:
VONAGE_API_SECRET: ${{ secrets.VONAGE_API_SECRET }}
VONAGE_TO: ${{ secrets.VONAGE_TO }}
VONAGE_FROM: ${{ secrets.VONAGE_FROM }}
SMSAPI_AUTH_TOKEN: ${{ secrets.SMSAPI_AUTH_TOKEN }}
SMSAPI_TO: ${{ secrets.SMSAPI_TO }}
SMSAPI_FROM: ${{ secrets.SMSAPI_FROM }}
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] [SMSApi](https://www.smsapi.com/)

### Push
- [x] [FCM](https://firebase.google.com/docs/cloud-messaging)
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ services:
- VONAGE_API_SECRET
- VONAGE_TO
- VONAGE_FROM
- SMSAPI_AUTH_TOKEN
- SMSAPI_TO
- SMSAPI_FROM
build:
context: .
volumes:
Expand Down
51 changes: 51 additions & 0 deletions src/Utopia/Messaging/Adapters/SMS/SMSApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Utopia\Messaging\Adapters\SMS;

use Utopia\Messaging\Adapters\SMS as SMSAdapter;
use Utopia\Messaging\Messages\SMS;

// Reference Material
// https://www.smsapi.com/docs/#2-single-sms
class SMSApi extends SMSAdapter
{
/**
* @param string $apiToken SMSApi token
*/
public function __construct(
private string $apiToken
) {
}

public function getName(): string
{
return 'SMSApi';
}

public function getMaxMessagesPerRequest(): int
{
return 1000;
}

/**
* {@inheritdoc}
*
* @throws \Exception
*/
protected function process(SMS $message): string
{
return $this->request(
method: 'POST',
url: 'https://api.smsapi.com/sms.do',
headers: [
'Authorization: Bearer '.$this->apiToken,
'content-type: application/json',
],
body: \json_encode([
'from' => $message->getFrom(), //sendername made in https://ssl.smsapi.com/sms_settings/sendernames
'to' => $message->getTo()[0], //destination number
'message' => $message->getContent(), //message content
]),
);
}
}
30 changes: 30 additions & 0 deletions tests/e2e/SMS/SMSApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Tests\E2E;

use Utopia\Messaging\Adapters\SMS\SMSApi;
use Utopia\Messaging\Messages\SMS;

class SMSApiTest extends Base
{
/**
* @throws \Exception
*/
public function testSendSMS()
{
// $sender = new SMSApi(getenv('SMSAPI_AUTH_TOKEN'));

// $message = new SMS(
// to: [getenv('SMSAPI_TO')],
// content: 'Test Content',
// from: getenv('SMSAPI_FROM')
// );

// $response = $sender->send($message);
// $result = \json_decode($response, true);

// $this->assertEquals('success', $result['type']);

$this->markTestSkipped('SMSApi currenlty not available in INDIA.');
}
}
Loading