sol-parts / symfony-smsclub-notifier
Symfony SmsClub Notifier Bridge
Package info
github.com/sol-parts/symfony-smsclub-notifier
Type:symfony-notifier-bridge
pkg:composer/sol-parts/symfony-smsclub-notifier
Requires
- php: >=8.2
- ext-mbstring: *
- symfony/http-client: ^6.4|^7.0
- symfony/notifier: ^7.3
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Provides SmsClub integration for Symfony Notifier.
The transport supports sending SMS messages, reading the SmsClub response from
the resulting SentMessage, and checking the account balance.
Installation
composer require sol-parts/symfony-smsclub-notifier
Standalone usage
The transport can be used without the Symfony Full Stack Framework:
use SolParts\SymfonySmsClubNotifier\SmsClubTransport; use Symfony\Component\Notifier\Message\SmsMessage; $transport = new SmsClubTransport('auth-token', 'InfoCenter'); $message = new SmsMessage('380931234567', 'Your order has been shipped.'); $sentMessage = $transport->send($message); dump($sentMessage->getMessageId()); // '1241725993' dump($sentMessage->getInfo()); // [ // 'success_request' => [ // 'info' => [ // '1241725993' => '380931234567', // ], // ], // ]
Checking the balance
$balance = $transport->balance(); dump($balance); // '8121.1800 UAH'
Symfony Full Stack Framework
Add the SmsClub DSN to your environment:
# .env.local SMSCLUB_DSN=smsclub://TOKEN@default?from=FROM
Register the transport factory:
# config/services.yaml services: SolParts\SymfonySmsClubNotifier\SmsClubTransportFactory: autowire: true tags: ['texter.transport_factory']
Configure the texter transport:
# config/packages/notifier.yaml framework: notifier: texter_transports: smsclub: '%env(SMSCLUB_DSN)%'
Where:
TOKENis your SmsClub API token;FROMis your registered alphanumeric 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.', )); } }