diff --git a/services/Commands/Hm_CheckMailCommand.php b/services/Commands/Hm_CheckMailCommand.php index 74e668160..7a8eb5ee8 100644 --- a/services/Commands/Hm_CheckMailCommand.php +++ b/services/Commands/Hm_CheckMailCommand.php @@ -35,9 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->info("Checking for new mail..."); $message = "Hello! You have a new mail on test@entreprise server."; - // $notification = (new Hm_NewMailNotification()) - // ->greeting('New Mail Alert') - // ->line($message); + // $notification = new Hm_NewMailNotification($message); // $notification->sendNow(); Hm_NewMailNotification::dispatch($message); // Hm_ProcessNewEmail::dispatch(email: 'muhngesteven@gmail.com'); diff --git a/services/Core/Notifications/Channels/Hm_TelegramChannel.php b/services/Core/Notifications/Channels/Hm_TelegramChannel.php index 30ff324a2..c53fc3293 100644 --- a/services/Core/Notifications/Channels/Hm_TelegramChannel.php +++ b/services/Core/Notifications/Channels/Hm_TelegramChannel.php @@ -3,10 +3,10 @@ namespace Services\Core\Notifications\Channels; use Services\Core\Hm_Container; -use Symfony\Component\Notifier\Notifier; +use Symfony\Component\Notifier\Chatter; +use Symfony\Component\Notifier\Transport\Dsn; use Symfony\Component\Notifier\Message\ChatMessage; -use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions; -use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransport; +use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory; /** * Class Hm_TelegramChannel @@ -15,11 +15,11 @@ class Hm_TelegramChannel extends Hm_NotificationChannel { /** - * The Notifier instance. + * The Chatter instance. * - * @var Notifier + * @var Chatter */ - private $notifier; + private $chatter; /** * Constructor. @@ -29,29 +29,25 @@ public function __construct() { $config = Hm_Container::getContainer()->get('config'); $telegramConfig = $config->get('telegram'); - $telegramBotToken = $telegramConfig['bot_token']; - $telegramChatId = $telegramConfig['chat_id']; - $telegramTransport = new TelegramTransport($telegramBotToken, $telegramChatId); - $this->notifier = new Notifier([$telegramTransport]); + $telegramToken = $telegramConfig['bot_token']; + $telegramChatId = $telegramConfig['chat_id']; // ID du chat ou username (@username) + + $dsnString = sprintf('telegram://%s@default?channel=%s', $telegramToken, $telegramChatId); + $dsn = new Dsn($dsnString); + $factory = new TelegramTransportFactory(); + $transport = $factory->create($dsn); + $this->chatter = new Chatter($transport); } /** - * Send a Telegram message using the Telegram Bot. + * Send a Telegram message. * * @param Hm_Notification $notification The notification object. */ public function send($notification): void { - $telegramMessage = new ChatMessage($notification->getMessageText()); - - // Optionally add more Telegram message options (like parsing mode) - $telegramMessage->options( - (new TelegramOptions()) - ->parseMode(TelegramOptions::PARSE_MODE_MARKDOWN_V2) - ); - - $this->notifier->send($telegramMessage->getNotification()); - - echo "Message sent via Telegram!"; + $chatMessage = new ChatMessage($notification->getContent()); + $this->chatter->send($chatMessage); + echo "Message sent to Telegram!"; } -} +} \ No newline at end of file diff --git a/services/Core/Notifications/Channels/Hm_TwilioChannel.php b/services/Core/Notifications/Channels/Hm_TwilioChannel.php index 475c1b373..7075fb1d0 100644 --- a/services/Core/Notifications/Channels/Hm_TwilioChannel.php +++ b/services/Core/Notifications/Channels/Hm_TwilioChannel.php @@ -3,9 +3,10 @@ namespace Services\Core\Notifications\Channels; use Services\Core\Hm_Container; -use Symfony\Component\Notifier\Notifier; +use Symfony\Component\Notifier\Chatter; +use Symfony\Component\Notifier\Transport\Dsn; use Symfony\Component\Notifier\Message\SmsMessage; -use Symfony\Component\Notifier\Bridge\Twilio\TwilioTransport; +use Symfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory; /** * Class Hm_TwilioChannel @@ -14,11 +15,11 @@ class Hm_TwilioChannel extends Hm_NotificationChannel { /** - * The Notifier instance. + * The Chatter instance. * - * @var Notifier + * @var Chatter */ - private $notifier; + private $chatter; /** * Constructor. @@ -28,8 +29,19 @@ public function __construct() { $config = Hm_Container::getContainer()->get('config'); $twilioConfig = $config->get('twilio'); - $twilioTransport = new TwilioTransport($twilioConfig['sid'], $twilioConfig['token'], $twilioConfig['from']); - $this->notifier = new Notifier([$twilioTransport]); + $twilioAccountSid = $twilioConfig['sid']; + $twilioAuthToken = $twilioConfig['token']; + $twilioFrom = $twilioConfig['from']; + $dsnString = sprintf( + 'twilio://%s:%s@default?from=%s', + $twilioAccountSid, + $twilioAuthToken, + $twilioFrom + ); + $dsn = new Dsn($dsnString); + $factory = new TwilioTransportFactory(); + $transport = $factory->create($dsn); + $this->chatter = new Chatter($transport); } /** @@ -39,12 +51,18 @@ public function __construct() * @param string $message The message content. * @param string $title The title or subject of the notification (optional). */ + /** + * Send a Twilio SMS message. + * + * @param Hm_Notification $notification The notification object. + */ public function send($notification): void { - $smsMessage = new SmsMessage($notification->getRecipient(), $notification->getMessageText()); - // Send the message via Twilio - $this->notifier->send($smsMessage->getNotification()); + $config = Hm_Container::getContainer()->get('config'); + $twilioTo = $config->get('twilio')['to']; + $smsMessage = new SmsMessage($twilioTo, $notification->getContent()); + $this->chatter->send($smsMessage); echo "Message sent via Twilio!"; } } diff --git a/services/Core/Notifications/Channels/Hm_VonageChannel.php b/services/Core/Notifications/Channels/Hm_VonageChannel.php index b2500b18a..063c25ddb 100644 --- a/services/Core/Notifications/Channels/Hm_VonageChannel.php +++ b/services/Core/Notifications/Channels/Hm_VonageChannel.php @@ -3,14 +3,19 @@ namespace Services\Core\Notifications\Channels; use Services\Core\Hm_Container; -use Symfony\Component\Notifier\Notifier; +use Symfony\Component\Notifier\Chatter; +use Symfony\Component\Notifier\Transport\Dsn; use Symfony\Component\Notifier\Message\SmsMessage; -use Symfony\Component\Notifier\Bridge\Vonage\VonageOptions; -use Symfony\Component\Notifier\Bridge\Vonage\VonageTransport; +use Symfony\Component\Notifier\Bridge\Vonage\VonageTransportFactory; class Hm_VonageChannel extends Hm_NotificationChannel { - private $notifier; + /** + * The Chatter instance. + * + * @var Chatter + */ + private $chatter; /** * Constructor. @@ -20,28 +25,35 @@ public function __construct() { $config = Hm_Container::getContainer()->get('config'); $vonageConfig = $config->get('vonage'); + $vonageApiKey = $vonageConfig['api_key']; $vonageApiSecret = $vonageConfig['api_secret']; - $vonageFromNumber = $vonageConfig['from']; - $vonageTransport = new VonageTransport($vonageApiKey, $vonageApiSecret, $vonageFromNumber); - $this->notifier = new Notifier([$vonageTransport]); + $vonageFrom = $vonageConfig['from']; + + $dsnString = sprintf( + 'vonage://%s:%s@default?from=%s', + $vonageApiKey, + $vonageApiSecret, + $vonageFrom + ); + $dsn = new Dsn($dsnString); + $factory = new VonageTransportFactory(); + $transport = $factory->create($dsn); + $this->chatter = new Chatter($transport); } /** - * Send an SMS message using Vonage. + * Send a Vonage SMS message. * * @param Hm_Notification $notification The notification object. */ public function send($notification): void { - $smsMessage = new SmsMessage($notification->getRecipient(), $notification->getMessageText()); - - // Optionally, you can configure options for Vonage (like TTL, etc.) - // $smsMessage->options(new VonageOptions()); - - // Send the message via Vonage - $this->notifier->send($smsMessage->getNotification()); + $config = Hm_Container::getContainer()->get('config'); + $vonageTo = $config->get('vonage')['to']; - echo "Message sent via Vonage (Nexmo)!"; + $smsMessage = new SmsMessage($vonageTo, $notification->getContent()); + $this->chatter->send($smsMessage); + echo "Message sent via Vonage!"; } } diff --git a/services/Notifications/Hm_NewMailNotification.php b/services/Notifications/Hm_NewMailNotification.php index 291eaa528..426f5e6f4 100644 --- a/services/Notifications/Hm_NewMailNotification.php +++ b/services/Notifications/Hm_NewMailNotification.php @@ -20,6 +20,6 @@ class Hm_NewMailNotification extends Hm_Notification implements Hm_ShouldQueue public function via(): array { - return ['slack'];//, 'telegram','broadcast' + return ['telegram'];//, 'slack', 'telegram','broadcast' } }