-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from utopia-php/feat-app-adapters
Feat app adapters
- Loading branch information
Showing
57 changed files
with
623 additions
and
340 deletions.
There are no files selected for viewing
This file contains 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,20 @@ | ||
name: "Static Analysis" | ||
|
||
on: [pull_request] | ||
jobs: | ||
analyse: | ||
name: Analyse | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 2 | ||
|
||
- run: git checkout HEAD^2 | ||
|
||
- name: Run Static Analysis | ||
run: | | ||
docker run --rm -v $PWD:/app composer sh -c \ | ||
"composer install --profile --ignore-platform-reqs && composer analyse" |
File renamed without changes.
This file contains 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 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 |
---|---|---|
|
@@ -21,8 +21,8 @@ composer require utopia-php/messaging | |
<?php | ||
|
||
use \Utopia\Messaging\Messages\Email; | ||
use \Utopia\Messaging\Adapters\Email\SendGrid; | ||
use \Utopia\Messaging\Adapters\Email\Mailgun; | ||
use \Utopia\Messaging\Adapter\Email\SendGrid; | ||
use \Utopia\Messaging\Adapter\Email\Mailgun; | ||
|
||
$message = new Email( | ||
to: ['[email protected]'], | ||
|
@@ -43,8 +43,8 @@ $messaging->send($message); | |
<?php | ||
|
||
use \Utopia\Messaging\Messages\SMS; | ||
use \Utopia\Messaging\Adapters\SMS\Twilio; | ||
use \Utopia\Messaging\Adapters\SMS\Telesign; | ||
use \Utopia\Messaging\Adapter\SMS\Twilio; | ||
use \Utopia\Messaging\Adapter\SMS\Telesign; | ||
|
||
$message = new SMS( | ||
to: ['+12025550139'], | ||
|
@@ -64,7 +64,7 @@ $messaging->send($message); | |
<?php | ||
|
||
use \Utopia\Messaging\Messages\Push; | ||
use \Utopia\Messaging\Adapters\Push\FCM; | ||
use \Utopia\Messaging\Adapter\Push\FCM; | ||
|
||
$message = new Push( | ||
to: ['eyJhGc...ssw5c'], | ||
|
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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,82 @@ | ||
<?php | ||
|
||
namespace Utopia\Messaging\Adapter\Chat; | ||
|
||
use Utopia\Messaging\Adapter; | ||
use Utopia\Messaging\Messages\Discord as DiscordMessage; | ||
|
||
class Discord extends Adapter | ||
{ | ||
/** | ||
* @param string $webhookId Your Discord webhook ID. | ||
* @param string $webhookToken Your Discord webhook token. | ||
*/ | ||
public function __construct( | ||
private string $webhookId, | ||
private string $webhookToken, | ||
) { | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'Discord'; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return 'app'; | ||
} | ||
|
||
public function getMessageType(): string | ||
{ | ||
return DiscordMessage::class; | ||
} | ||
|
||
public function getMaxMessagesPerRequest(): int | ||
{ | ||
return 1; | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
protected function process(DiscordMessage $message): string | ||
{ | ||
$query = []; | ||
|
||
if (! \is_null($message->getWait())) { | ||
$query['wait'] = $message->getWait(); | ||
} | ||
if (! \is_null($message->getThreadId())) { | ||
$query['thread_id'] = $message->getThreadId(); | ||
} | ||
|
||
$queryString = ''; | ||
foreach ($query as $key => $value) { | ||
if (empty($queryString)) { | ||
$queryString .= '?'; | ||
} | ||
$queryString .= $key.'='.$value; | ||
} | ||
|
||
return $this->request( | ||
method: 'POST', | ||
url: "https://discord.com/api/webhooks/{$this->webhookId}/{$this->webhookToken}{$queryString}", | ||
headers: [ | ||
'Content-Type: application/json', | ||
], | ||
body: \json_encode([ | ||
'content' => $message->getContent(), | ||
'username' => $message->getUsername(), | ||
'avatar_url' => $message->getAvatarUrl(), | ||
'tts' => $message->getTTS(), | ||
'embeds' => $message->getEmbeds(), | ||
'allowed_mentions' => $message->getAllowedMentions(), | ||
'components' => $message->getComponents(), | ||
'attachments' => $message->getAttachments(), | ||
'flags' => $message->getFlags(), | ||
'thread_name' => $message->getThreadName(), | ||
]), | ||
); | ||
} | ||
} |
This file contains 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
4 changes: 2 additions & 2 deletions
4
...opia/Messaging/Adapters/Email/Mailgun.php → ...topia/Messaging/Adapter/Email/Mailgun.php
This file contains 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
Oops, something went wrong.