Skip to content

Commit dfa57c5

Browse files
committed
minor #16906 [Notifier] Fix documentation symfony notifier (matthieudelmas)
This PR was submitted for the 6.2 branch but it was merged into the 5.4 branch instead. Discussion ---------- [Notifier] Fix documentation symfony notifier Hi there 👋 After following [the notifier doc](https://symfony.com/doc/current/notifier.html#customize-notification-messages) to send slack notifications, I think there is a problem at the message customization step : - I successfully get a slack notification, but when we go to the "Notifications" tab of the Symfony profiler I have an error message "`Impossible to invoke a method ("getSubject") on a variable null" ` ![image](https://user-images.githubusercontent.com/95386861/175016223-b48f5011-f596-4fb5-9200-ee3e5b894830.png) - when i dump the created ChatMessage, i see that the notification is empty. ![image](https://user-images.githubusercontent.com/95386861/175016085-86229a23-464e-43b6-8c9a-2dd6f887acc3.png) => Reading the ChatMessage class, it seems that the static method **fromNotification** can solves this problem _(check PR proposal)_ The other fixes are more obvious: - use RecipientInterface instead of SmsRecipientInterface since in the asChatMessage we use the RecipientInterface - strval on price in the message since price is an integer - method emoji on notification not on ChatMessage as the doc is telling us _(FYI this is my first public PR on github)_ <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `6.x` for features of unreleased versions). --> Commits ------- 71ff918 Fix documentation symfony notifier
2 parents 6a36b23 + 71ff918 commit dfa57c5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

notifier.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ and its ``asChatMessage()`` method::
697697
use Symfony\Component\Notifier\Message\ChatMessage;
698698
use Symfony\Component\Notifier\Notification\ChatNotificationInterface;
699699
use Symfony\Component\Notifier\Notification\Notification;
700-
use Symfony\Component\Notifier\Recipient\SmsRecipientInterface;
700+
use Symfony\Component\Notifier\Recipient\RecipientInterface;
701701

702702
class InvoiceNotification extends Notification implements ChatNotificationInterface
703703
{
@@ -710,10 +710,11 @@ and its ``asChatMessage()`` method::
710710

711711
public function asChatMessage(RecipientInterface $recipient, string $transport = null): ?ChatMessage
712712
{
713-
// Add a custom emoji if the message is sent to Slack
713+
// Add a custom subject and emoji if the message is sent to Slack
714714
if ('slack' === $transport) {
715-
return (new ChatMessage('You\'re invoiced '.$this->price.' EUR.'))
716-
->emoji('money');
715+
$this->subject('You\'re invoiced '.strval($this->price).' EUR.');
716+
$this->emoji("money");
717+
return ChatMessage::fromNotification($this);
717718
}
718719

719720
// If you return null, the Notifier will create the ChatMessage

0 commit comments

Comments
 (0)