Add log SMS when a message is sent

Introduced a new event subscriber to log SMS sent events with details such as recipient and message IDs. This enhances monitoring and debugging of SMS delivery.
This commit is contained in:
Julien Fastré 2025-01-17 13:47:09 +01:00
parent 594ed4a5b4
commit b02820407c
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 38 additions and 0 deletions

View File

@ -1,6 +1,7 @@
framework:
notifier:
texter_transports:
#ovhcloud: '%env(OVHCLOUD_DSN)%'
ovhcloud: '%env(SHORT_MESSAGE_DSN)%'
channel_policy:
# use chat/slack, chat/telegram, sms/twilio or sms/nexmo

View File

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Service\Notifier;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Notifier\Event\SentMessageEvent;
final readonly class SentMessageEventSubscriber implements EventSubscriberInterface
{
public function __construct(
private LoggerInterface $logger,
) {}
public static function getSubscribedEvents()
{
return [
SentMessageEvent::class => ['onSentMessage', 0],
];
}
public function onSentMessage(SentMessageEvent $event): void
{
$message = $event->getMessage();
$this->logger->warning('[sms] a sms was sent', ['validReceiversI' => $message->getOriginalMessage()->getRecipientId(), 'idsI' => $message->getMessageId()]);
}
}