Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Esendex Notifier Laravel Package

symfony/esendex-notifier

Symfony Notifier bridge for Esendex SMS. Configure via ESENDEX_DSN (email/password, account reference, from) and send SmsMessage notifications. Supports EsendexOptions for per-message settings like accountReference and more.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup for Laravel

  1. Install the Package Use Composer to install the Symfony Notifier and Esendex bridge:

    composer require symfony/notifier symfony/esendex-notifier
    
  2. Configure the DSN Add the DSN to your .env file:

    ESENDEX_DSN=esendex://EMAIL:PASSWORD@default?accountreference=ACCOUNT_REFERENCE&from=FROM
    

    Replace placeholders with your Esendex credentials and account details.

  3. Register the Transport In a service provider (e.g., AppServiceProvider), bind the Esendex transport:

    use Symfony\Component\Notifier\Notifier;
    use Symfony\Component\Notifier\Transport\EsendexTransport;
    
    public function register()
    {
        $this->app->singleton(Notifier::class, function ($app) {
            $dsn = $app['config']['services.esendex.dsn'];
            $transport = new EsendexTransport($dsn);
            return new Notifier([$transport]);
        });
    }
    
  4. Send Your First SMS Use Laravel’s notification system or Symfony’s Notifier directly:

    use Symfony\Component\Notifier\Message\SmsMessage;
    use Symfony\Component\Notifier\Notifier;
    
    $notifier = app(Notifier::class);
    $message = new SmsMessage('+1234567890', 'Hello from Laravel!');
    $notifier->send($message);
    

First Use Case: OTP Delivery

Leverage the package to send one-time passwords (OTPs) via SMS:

use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Bridge\Esendex\EsendexOptions;

$sms = new SmsMessage('+1234567890', 'Your OTP is: 123456');
$options = (new EsendexOptions())
    ->accountReference('otp_account')
    ->reference('user_123_otp');
$sms->options($options);

$notifier->send($sms);

Implementation Patterns

Workflow: Sending SMS Notifications

  1. Compose the Message Use Laravel’s SmsMessage or Symfony’s SmsMessage:

    $message = new SmsMessage($recipientPhone, $messageBody);
    
  2. Customize with EsendexOptions Attach Esendex-specific options (e.g., account reference, scheduling):

    $options = (new EsendexOptions())
        ->accountReference('marketing_account')
        ->scheduledFor(new \DateTime('+1 hour'));
    $message->options($options);
    
  3. Send via Notifier Use Laravel’s Notifier facade or inject the Symfony Notifier:

    Notifier::send($message);
    // OR
    $notifier->send($message);
    

Integration with Laravel Notifications

Extend Laravel’s Notification class to use the Esendex bridge:

use Illuminate\Notifications\Notification;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Bridge\Esendex\EsendexOptions;

class EsendexSmsNotification extends Notification
{
    public function via($notifiable)
    {
        return ['esendex_sms'];
    }

    public function toEsendexSms($notifiable)
    {
        $message = new SmsMessage($notifiable->phone, 'Your notification message');
        $options = (new EsendexOptions())
            ->accountReference('notifications_account');
        $message->options($options);
        return $message;
    }
}

Register the channel in config/notifications.php:

'channels' => [
    'esendex_sms' => [
        'driver' => 'esendex',
    ],
],

Async Processing with Queues

Use Laravel queues to handle Esendex sends asynchronously:

  1. Dispatch the Notification

    $user->notify(new EsendexSmsNotification());
    
  2. Configure the Queue Worker Ensure your queue worker processes the job:

    php artisan queue:work
    

Handling Delivery Status

Esendex provides webhooks for delivery status updates. Set up a Laravel route to handle them:

Route::post('/esendex/webhook', function (Request $request) {
    // Parse Esendex webhook payload
    $status = $request->input('status');
    $messageId = $request->input('messageId');

    // Log or update database
    \Log::info("Esendex message $messageId status: $status");
});

Configure Esendex to send webhooks to this endpoint in their dashboard.


Gotchas and Tips

Pitfalls

  1. DSN Configuration Errors

    • Issue: Incorrect DSN format or missing credentials cause silent failures.
    • Fix: Validate the DSN structure and test with a minimal setup:
      ESENDEX_DSN=esendex://test@example.com:password@default?accountreference=test_account&from=TEST
      
    • Debug: Check Symfony’s Notifier logs for connection errors.
  2. Account Reference Mismatch

    • Issue: Messages fail if the accountreference in the DSN doesn’t match Esendex’s configured account.
    • Fix: Override per-message with EsendexOptions:
      $options->accountReference('correct_account_ref');
      
  3. Character Limits

    • Issue: Esendex enforces SMS length limits (e.g., 160 characters per message). Long messages may be split or fail.
    • Fix: Use EsendexOptions to set concatenated for long messages:
      $options->concatenated(true);
      
  4. Webhook Verification

    • Issue: Esendex webhooks may be rejected if Laravel’s endpoint doesn’t verify the request signature.
    • Fix: Implement signature verification (e.g., using Esendex’s X-Esendex-Signature header).

Debugging Tips

  1. Enable Notifier Debug Mode Configure Symfony’s Notifier to log transport interactions:

    $transport = new EsendexTransport($dsn, [
        'debug' => true,
    ]);
    
  2. Inspect Raw API Calls Use Laravel’s logging to capture Esendex API requests:

    \Log::debug('Esendex API Request:', [
        'url' => $request->getUri(),
        'body' => $request->getContent(),
    ]);
    
  3. Test with Sandbox Credentials Use Esendex’s sandbox environment for testing:

    ESENDEX_DSN=esendex://sandbox@example.com:password@default?accountreference=sandbox_account&from=SANDBOX
    

Extension Points

  1. Custom EsendexOptions Extend EsendexOptions to add project-specific settings:

    class CustomEsendexOptions extends EsendexOptions
    {
        public function customTag(string $tag): self
        {
            $this->options['custom_tag'] = $tag;
            return $this;
        }
    }
    
  2. Override Transport Behavior Create a custom transport class to modify API calls:

    use Symfony\Component\Notifier\Transport\EsendexTransport as BaseTransport;
    
    class CustomEsendexTransport extends BaseTransport
    {
        protected function doSend(SmsMessage $message): void
        {
            // Custom logic before sending
            $this->client->request('POST', '/messages', [
                'json' => [
                    'to' => $message->getPhone(),
                    'text' => $message->getContent(),
                    'custom_tag' => 'my_tag',
                ],
            ]);
        }
    }
    
  3. Add Support for Email While the package focuses on SMS, you can extend it for email by creating a custom message class:

    use Symfony\Component\Notifier\Message\EmailMessage;
    
    class EsendexEmailMessage extends EmailMessage
    {
        public function __construct(string $to, string $subject, string $html = null, string $text = null)
        {
            parent::__construct($to, $subject, $html, $text);
        }
    }
    

Configuration Quirks

  1. DSN Parameters

    • from: Must match Esendex’s configured sender IDs (alphanumeric).
    • accountreference: Required for API calls; defaults to the DSN value but can be overridden per-message.
  2. Rate Limiting

    • Esendex enforces rate limits. Handle TooManyRequests exceptions gracefully:
      try {
          $notifier->send($message);
      } catch (\Symfony\Component\Notifier\Exception\TransportException $e) {
          if ($e->getCode() === 429) {
              \Log::warning('Esendex rate
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky