Installation
composer require com-company/conexteo-notifier
Add the DSN to your .env:
CONEXTEO_DSN=conexteo://APP_ID:API_KEY@default?sender=SENDER
First Use Case: Sending a Notification
Inject the Notifier service and use the conexteo transport:
use Symfony\Component\Notifier\NotifierInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
class MyService
{
public function __construct(private NotifierInterface $notifier) {}
public function sendWelcomeSms(string $phone): void
{
$message = new SmsMessage('Welcome! Your account is ready.');
$this->notifier->send($message->to($phone));
}
}
Where to Look First
config/packages/conexteo_notifier.yaml (if provided) for default settings.CONEXTEO_DSN in .env matches the required structure.SmsMessage, Email).Sending SMS Notifications
$this->notifier->send(
new SmsMessage('Your OTP: 123456')
->to('+1234567890')
->priority(NotifierInterface::PRIORITY_HIGH)
);
Handling Failures
Use Symfony’s Failure events to log or retry failed sends:
$this->notifier->send(
new SmsMessage('Hello'),
['failure' => function (Failure $failure) {
// Log or retry logic
}]
);
Dynamic Sender/Recipient Override the sender or recipient per message:
$message = new SmsMessage('Hello')
->to($phone)
->sender('CustomSender'); // Overrides DSN's `sender`
EventDispatcher to trigger actions post-send (e.g., analytics).RateLimiter to throttle messages if needed.Transport interface for unit tests:
$transport = $this->createMock(TransportInterface::class);
$notifier = new Notifier([$transport]);
DSN Validation
CONEXTEO_DSN (e.g., missing APP_ID or API_KEY) throws cryptic errors.ParameterBag check:
if (!preg_match('/^conexteo:\/\/[^:]+:[^@]+@/', $dsn)) {
throw new \InvalidArgumentException('Invalid Conexteo DSN');
}
Sender Defaults
sender in the DSN is optional but required by Conexteo’s API.?sender=SENDER is included in the DSN or handle missing sender in the transport.Async Delays
AsyncTransport to queue messages:
$this->notifier->send($message, ['transport' => new AsyncTransport($conexteoTransport)]);
monolog to log transport interactions:
# config/packages/monolog.yaml
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
$message->getHeaders()->add('X-DEBUG-PAYLOAD', json_encode($message->getContent()));
Custom Transports
Extend TransportInterface to add features like:
Middleware
Use Symfony’s TransportMiddleware to modify messages:
$transport = new ConexteoTransport($dsn);
$transport->addMiddleware(new AddSignatureMiddleware('your-secret'));
Configuration Overrides
Override default settings in config/packages/conexteo_notifier.yaml:
conexteo_notifier:
default_sender: 'OverrideSender'
timeout: 30 # seconds
How can I help you explore Laravel packages today?