diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 552b207d..db516aa3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 80d626d9..9fdb4926 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,6 +29,9 @@ services: - VONAGE_API_SECRET - VONAGE_TO - VONAGE_FROM + - BANDWIDTH_API_KEY + - BANDWIDTH_API_SECRET + - BANDWIDTH_API_URL build: context: . volumes: diff --git a/src/Utopia/Messaging/Adapters/SMS/Bandwidth.php b/src/Utopia/Messaging/Adapters/SMS/Bandwidth.php new file mode 100644 index 00000000..d8e04019 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/SMS/Bandwidth.php @@ -0,0 +1,47 @@ +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(), + ]) + ); + } +} diff --git a/tests/e2e/SMS/BandwidthTest.php b/tests/e2e/SMS/BandwidthTest.php new file mode 100644 index 00000000..12f812fe --- /dev/null +++ b/tests/e2e/SMS/BandwidthTest.php @@ -0,0 +1,42 @@ +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)); + } +}