connected-company/conexteo-notifier
Installation
composer require connected-company/conexteo-notifier
Ensure your Laravel project uses Symfony's symfony/notifier (v5.4+). If not, install it first:
composer require symfony/notifier
Configuration
Add the DSN to your .env:
CONEXTEO_DSN=conexteo://APP_ID:API_KEY@default?sender=SENDER
Replace placeholders with your Conexteo credentials.
First Use Case Send a notification via a controller or command:
use Symfony\Component\Notifier\NotifierInterface;
public function sendNotification(NotifierInterface $notifier)
{
$message = new ChatMessage('Hello from Laravel!');
$notifier->send($message->to('recipient@example.com'));
}
Register the NotifierInterface in your AppServiceProvider:
public function register()
{
$this->app->singleton(NotifierInterface::class, function ($app) {
return new Notifier([new ConexteoTransport($app['config']['services.conexteo.dsn'])]);
});
}
Verify Integration Check Conexteo’s developer dashboard for received messages.
Transport Initialization
Use the ConexteoTransport class directly or via Symfony’s Notifier:
$transport = new ConexteoTransport($dsn);
$notifier = new Notifier([$transport]);
Message Types
$message = new ChatMessage('Your OTP: 12345');
$notifier->send($message->to('+1234567890'));
$message = new EmailMessage('Welcome!');
$notifier->send($message->to('user@example.com'));
Async Processing Queue notifications for background processing:
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendWelcomeNotification implements ShouldQueue
{
use Queueable;
public function handle(NotifierInterface $notifier)
{
$notifier->send(new ChatMessage('Welcome!'));
}
}
Dynamic Sender/Recipient Fetch sender/recipient from a user model:
$user = User::find(1);
$message = new ChatMessage("Hello, {$user->name}!");
$notifier->send($message->to($user->phone));
Laravel Notifications: Extend Laravel’s Notification class to use Symfony’s Notifier:
use Illuminate\Notifications\Notification;
use Symfony\Component\Notifier\NotifierInterface;
class ConexteoNotification extends Notification
{
public function via($notifier)
{
return [ConexteoChannel::class];
}
public function toConexteo($notifier)
{
return new ChatMessage('Custom content');
}
}
Register the channel in AppServiceProvider:
$this->app->bind(ConexteoChannel::class, function ($app) {
return new ConexteoChannel($app->make(NotifierInterface::class));
});
Logging Failures
Wrap notifier->send() in a try-catch to log errors:
try {
$notifier->send($message);
} catch (\Exception $e) {
\Log::error('Conexteo notification failed', ['error' => $e->getMessage()]);
}
DSN Validation
conexteo://APP_ID:API_KEY@default?sender=SENDER.default host or invalid credentials will throw TransportException.Message Limits
if (strlen($message->getContent()) > 160) {
throw new \InvalidArgumentException('Message exceeds 160 characters.');
}
Rate Limiting
$transport->setRetryStrategy(new RetryStrategy(3, 1000)); // 3 retries, 1s delay
Recipient Format
+1234567890). Strip non-numeric characters:
$phone = preg_replace('/[^0-9]/', '', $user->phone);
Enable Debug Mode Set Symfony’s debug mode to log transport interactions:
$transport->setDebug(true);
Check logs for raw API responses/errors.
Mock Testing Use a mock transport in tests:
$mockTransport = $this->createMock(ConexteoTransport::class);
$mockTransport->method('send')->willReturn(true);
$notifier = new Notifier([$mockTransport]);
Custom Headers
Extend ConexteoTransport to add headers:
class CustomConexteoTransport extends ConexteoTransport
{
protected function getHeaders(): array
{
return array_merge(parent::getHeaders(), ['X-Custom-Header' => 'value']);
}
}
Template Engine Use Laravel’s Blade to render dynamic messages:
$content = view('notifications.conexteo_template', ['user' => $user])->render();
$message = new ChatMessage($content);
Webhook Validation If Conexteo supports webhooks, validate signatures:
use Symfony\Component\HttpFoundation\Request;
public function handleWebhook(Request $request)
{
$payload = $request->getContent();
$signature = $request->headers->get('X-Conexteo-Signature');
if (!hash_equals($signature, hash_hmac('sha256', $payload, config('services.conexteo.webhook_secret')))) {
abort(403);
}
}
.env.testing):
CONEXTEO_DSN=conexteo://TEST_APP_ID:TEST_KEY@default
config/services.php:
'conexteo' => [
'dsn' => env('CONEXTEO_DSN'),
'default_sender' => env('CONEXTEO_DEFAULT_SENDER', 'Support'),
],
Then access it in ConexteoTransport:
$sender = $this->config['default_sender'] ?? null;
How can I help you explore Laravel packages today?