sol-parts / symfony-turbosms-notifier
Symfony TurboSMS Notifier Bridge
Package info
github.com/sol-parts/symfony-turbosms-notifier
Type:symfony-notifier-bridge
pkg:composer/sol-parts/symfony-turbosms-notifier
Requires
- php: >=8.2
- symfony/http-client: ^6.4|^7.0
- symfony/notifier: ^7.3
README
Provides TurboSMS integration for Symfony Notifier. The transport supports SMS, hybrid Viber with SMS fallback, and account balance checks through the TurboSMS HTTP JSON API.
Installation
composer require sol-parts/symfony-turbosms-notifier
Standalone usage
The transport can be used without the Symfony Full Stack Framework:
use SolParts\SymfonyTurboSmsNotifier\TurboSmsTransport; use Symfony\Component\Notifier\Message\SmsMessage; $transport = new TurboSmsTransport('auth-token', 'ExampleShop'); $message = new SmsMessage( phone: '+380771234567', subject: 'Your order has been shipped.', ); $sentMessage = $transport->send($message); dump($sentMessage->getMessageId()); // 'f37015f7-68c1-28d7-44af-bba8e55e7536' dump($sentMessage->getInfo()); // The complete decoded TurboSMS API response.
Checking the balance
$balance = $transport->balance(); dump($balance); // '12345.67'
A rejected or unreadable balance request raises a
Symfony\Component\Notifier\Exception\TransportException rather than returning
a placeholder value.
Symfony Full Stack Framework
Add the TurboSMS DSN to your environment:
# .env.local TURBOSMS_DSN=turbosms://AUTH_TOKEN@default?from=FROM
Register the transport factory:
# config/services.yaml services: SolParts\SymfonyTurboSmsNotifier\TurboSmsTransportFactory: autowire: true tags: ['texter.transport_factory']
Configure the texter transport:
# config/packages/notifier.yaml framework: notifier: texter_transports: turbosms: '%env(TURBOSMS_DSN)%'
Where:
AUTH_TOKENis the token generated in the TurboSMS HTTP API settings;FROMis your registered sender name.
URL-encode the token and sender name if they contain characters reserved in a URI.
Inject Symfony's TexterInterface to send a message:
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\TexterInterface; final class OrderNotifier { public function __construct( private readonly TexterInterface $texter, ) { } public function sendShippingNotice(string $phone): void { $this->texter->send(new SmsMessage( $phone, 'Your order has been shipped.', )); } }
Hybrid Viber with SMS fallback
Use TurboSmsOptions to include both Viber and SMS in the same TurboSMS
request. TurboSMS tries Viber first and uses SMS when Viber delivery fails:
use SolParts\SymfonyTurboSmsNotifier\TurboSmsOptions; use Symfony\Component\Notifier\Message\SmsMessage; $options = (new TurboSmsOptions()) ->viber_if_possible(true) ->is_transactional(true); $message = new SmsMessage( phone: '+380771234567', subject: 'Your order has been shipped.', options: $options, );
TurboSMS registers the Viber sender separately from the SMS sender. When the two differ, set the Viber one explicitly — otherwise the SMS sender name is reused for both:
$options->viber_sender('Example Shop UA');
Transactional Viber messages must match a template registered with TurboSMS. To retry immediately with an SMS-only request when TurboSMS rejects the Viber sender or transactional template, enable the explicit retry option:
$options->resend_sms_if_viber_not_send(true);
The retry also covers a Viber leg rejected for an individual recipient, which
TurboSMS reports inside response_result while keeping the overall response
code successful.