-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(feedback): Send a LINE Notify message when there is a feedback
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EventSubscriber; | ||
|
||
use App\Controller\Admin\FeedbackCrudController; | ||
use App\Entity\Feedback; | ||
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener; | ||
use Doctrine\ORM\Events; | ||
use EasyCorp\Bundle\EasyAdminBundle\Config\Action; | ||
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; | ||
use Symfony\Component\Notifier\Notification\Notification; | ||
use Symfony\Component\Notifier\NotifierInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
#[AsEntityListener(event: Events::postPersist, method: 'onFeedbackCreated', entity: Feedback::class)] | ||
final readonly class FeedbackCreatedListenerSubscriber | ||
{ | ||
public function __construct( | ||
private NotifierInterface $notifier, | ||
private TranslatorInterface $translator, | ||
private AdminUrlGenerator $adminUrlGenerator, | ||
) { | ||
} | ||
|
||
public function onFeedbackCreated(Feedback $feedback): void | ||
{ | ||
// FIXME: only optimized for LINE Notify | ||
|
||
$notificationContent = $this->translator->trans('notification.on-feedback-created.content', [ | ||
'%id%' => $feedback->getId(), | ||
'%account%' => $feedback->getSender()?->getUserIdentifier() | ||
?? $this->translator->trans('notification.on-feedback-created.anonymous'), | ||
'%subject%' => $feedback->getTitle(), | ||
'%link%' => $this->adminUrlGenerator->unsetAll() | ||
->setController(FeedbackCrudController::class) | ||
->setAction(Action::DETAIL) | ||
->setEntityId($feedback->getId()) | ||
->generateUrl(), | ||
]); | ||
|
||
$this->notifier->send((new Notification($notificationContent))->channels(['chat/linenotify'])); | ||
} | ||
} |
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