Skip to content
Closed
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 }}
BANDWIDTH_API_KEY: ${{ secrets.BANDWIDTH_API_KEY }}
BANDWIDTH_API_SECRET: ${{ secrets.BANDWIDTH_API_SECRET }}
BANDWIDTH_API_URL: ${{ secrets.BANDWIDTH_API_URL }}
run: |
docker compose up -d --build
sleep 5
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
- BANDWIDTH_API_KEY
- BANDWIDTH_API_SECRET
- BANDWIDTH_API_URL
build:
context: .
volumes:
Expand Down
47 changes: 47 additions & 0 deletions src/Utopia/Messaging/Adapters/SMS/Bandwidth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Utopia\Messaging\Adapters\SMS;

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

class Bandwidth extends SMSAdapter
{
private $apiKey;
private $apiSecret;
private $apiUrl;

public function __construct(private string $apiKey, private string $apiSecret, private string $apiUrl)
{
$this->apiKey = $apiKey;
$this->apiSecret = $apiSecret;
$this->apiUrl = $apiUrl;
}

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

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

protected function process(SMS $message): string
{
return $this->request(
method: 'POST',
url: $this->apiUrl,
headers: [
'Content-Type: application/json',
'Authorization: Basic ' . base64_encode($this->apiKey . ':' . $this->apiSecret),
],
body: json_encode([
'to' => $message->getTo(),
'from' => $message->getFrom(),
'text' => $message->getBody(),
])
);
}
}
42 changes: 42 additions & 0 deletions tests/e2e/SMS/BandwidthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Tests\E2E;

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

class BandwidthTest extends TestCase
{
/**
* @throws \Exception
*/
public function testSendSMS()
{
$apiKey = getenv('BANDWIDTH_API_KEY');
$apiSecret = getenv('BANDWIDTH_API_SECRET');
$apiUrl = getenv('BANDWIDTH_API_URL');
$bandwidth = new Bandwidth($this->apiKey, $this->apiSecret, $this->apiUrl);
$this->assertEquals('Bandwidth', $bandwidth->getName());
}

public function testGetMaxMessagesPerRequest()
{
$bandwidth = new Bandwidth($this->apiKey, $this->apiSecret, $this->apiUrl);
$this->assertEquals(1000, $bandwidth->getMaxMessagesPerRequest());
}

public function testProcess()
{
$bandwidth = new Bandwidth($this->apiKey, $this->apiSecret, $this->apiUrl);

$sms = new SMS();
$sms->setTo('recipient_number');
$sms->setFrom('sender_number');
$sms->setBody('Test SMS');

// Mock the request method to avoid actual HTTP requests
$this->setOutputCallback(function () {});
$this->expectOutputString('{"status":"success"}');
$this->assertEquals('{"status":"success"}', $bandwidth->process($sms));
}
}