-
Notifications
You must be signed in to change notification settings - Fork 65
Added Pushbullet Adapter #43
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
Open
Sumitmaithani
wants to merge
7
commits into
utopia-php:main
Choose a base branch
from
Sumitmaithani:pushBullet-adapter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
831ef73
added pushbullet adapter
Sumitmaithani 512cd37
fixed lint error
Sumitmaithani 7d08600
Update src/Utopia/Messaging/Adapters/Push/PushBullet.php
Sumitmaithani 5e3cf14
Rename PushBullet.php to Pushbullet.php
Sumitmaithani beceb40
changed file name
Sumitmaithani 44ed9fc
Update src/Utopia/Messaging/Adapters/Push/Pushbullet.php
Sumitmaithani 2bcfdbe
changes PushBullet to Pushbullet
Sumitmaithani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,48 @@ | ||
| version: '3.9' | ||
| version: "3.9" | ||
|
|
||
| services: | ||
| tests: | ||
| environment: | ||
| - MAILGUN_API_KEY | ||
| - MAILGUN_DOMAIN | ||
| - SENDGRID_API_KEY | ||
| - FCM_SERVER_KEY | ||
| - FCM_SERVER_TO | ||
| - TWILIO_ACCOUNT_SID | ||
| - TWILIO_AUTH_TOKEN | ||
| - TWILIO_TO | ||
| - TWILIO_FROM | ||
| - TELNYX_API_KEY | ||
| - TELNYX_PUBLIC_KEY | ||
| - APNS_AUTHKEY_8KVVCLA3HL | ||
| - APNS_AUTH_ID | ||
| - APNS_TEAM_ID | ||
| - APNS_BUNDLE_ID | ||
| - APNS_TO | ||
| - MSG_91_SENDER_ID | ||
| - MSG_91_AUTH_KEY | ||
| - MSG_91_TO | ||
| - MSG_91_FROM | ||
| - TEST_EMAIL | ||
| - TEST_FROM_EMAIL | ||
| - VONAGE_API_KEY | ||
| - VONAGE_API_SECRET | ||
| - VONAGE_TO | ||
| - VONAGE_FROM | ||
| - MAILGUN_API_KEY | ||
| - MAILGUN_DOMAIN | ||
| - SENDGRID_API_KEY | ||
| - FCM_SERVER_KEY | ||
| - FCM_SERVER_TO | ||
| - TWILIO_ACCOUNT_SID | ||
| - TWILIO_AUTH_TOKEN | ||
| - TWILIO_TO | ||
| - TWILIO_FROM | ||
| - TELNYX_API_KEY | ||
| - TELNYX_PUBLIC_KEY | ||
| - APNS_AUTHKEY_8KVVCLA3HL | ||
| - APNS_AUTH_ID | ||
| - APNS_TEAM_ID | ||
| - APNS_BUNDLE_ID | ||
| - APNS_TO | ||
| - MSG_91_SENDER_ID | ||
| - MSG_91_AUTH_KEY | ||
| - MSG_91_TO | ||
| - MSG_91_FROM | ||
| - TEST_EMAIL | ||
| - TEST_FROM_EMAIL | ||
| - VONAGE_API_KEY | ||
| - VONAGE_API_SECRET | ||
| - VONAGE_TO | ||
| - VONAGE_FROM | ||
| - PUSHBULLET_API_KEY | ||
| build: | ||
| context: . | ||
| volumes: | ||
| - ./src:/usr/local/src/src | ||
| - ./tests:/usr/local/src/tests | ||
| - ./phpunit.xml:/usr/local/src/phpunit.xml | ||
|
|
||
| maildev: | ||
| image: appwrite/mailcatcher:1.0.0 | ||
| ports: | ||
| - '10000:1080' | ||
| - "10000:1080" | ||
|
|
||
| request-catcher: | ||
| image: appwrite/requestcatcher:1.0.0 | ||
| ports: | ||
| - '10001:5000' | ||
| - "10001:5000" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
|
|
||
| namespace Utopia\Messaging\Adapters\Push; | ||
|
|
||
| use Exception; | ||
| use GuzzleHttp\Client; | ||
| use Utopia\Messaging\Adapters\Push as PushAdapter; | ||
| use Utopia\Messaging\Messages\Push; | ||
|
|
||
| class Pushbullet extends PushAdapter | ||
| { | ||
| /** | ||
| * @param string $apiKey The PushBullet API key. | ||
| */ | ||
| public function __construct(private string $apiKey) | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Get adapter name. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getName(): string | ||
| { | ||
| return 'Pushbullet'; | ||
| } | ||
|
|
||
| /** | ||
| * Get max messages per request. | ||
| * | ||
| * @return int | ||
| */ | ||
| public function getMaxMessagesPerRequest(): int | ||
| { | ||
| //TODO:: Didn't find the limit in PushBullet documentation | ||
| return 1000; | ||
| } | ||
|
|
||
| public function process(Push $message): bool | ||
| { | ||
| // Compose the Pushbullet API request | ||
| $payload = [ | ||
| 'type' => 'note', | ||
| 'title' => $message->getTitle(), | ||
| 'body' => $message->getBody(), | ||
| ]; | ||
|
|
||
| try { | ||
| $client = new Client(); | ||
| $response = $client->request('POST', 'https://api.pushbullet.com/v2/pushes', [ | ||
| 'headers' => [ | ||
| 'Access-Token' => $this->apiKey, | ||
| 'Content-Type' => 'application/json', | ||
| ], | ||
| 'json' => $payload, | ||
| ]); | ||
|
|
||
| return $response; | ||
| } catch (Exception $e) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\E2E; | ||
|
|
||
| use Utopia\Messaging\Adapters\Push\Pushbullet as PushbulletAdapter; | ||
| use Utopia\Messaging\Messages\Push; | ||
|
|
||
| class PushbulletTest extends Base | ||
| { | ||
| public function testSend(): void | ||
| { | ||
| $pushbulletApiKey = getenv('PUSHBULLET_API_KEY'); | ||
|
|
||
| $adapter = new PushbulletAdapter($pushbulletApiKey); | ||
|
|
||
| $message = new Push( | ||
| to: [$to], | ||
| title: 'TestTitle', | ||
| body: 'TestBody', | ||
| data: null, | ||
| action: null, | ||
| sound: 'default', | ||
| icon: null, | ||
| color: null, | ||
| tag: null, | ||
| badge: '1' | ||
| ); | ||
|
|
||
| $response = \json_decode($adapter->process($message)); | ||
|
|
||
| $this->assertNotEmpty($response); | ||
| $this->assertEquals('success', $response->status); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.