-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
300 additions
and
1 deletion.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
services/Core/Notifications/Channels/Hm_NotificationChannel.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Services\Core\Notifications\Channels; | ||
|
||
abstract class Hm_NotificationChannel | ||
{ | ||
abstract public function send($notifiable, string $message): void; | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace Services\Core\Notifications\Channels; | ||
|
||
use Symfony\Component\Notifier\Notification\Notification; | ||
use Symfony\Component\Notifier\Bridge\Slack\SlackTransport; | ||
|
||
class Hm_SlackChannel extends Hm_NotificationChannel | ||
{ | ||
private SlackTransport $transport; | ||
|
||
public function __construct(SlackTransport $transport) | ||
{ | ||
$this->transport = $transport; | ||
} | ||
|
||
public function send($notifiable, string $message): void | ||
{ | ||
// Assuming $notifiable has a method to get the Slack channel/user ID | ||
$notification = (new Notification('Slack Notification')) | ||
->content($message); | ||
|
||
$this->transport->send($notification); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
services/Core/Notifications/Channels/Hm_TelegramChannel.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Services\Core\Notifications\Channels; | ||
|
||
use Symfony\Component\Notifier\Notification\Notification; | ||
use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransport; | ||
|
||
class Hm_TelegramChannel extends Hm_NotificationChannel | ||
{ | ||
private TelegramTransport $transport; | ||
|
||
public function __construct(TelegramTransport $transport) | ||
{ | ||
$this->transport = $transport; | ||
} | ||
|
||
public function send($notifiable, string $message): void | ||
{ | ||
$notification = (new Notification('Telegram Notification')) | ||
->content($message); | ||
|
||
$this->transport->send($notification); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace Services\Core\Notifications\Channels; | ||
|
||
use Symfony\Component\Notifier\Notification\Notification; | ||
use Symfony\Component\Notifier\Bridge\Twilio\TwilioTransport; | ||
|
||
class Hm_TwilioChannel extends Hm_NotificationChannel | ||
{ | ||
private TwilioTransport $transport; | ||
|
||
public function __construct(TwilioTransport $transport) | ||
{ | ||
$this->transport = $transport; | ||
} | ||
|
||
public function send($notifiable, string $message): void | ||
{ | ||
$notification = (new Notification('SMS Notification')) | ||
->content($message); | ||
|
||
$this->transport->send($notification); | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
|
||
namespace Services\Core\Notifications; | ||
|
||
use Symfony\Component\Notifier\Notifier; | ||
use Services\Core\Notifications\Channels\Hm_SlackChannel; | ||
use Services\Core\Notifications\Channels\Hm_TwilioChannel; | ||
use Services\Core\Notifications\Channels\Hm_TelegramChannel; | ||
|
||
class Hm_Notification | ||
{ | ||
public function __construct(private array $config = []) | ||
{ | ||
$this->config = $config; // Set configuration in the constructor | ||
} | ||
|
||
public function via(): array | ||
{ | ||
return $this->config['channels'] ?? ['slack', 'telegram']; | ||
} | ||
|
||
public function send($notifiable, string $title, string $content): void | ||
{ | ||
$channels = $this->via(); | ||
foreach ($channels as $channel) { | ||
$this->sendThroughChannel($channel, $notifiable, $content); | ||
} | ||
} | ||
|
||
private function sendThroughChannel(string $channel, $notifiable, string $message): void | ||
{ | ||
switch ($channel) { | ||
case 'slack': | ||
(new Hm_SlackChannel(new SlackTransport()))->send($notifiable, $message); | ||
break; | ||
case 'telegram': | ||
(new Hm_TelegramChannel(new TelegramTransport()))->send($notifiable, $message); | ||
break; | ||
case 'twilio': | ||
(new Hm_TwilioChannel(new TwilioTransport()))->send($notifiable, $message); | ||
break; | ||
// Add more channels as necessary | ||
} | ||
} | ||
} | ||
|
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,26 @@ | ||
<?php | ||
|
||
namespace Services\Notifications; | ||
|
||
use Services\Core\Notifications\Hm_Notification; | ||
|
||
class Hm_NewMailNotification extends Hm_Notification | ||
{ | ||
public function __construct(array $config = []) | ||
{ | ||
parent::__construct($config); | ||
} | ||
|
||
public function via(): array | ||
{ | ||
// Specify which channels this notification should use | ||
return ['slack', 'telegram']; | ||
} | ||
|
||
public function sendNotification($notifiable, string $message): void | ||
{ | ||
// You can define a title and content as needed | ||
$title = "New Notification"; | ||
$this->send($notifiable, $title, $message); | ||
} | ||
} |
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