Skip to content
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 }}
CM_API_KEY: ${{ secrets.CM_API_KEY }}
CM_TO: ${{ secrets.CM_TO }}
CM_FROM: ${{ secrets.CM_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/)
- [ ] [CM](https://www.cm.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
- CM_API_KEY
- CM_TO
- CM_FROM
build:
context: .
volumes:
Expand Down
49 changes: 49 additions & 0 deletions src/Utopia/Messaging/Adapters/SMS/CM.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Utopia\Messaging\Adapters\SMS;

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

class CM extends SMSAdapter
{
/**
* @param string $apiKey CM API Key
*/
public function __construct(
private string $apiKey
) {
}

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

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

/**
* {@inheritdoc}
*
* @throws \Exception
*/
protected function process(SMS $message): string
{
return $this->request(
method: 'POST',
url: 'https://api.cmtelecom.com/v1.0/message',
headers: [
'Content-Type: application/json',
'Authorization: Bearer '.$this->apiKey,
],
body: json_encode([
'from' => $message->getFrom(),
'to' => $message->getTo()[0],
'body' => $message->getContent(),
]),
);
}
}
35 changes: 35 additions & 0 deletions tests/e2e/SMS/CM.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Tests\E2E;

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

class CMest extends Base
{
/**
* @throws \Exception
*/
public function testSendSMS()
{
$apiKey = getenv('CM_API_KEY');

$to = [getenv('CM_TO')];
$from = getenv('CM_FROM');

$sender = new CM($apiKey);
$message = new SMS(
to: $to,
content: 'Test Content',
from: $from
);

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

$this->assertArrayNotHasKey('errors', $result);
$this->assertArrayHasKey('message_id', $result);
$this->assertArrayHasKey('message', $result);
$this->assertArrayHasKey('balance', $result);
}
}