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 aws sns adapter #56

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
TWILIO_FROM: ${{ secrets.TWILIO_FROM }}
TELNYX_API_KEY: ${{ secrets.TELNYX_API_KEY }}
TELNYX_PUBLIC_KEY: ${{ secrets.TELNYX_PUBLIC_KEY }}
AWSSNS_API_GATEWAY_URL: ${{ secrets.AWSSNS_API_GATEWAY_URL }}
APNS_AUTHKEY_8KVVCLA3HL: ${{ secrets.APNS_AUTHKEY_8KVVCLA3HL }}
APNS_AUTH_ID: ${{ secrets.APNS_AUTH_ID }}
APNS_TEAM_ID: ${{ secrets.APNS_TEAM_ID }}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
- TWILIO_FROM
- TELNYX_API_KEY
- TELNYX_PUBLIC_KEY
- AWSSNS_API_GATEWAY_URL
- APNS_AUTHKEY_8KVVCLA3HL
- APNS_AUTH_ID
- APNS_TEAM_ID
Expand Down
62 changes: 62 additions & 0 deletions src/Utopia/Messaging/Adapters/Push/AWSSNS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Utopia\Messaging\Adapters\Push;

use Utopia\Messaging\Adapters\Push as PushAdapter;
use Utopia\Messaging\Messages\Push;

class AWSSNS extends PushAdapter
{
/**
* @param string $apiGatewayUrl
*/
public function __construct(
private string $apiGatewayUrl
) {
}

/**
* Get adapter name.
*
* @return string
*/
public function getName(): string
{
return 'AWSSNS';
}

/**
* Get max messages per request.
*
* @return int
*/
public function getMaxMessagesPerRequest(): int
{
return 5000;
}

/**
* {@inheritdoc}
*
* @throws \Exception
*/
protected function process(Push $message): string
{
// Create the payload
$payload = [
'message' => $message->getData()
];

// Make the HTTP request
$response = $this->request(
method: 'POST',
url: $this->apiGatewayUrl,
headers: [
'Content-Type: application/json',
],
body: json_encode($payload)
);

return $response;
}
}
26 changes: 26 additions & 0 deletions tests/e2e/Push/AWSSNSTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests\E2E;

use Utopia\Messaging\Adapters\Push\AWSSNS as AWSSNSAdapter;
use Utopia\Messaging\Messages\Push;

class AWSSNSTest extends Base
{
public function testSend(): void
{
$apiGatewayUrl = getenv('AWSSNS_API_GATEWAY_URL');

$adapter = new AWSSNSAdapter($apiGatewayUrl);

$message = new Push(
data: null
);

$response = json_decode($adapter->send($message), true);

$this->assertNotEmpty($response);
$this->assertEquals('success', $response['status'] ?? null);
$this->assertNotEmpty($response['MessageId'] ?? null);
}
}