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 Pushy Messaging Adapter #41

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
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
VONAGE_API_SECRET: ${{ secrets.VONAGE_API_SECRET }}
VONAGE_TO: ${{ secrets.VONAGE_TO }}
VONAGE_FROM: ${{ secrets.VONAGE_FROM }}
PUSHY_SECRET_KEY: ${{ secrets.PUSHY_SECRET_KEY }}
PUSHY_SERVER_TO: ${{ secrets.PUSHY_SERVER_TO }}
run: |
docker compose up -d --build
sleep 5
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ $messaging->send($message);
- [ ] [UrbanAirship](https://www.urbanairship.com/)
- [ ] [Pushwoosh](https://www.pushwoosh.com/)
- [ ] [PushBullet](https://www.pushbullet.com/)
- [ ] [Pushy](https://pushy.me/)
- [x] [Pushy](https://pushy.me/)

## System Requirements

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ services:
- VONAGE_API_SECRET
- VONAGE_TO
- VONAGE_FROM
- PUSHY_SECRET_KEY
- PUSHY_SERVER_TO
build:
context: .
volumes:
Expand Down
65 changes: 65 additions & 0 deletions src/Utopia/Messaging/Adapters/Push/Pushy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Utopia\Messaging\Adapters\Push;

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

class Pushy extends PushAdapter
{
/**
* @param string $secretKey The secret API key that pushy provides.
*/
public function __construct(
private string $secretKey,
) {
}

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

/**
* Get max messages per request.
*
* @return int
*/
public function getMaxMessagesPerRequest(): int
{
return 1000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you confirm from the documentation that this limit is 1000 for Pushy?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Diveshmahajan4 The limit here should be 100000

}

/**
* {@inheritdoc}
*
* @throws \Exception
*/
public function process(Push $message): string
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

return $this->request(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should build a structured response consistent with other adapters, please check APNS/FCM for an idea on how to do so

method: 'POST',
url: "https://api.pushy.me/push?api_key={$this->secretKey}",
headers: [
'Content-Type: application/json',
],
body: \json_encode([
'to' => $message->getTo(),
'data' => $message->getData(),
'notifications' => [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be notification instead of notifications

'title' => $message->getTitle(),
'body' => $message->getBody(),
'badge' => $message->getBadge(),
'sound' => $message->getSound()
],
])
);
}

}
37 changes: 37 additions & 0 deletions tests/e2e/Push/PushyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Tests\E2E;

use Utopia\Messaging\Adapters\Push\Pushy as PushyAdapter;
use Utopia\Messaging\Messages\Push;

class PushyTest extends Base{
public function testSend(): void {
$secretKey = getenv('PUSHY_SECRET_KEY');

$adapter = new PushyAdapter($secretKey);

$to = getenv('PUSHY_SERVER_TO');

$message = new Push(
to: [$to],
title: 'TestTitle',
body: 'TestBody',
data: [
'some' => 'metadata',
],
action: null,
sound: 'default',
icon: null,
color: null,
tag: null,
badge: '1'
);

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

$this->assertNotEmpty($response);
$this->assertEquals(1, $response->success);
$this->assertEquals(0, $response->failure);
}
}
Loading