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 BulkSMS Messaging adapter #48

Closed
wants to merge 1 commit into from
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
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] [BulkSMS](https://www.bulksms.com/)

### Push
- [x] [FCM](https://firebase.google.com/docs/cloud-messaging)
Expand Down
53 changes: 53 additions & 0 deletions src/Utopia/Messaging/Adapters/SMS/BulkSMS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Utopia\Messaging\Adapters\SMS;

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

// Reference Material
// https://www.bulksms.com/developer/json/v1/#tag/Message
class BulkSMS extends SMSAdapter
{
/**
* @param string $username BulkSMS Username
* @param string $password BulkSMS Password
*/
public function __construct(
private string $username,
private string $password
) {
}

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

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

/**
* {@inheritdoc}
*
* @throws \Exception
*/
protected function process(SMS $message): string
{
return $this->request(
method: 'POST',
url: "https://api.bulksms.com/v1/messages?auto-unicode=true&longMessageMaxParts=30",
headers: [
'content-type: application/json',
'Authorization: Basic '.base64_encode("{$this->username}:{$this->password}")
],
body: \json_encode([
'from' => $message->getFrom(),
'to' => $message->getTo(),
'body' => $message->getContent()
]),
);
}
}
14 changes: 14 additions & 0 deletions tests/e2e/SMS/BulkSMSTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tests\E2E;

class BulkSMSTest extends Base
{
/**
* @throws \Exception
*/
public function testSendSMS()
{
$this->markTestSkipped('Bulksms requires you to create an account in order to enable bulk SMS');
}
}