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

Feat push #20

Merged
merged 39 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
52021ee
Added start to APNS
wess Jul 19, 2023
8ee1844
Data structures and apns
wess Jul 29, 2023
2e37e48
working on email adapter for service and impl
wess Jul 31, 2023
5ccda37
Little reorg
wess Jul 31, 2023
e9c792a
Sendgrid test and some key clean up
wess Aug 2, 2023
cb8f99e
Removes unneeded classes for apns
wess Aug 3, 2023
f0c5cbb
Removes TwilioNotify as Twilio is ending it this year
wess Aug 4, 2023
6472702
Twillio test
wess Aug 4, 2023
40eada3
Removes, decided, unneeded entities
wess Aug 7, 2023
43bed4b
Updates gitignore, it was missing a good bit
wess Aug 11, 2023
7f4448c
Moves p8 to use env var
wess Aug 11, 2023
5d26fde
Adds proper env vars to docker-compose.yml
wess Aug 14, 2023
0ea850d
lint all the things! (^_^)/
wess Aug 14, 2023
6f2defb
Let's add EU
wess Aug 14, 2023
5f85757
Fixes lints and boom passing tests
wess Aug 14, 2023
b8add14
PR requested updates
wess Aug 30, 2023
da94fa7
Correction and clean up for APNS.php
wess Aug 30, 2023
d43325a
Removes personal email and moves test emails into .env
wess Aug 30, 2023
36aee6a
Lint fixes
wess Aug 30, 2023
ab0a41c
Removes .env from docker compose
wess Aug 31, 2023
4ebebe9
Adds US flag to mailgun for region handling
wess Sep 1, 2023
a1a1fb3
Forwards env files in docker-composer.yml
wess Sep 7, 2023
1c5a451
Updates workflow for runtime env vars
wess Sep 7, 2023
8f0e760
isUS, for mailgun, is true
wess Sep 7, 2023
b301211
Type-o in workflow
wess Sep 7, 2023
5e5e063
Removes dead commented code
wess Sep 8, 2023
3da89f1
Updates requested for PR
wess Sep 8, 2023
b67db70
Updates sendgrid to check for empty/success response
wess Sep 11, 2023
abb795f
LINT run.
wess Sep 11, 2023
91885b0
Updates docker compose with vonage vars
wess Sep 11, 2023
5114e74
Adds FCM key to env
wess Sep 11, 2023
ee8c94c
Adds vars to test workflow
wess Sep 11, 2023
a627f56
removed extra character in yml
wess Sep 11, 2023
2d7001f
Restart job
wess Sep 11, 2023
436fbf5
testing with inline value
wess Sep 11, 2023
a9e9000
Adds FCM_SERVER_TO back in to ENV
wess Sep 11, 2023
6367acc
Lint and changes
wess Sep 11, 2023
fcde4b4
APNS max send bumped to 5k
wess Sep 11, 2023
2bb0922
Uses curl_multi for apple push
wess Sep 14, 2023
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
29 changes: 28 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,34 @@ jobs:
with:
fetch-depth: 2
- run: git checkout HEAD^2
- name: Run Tests
- 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
Expand Down
94 changes: 94 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,97 @@
.idea
vendor
Makefile
.envrc
.env
*.p8

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### PHPUnit ###
# Covers PHPUnit
# Reference: https://phpunit.de/

# Generated files
.phpunit.result.cache
.phpunit.cache

# PHPUnit
/app/phpunit.xml
/phpunit.xml

# Build data
/build/

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/macos,linux,windows,phpunit
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Install using composer:
composer require utopia-php/messaging
```

## Email
## Email

```php
<?php
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"ext-curl": "*"
},
"require-dev": {
"phpunit/phpunit": "9.5.*",
"phpmailer/phpmailer": "6.6.*",
"phpunit/phpunit": "9.6.*",
"phpmailer/phpmailer": "6.8.*",
"laravel/pint": "^1.2"
},
"config": {
Expand Down
49 changes: 26 additions & 23 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,40 @@ 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
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:
Expand Down
24 changes: 21 additions & 3 deletions src/Utopia/Messaging/Adapters/Email/Mailgun.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@ class Mailgun extends EmailAdapter
public function __construct(
private string $apiKey,
private string $domain,
private bool $isUS = true
wess marked this conversation as resolved.
Show resolved Hide resolved
) {
}

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

/**
* Get adapter description.
*
* @return int
*/
public function getMaxMessagesPerRequest(): int
{
return 1000;
Expand All @@ -34,19 +45,26 @@ public function getMaxMessagesPerRequest(): int
*/
protected function process(Email $message): string
{
return $this->request(
$usDomain = 'api.mailgun.net';
$euDomain = 'api.eu.mailgun.net';

$domain = $this->isUS ? $usDomain : $euDomain;

$response = $this->request(
method: 'POST',
url: "https://api.mailgun.net/v3/{$this->domain}/messages",
url: "https://$domain/v3/{$this->domain}/messages",
headers: [
'Authorization: Basic '.base64_encode('api:'.$this->apiKey),
],
body: \http_build_query([
'from' => $message->getFrom(),
'to' => \implode(',', $message->getTo()),
'from' => $message->getFrom(),
'subject' => $message->getSubject(),
'text' => $message->isHtml() ? null : $message->getContent(),
'html' => $message->isHtml() ? $message->getContent() : null,
]),
);

return $response;
}
}
Loading