-
Notifications
You must be signed in to change notification settings - Fork 62
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||||
} | ||||
|
||||
/** | ||||
* {@inheritdoc} | ||||
* | ||||
* @throws \Exception | ||||
*/ | ||||
public function process(Push $message): string | ||||
{ | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
return $this->request( | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' => [ | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be |
||||
'title' => $message->getTitle(), | ||||
'body' => $message->getBody(), | ||||
'badge' => $message->getBadge(), | ||||
'sound' => $message->getSound() | ||||
], | ||||
]) | ||||
); | ||||
} | ||||
|
||||
} |
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); | ||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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