Skip to content

Commit

Permalink
added aws sns adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Dksie09 committed Oct 13, 2023
1 parent 2d0f474 commit f14b822
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
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);
}
}

0 comments on commit f14b822

Please sign in to comment.