Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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"
65 changes: 65 additions & 0 deletions src/Utopia/Messaging/Adapters/Push/PushBullet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
Comment thread
Sumitmaithani marked this conversation as resolved.

namespace Utopia\Messaging\Adapters\Push;

use Exception;

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

class PushBullet extends PushAdapter
Comment thread
Sumitmaithani marked this conversation as resolved.
Outdated
{
/**
* @param string $apiKey The PushBullet API key.
*/
public function __construct(string $apiKey)
{
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
{
return 1000;
}
Comment thread
stnguyen90 marked this conversation as resolved.

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->getStatusCode() === 200;
Comment thread
stnguyen90 marked this conversation as resolved.
Outdated
} 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
Comment thread
Sumitmaithani marked this conversation as resolved.
Outdated
{
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);
}
}