0

When using Symfony's notifier component to send an SMS via a custom SMS Service, the Texter::send()-method always returns NULL, which prevents me from seeing if the message has been sent or not.

Though the documentation (from v6.3 up to 7.2:) suggests to expect a SentMessage-object result:

 // TexterInterface $texter
 $sentMessage = $texter->send($sms);
 // ...

But when looking/debugging the actual Symfony\Component\Notifier\Texter-Class, the code looks like this:

 public function send(MessageInterface $message): ?SentMessage
 {
 if (null === $this->bus) {
 return $this->transport->send($message);
 }
 $this->dispatcher?->dispatch(new MessageEvent($message, true));
 $this->bus->dispatch($message);
 return null; // <--- Always returns NULL (the returned SentMessage-object is lost)
 }

Does anyone know the specifics behind the scenes of the Notifier-Component and how to retrieve back the actual SentMessage object?

I do indeed return the SentMessage-object in my Transport-class, but it goes lost in the specififed line.

How to know if the SMS has been sent?

asked May 8, 2025 at 8:46

1 Answer 1

0

The Texter::send() method returns null because it's dispatching the message asynchronously. To get the SentMessage object, you either have to force synchronous behavior by removing the message bus from your DSN (bad idea) or handle the SentMessageEvent asynchronously in an event listener or subscriber.

SecretAgentMan
2,8708 gold badges26 silver badges44 bronze badges
answered Sep 19, 2025 at 9:24
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.