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

Mattermost Notifier Laravel Package

symfony/mattermost-notifier

Symfony Notifier integration for Mattermost. Configure via DSN (access token, host/path, default channel) and send ChatMessage notifications, optionally overriding the recipient channel with MattermostOptions.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event-Driven Alignment: The package aligns well with Laravel’s event system (e.g., Illuminate\Events\Dispatcher), enabling seamless integration for asynchronous notifications like job failures, system alerts, or user actions. Its PSR-15 middleware support complements Laravel’s middleware stack (e.g., Illuminate\Pipeline), facilitating request/response handling.
  • Decoupling: The Symfony Notifier’s interface-based design (Notifier, Transport) allows for easy abstraction, enabling Laravel to mock or swap providers (e.g., Mattermost ↔ Slack) without refactoring business logic. This is particularly useful for Laravel’s dependency injection system.
  • Laravel Compatibility: While Symfony’s HttpClient is not native to Laravel, the package’s core functionality (DSN-based configuration, ChatMessage objects) can be adapted using Laravel’s Http client or Guzzle. The PSR-15 middleware can be replaced with Laravel’s middleware, ensuring compatibility.
  • Use Case Suitability: Ideal for internal tooling (e.g., CI/CD alerts, error tracking) or low-code integrations where Mattermost is the primary communication channel. Less suited for high-frequency user-facing notifications (e.g., real-time chat) due to Laravel’s synchronous HTTP handling by default.

Integration Feasibility

  • Webhook-Based: Mattermost’s webhook API is robust and widely adopted, reducing integration complexity. Laravel’s Http client or Guzzle can handle POST requests to Mattermost’s endpoint with minimal boilerplate.
  • Configuration: The DSN format (mattermost://TOKEN@HOST/PATH?channel=ID) can be mapped to Laravel’s .env or config/mattermost.php for centralized management. Example:
    MATTERMOST_DSN=mattermost://${MATTERMOST_TOKEN}@${MATTERMOST_HOST}/api/v4/posts?channel=${DEFAULT_CHANNEL}
    
  • Event Mapping: Laravel’s Event facade can trigger notifications via the package’s Notifier interface. For example:
    use Symfony\Component\Notifier\Notifier;
    use Symfony\Component\Notifier\Message\ChatMessage;
    
    // In a Laravel event listener:
    public function handle(JobFailed $event) {
        $notifier = new Notifier(new MattermostTransport($this->mattermostDsn));
        $notifier->send(new ChatMessage('Job failed: ' . $event->job->name));
    }
    
  • Message Customization: The MattermostOptions class allows per-message channel overrides, which can be extended in Laravel via dynamic properties or service providers.

Technical Risk

  • Symfony Dependency:
    • Namespace Collisions: Symfony’s Notifier namespace may conflict with Laravel’s autoloading. Mitigation: Use composer.json aliases or PSR-4 prefixes (e.g., Symfony\Component\Notifier\Bridge\Mattermost).
    • Lack of Laravel-Specific Docs: No native Laravel examples require adaptation (e.g., replacing Symfony’s ContainerInterface with Laravel’s Illuminate\Contracts\Container\Container).
  • Webhook Reliability:
    • Mattermost webhooks are HTTP-based; Laravel’s queue system (e.g., Illuminate\Queue) should wrap notifications to handle retries/failures. Example:
      $notifier->send($message)->then(function () {
          // Success
      })->otherwise(function ($e) {
          Log::error('Mattermost notification failed', ['error' => $e]);
      });
      
  • Message Formatting:
    • Mattermost’s markdown/slack-compatible formatting may need Laravel-specific templating (e.g., Blade). Example:
      $message = new ChatMessage(Blade::render('notifications.job-failed', ['job' => $event->job]));
      
  • Performance:
    • Synchronous webhook calls may block HTTP requests. Mitigation: Use Laravel’s dispatchSync() or queue the notification.

Key Questions

  1. Use Case Scope:
    • Will this replace existing Laravel notifications (e.g., Notifiable trait) or augment them? If augmenting, how will conflicts (e.g., duplicate alerts) be resolved?
  2. Authentication:
    • How will Mattermost tokens be secured (e.g., .env, Laravel Vault, AWS Secrets Manager)?
  3. Error Handling:
    • How will failed webhook deliveries be logged/retryed (e.g., Laravel’s FailedJob table, dead-letter queues)?
  4. Performance:
    • Will notifications be synchronous (blocking) or asynchronous (queued)? If synchronous, what’s the fallback for slow Mattermost responses?
  5. Testing:
    • How will mock Mattermost responses be implemented (e.g., Laravel’s Http client mocking, PestPHP assertions)?
  6. Scaling:
    • How will rate limits or high-volume notifications be handled (e.g., batching, exponential backoff)?
  7. Maintenance:
    • Who will own updates (e.g., Symfony version bumps, Mattermost API changes)? Will this be a vendor package or a custom fork?

Integration Approach

Stack Fit

  • Laravel Core:
    • Events: Trigger notifications via Laravel’s Event facade or dispatch() helper.
    • Queue System: Offload webhook calls to queue:work for reliability (e.g., Illuminate\Bus\Queueable).
    • Service Container: Bind the Notifier interface to a Laravel-specific implementation in AppServiceProvider:
      public function register() {
          $this->app->bind(\Symfony\Component\Notifier\Notifier::class, function ($app) {
              return new \Symfony\Component\Notifier\Notifier(
                  new \Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransport(
                      config('mattermost.dsn')
                  )
              );
          });
      }
      
    • Http Client: Replace Symfony’s HttpClient with Laravel’s Http client or Guzzle for consistency.
  • Symfony Bridge:
    • Use the package as a composer dependency without tight coupling. Example composer.json:
      {
        "require": {
          "symfony/notifier": "^6.4",
          "symfony/http-client": "^6.4",
          "guzzlehttp/guzzle": "^7.0" // Optional: For Laravel Http client compatibility
        },
        "replace": {
          "symfony/http-client": "guzzlehttp/guzzle" // Optional: Swap for Laravel's Http client
        }
      }
      
  • Alternatives:
    • For minimalism, use Laravel’s Http client directly with Mattermost’s API (avoids Symfony dependency).
    • For Symfony-heavy apps, consider spatie/laravel-notification-channels-mattermost (Laravel-specific).

Migration Path

  1. Phase 1: Proof of Concept (1–2 weeks)

    • Replace a single Laravel notification channel (e.g., email) with Mattermost.
    • Steps:
      1. Add the Symfony notifier to composer.json.
      2. Configure the DSN in .env:
        MATTERMOST_DSN=mattermost://${MATTERMOST_TOKEN}@${MATTERMOST_HOST}/api/v4/posts?channel=${DEFAULT_CHANNEL}
        
      3. Create a test event listener to send a Mattermost notification:
        use Symfony\Component\Notifier\Notifier;
        use Symfony\Component\Notifier\Message\ChatMessage;
        
        class SendMattermostAlert
        {
            public function __construct(private Notifier $notifier) {}
        
            public function handle(JobFailed $event) {
                $this->notifier->send(new ChatMessage('Job failed: ' . $event->job->name));
            }
        }
        
      4. Register the listener in EventServiceProvider:
        protected $listen = [
            JobFailed::class => [SendMattermostAlert::class],
        ];
        
      5. Test with a manual event dispatch:
        event(new JobFailed((new Job)->name('test-job')));
        
  2. Phase 2: Full Integration (2–4 weeks)

    • Create a Laravel-specific wrapper for the Symfony notifier to handle:
      • Laravel’s Notification classes (extend Illuminate\Notifications\Notification).
      • Queueable notifications (implement ShouldQueue).
      • Blade templating for message content.
    • Example wrapper:
      namespace App\Notifications\Channels;
      
      use Symfony\Component\Notifier\Notifier;
      use Symfony\Component\Notifier\Message\ChatMessage;
      use Illuminate\Notifications\Notification;
      
      class MattermostChannel
      {
          public function __construct(private Notifier $notifier) {}
      
          public function send($notifiable, Notification $notification) {
              $message = $notification->toMattermost($notifiable);
              $this->notifier->send($message);
          }
      }
      
    • Extend Laravel’s Notification class to support Mattermost:
      namespace App\Notifications;
      
      use Illuminate\Notifications\Notification;
      use App\Notifications
      
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.
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
spatie/mailcoach-vapor
spatie/laravel-javascript-views