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 Pushbullet Adapter #43

Open
wants to merge 7 commits 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
75 changes: 38 additions & 37 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,41 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 2
- run: git checkout HEAD^2
- name: Run Tests
env:
MAILGUN_API_KEY: ${{ secrets.MAILGUN_API_KEY }}
MAILGUN_DOMAIN: ${{ secrets.MAILGUN_DOMAIN }}
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
FCM_SERVER_KEY: ${{ secrets.FCM_SERVER_KEY }}
FCM_SERVER_TO: ${{ secrets.FCM_SERVER_TO }}
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
TWILIO_AUTH_TOKEN: ${{ secrets.TWILIO_AUTH_TOKEN }}
TWILIO_TO: ${{ secrets.TWILIO_TO }}
TWILIO_FROM: ${{ secrets.TWILIO_FROM }}
TELNYX_API_KEY: ${{ secrets.TELNYX_API_KEY }}
TELNYX_PUBLIC_KEY: ${{ secrets.TELNYX_PUBLIC_KEY }}
APNS_AUTHKEY_8KVVCLA3HL: ${{ secrets.APNS_AUTHKEY_8KVVCLA3HL }}
APNS_AUTH_ID: ${{ secrets.APNS_AUTH_ID }}
APNS_TEAM_ID: ${{ secrets.APNS_TEAM_ID }}
APNS_BUNDLE_ID: ${{ secrets.APNS_BUNDLE_ID }}
APNS_TO: ${{ secrets.APNS_TO }}
MSG_91_SENDER_ID: ${{ secrets.MSG_91_SENDER_ID }}
MSG_91_AUTH_KEY: ${{ secrets.MSG_91_AUTH_KEY }}
MSG_91_TO: ${{ secrets.MSG_91_TO }}
MSG_91_FROM: ${{ secrets.MSG_91_FROM }}
TEST_EMAIL: ${{ secrets.TEST_EMAIL }}
TEST_FROM_EMAIL: ${{ secrets.TEST_FROM_EMAIL }}
VONAGE_API_KEY: ${{ secrets.VONAGE_API_KEY }}
VONAGE_API_SECRET: ${{ secrets.VONAGE_API_SECRET }}
VONAGE_TO: ${{ secrets.VONAGE_TO }}
VONAGE_FROM: ${{ secrets.VONAGE_FROM }}
run: |
docker compose up -d --build
sleep 5
docker compose exec tests vendor/bin/phpunit
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 2
- run: git checkout HEAD^2
- name: Run Tests
env:
MAILGUN_API_KEY: ${{ secrets.MAILGUN_API_KEY }}
MAILGUN_DOMAIN: ${{ secrets.MAILGUN_DOMAIN }}
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
FCM_SERVER_KEY: ${{ secrets.FCM_SERVER_KEY }}
FCM_SERVER_TO: ${{ secrets.FCM_SERVER_TO }}
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
TWILIO_AUTH_TOKEN: ${{ secrets.TWILIO_AUTH_TOKEN }}
TWILIO_TO: ${{ secrets.TWILIO_TO }}
TWILIO_FROM: ${{ secrets.TWILIO_FROM }}
TELNYX_API_KEY: ${{ secrets.TELNYX_API_KEY }}
TELNYX_PUBLIC_KEY: ${{ secrets.TELNYX_PUBLIC_KEY }}
APNS_AUTHKEY_8KVVCLA3HL: ${{ secrets.APNS_AUTHKEY_8KVVCLA3HL }}
APNS_AUTH_ID: ${{ secrets.APNS_AUTH_ID }}
APNS_TEAM_ID: ${{ secrets.APNS_TEAM_ID }}
APNS_BUNDLE_ID: ${{ secrets.APNS_BUNDLE_ID }}
APNS_TO: ${{ secrets.APNS_TO }}
MSG_91_SENDER_ID: ${{ secrets.MSG_91_SENDER_ID }}
MSG_91_AUTH_KEY: ${{ secrets.MSG_91_AUTH_KEY }}
MSG_91_TO: ${{ secrets.MSG_91_TO }}
MSG_91_FROM: ${{ secrets.MSG_91_FROM }}
TEST_EMAIL: ${{ secrets.TEST_EMAIL }}
TEST_FROM_EMAIL: ${{ secrets.TEST_FROM_EMAIL }}
VONAGE_API_KEY: ${{ secrets.VONAGE_API_KEY }}
VONAGE_API_SECRET: ${{ secrets.VONAGE_API_SECRET }}
VONAGE_TO: ${{ secrets.VONAGE_TO }}
VONAGE_FROM: ${{ secrets.VONAGE_FROM }}
PUSHBULLET_API_KEY: ${{ secrets.PUSHBULLET_API_KEY }}
run: |
docker compose up -d --build
sleep 5
docker compose exec tests vendor/bin/phpunit
61 changes: 31 additions & 30 deletions docker-compose.yml
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"
64 changes: 64 additions & 0 deletions src/Utopia/Messaging/Adapters/Push/Pushbullet.php
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;
}
}
}
34 changes: 34 additions & 0 deletions tests/e2e/Push/PushBulletTest.php
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);
}
}