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

Rocket Chat Notifier Laravel Package

symfony/rocket-chat-notifier

Symfony Notifier bridge for Rocket.Chat. Configure a rocketchat:// DSN with incoming webhook token and default channel, then send ChatMessages. Supports custom payload (alias/avatar/channel overrides) and multiple attachments for rich messages.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony-Laravel Synergy: The package leverages Symfony’s Notifier component, which aligns with Laravel’s event-driven architecture and HTTP client abstractions (Guzzle/Symfony HTTP Client). Laravel’s Service Container can easily instantiate the RocketChatNotifier as a singleton or context-bound service, reducing boilerplate for message dispatch.
  • Modular Design: The package’s DSN-based configuration (rocketchat://TOKEN@HOST?channel=CHANNEL) mirrors Laravel’s .env pattern, enabling seamless integration with Laravel’s configuration system (e.g., config('services.rocket_chat')). This avoids hardcoding credentials or URLs.
  • Event-Driven Potential: The package’s ChatMessage and RocketChatOptions classes can be extended to trigger RocketChat notifications from Laravel events (e.g., OrderShipped, UserRegistered) via listeners or queued jobs, enabling reactive workflows.
  • Payload Flexibility: The ability to customize attachments, bot identity (alias/avatar), and dynamic channels via payloads aligns with Laravel’s rich notification patterns (e.g., Slack/Teams integrations). This supports use cases like:
    • Multi-channel alerts (e.g., #engineering for deployments, #support for tickets).
    • Structured data (e.g., JSON payloads for parsing in RocketChat scripts).
  • Limitation: The package is RocketChat-specific; if multi-protocol support (e.g., Slack, Discord) is needed, a wrapper layer or abstraction (e.g., NotificationGatewayInterface) would be required.

Integration Feasibility

  • Stack Compatibility:
    • HTTP Client: Laravel’s default Guzzle client is PSR-18 compliant, matching Symfony’s HTTP client requirements. The package can be adapted to use Guzzle directly or via Symfony’s HttpClient facade.
    • Dependency Injection: Laravel’s IoC container can resolve the notifier service with minimal changes:
      $this->app->singleton(RocketChatNotifier::class, function ($app) {
          return new RocketChatNotifier(
              $app->make(HttpClient::class),
              $app->config['services.rocket_chat.dsn']
          );
      });
      
    • Configuration: Map Symfony’s DSN format to Laravel’s .env:
      ROCKET_CHAT_DSN=rocketchat://API_TOKEN@rocketchat.example.com?channel=general
      
  • Migration Path:
    1. Phase 1: Replace direct RocketChat API calls with the notifier package in a single module (e.g., alerts).
    2. Phase 2: Extend Laravel’s Event system to trigger RocketChat notifications (e.g., notified:rocket-chat event).
    3. Phase 3: Replace legacy webhook logic with the package’s RocketChatOptions for richer payloads.
  • Compatibility Risks:
    • Symfony Version Mismatch: The package targets Symfony 7+ (PHP 8.4+). Laravel 10+ uses Symfony 6.4–7.0 components, so test for API compatibility (e.g., HttpClient changes in Symfony 7).
    • PHP Version: If using PHP <8.4, the package’s Symfony 8 dependency (v8.0.0-BETA1) may block adoption. Stick to Symfony 7.x branches for broader compatibility.
    • RocketChat API Changes: The package assumes RocketChat’s webhook API remains stable. Validate against your RocketChat version (e.g., v5.x vs. v6.x).

Key Questions

  1. Symfony Dependency Impact:
    • Will the package’s Symfony 7+ dependencies conflict with Laravel’s Symfony component versions? (Test with symfony/http-client:^6.4.)
    • Can we polyfill missing Symfony features (e.g., Notifier component) or use a wrapper?
  2. Authentication Strategy:
    • How will API tokens/credentials be secured? (Laravel’s .env, Vault, or IAM?)
    • Does RocketChat support OAuth2? If so, can we extend the package for token refresh?
  3. Error Handling:
    • Does the package support retries/exponential backoff for failed API calls? If not, can Laravel’s Queue system wrap the notifier with retry logic?
  4. Payload Customization:
    • How will RocketChat’s Incoming Webhook Script be configured? Will we need to deploy custom scripts to RocketChat for payload parsing?
  5. Monitoring:
    • Are there built-in metrics (e.g., message delivery success/failure)? If not, can we instrument the notifier with Laravel’s Logging or Monitoring (e.g., Sentry)?

Integration Approach

Stack Fit

  • Laravel Core Integration:
    • Service Provider: Register the notifier as a Laravel service in AppServiceProvider:
      public function register(): void
      {
          $this->app->singleton(RocketChatNotifier::class, function ($app) {
              return new RocketChatNotifier(
                  new \Symfony\Contracts\HttpClient\HttpClient(),
                  config('services.rocket_chat.dsn')
              );
          });
      }
      
    • Facade (Optional): Create a RocketChat facade for cleaner syntax:
      use Illuminate\Support\Facades\Facade;
      
      class RocketChat extends Facade { protected static function getFacadeAccessor() { return 'rocket_chat'; } }
      
  • HTTP Client Abstraction:
    • If using Guzzle, replace Symfony’s HttpClient with Guzzle:
      use GuzzleHttp\Client;
      
      $notifier = new RocketChatNotifier(new Client(), $dsn);
      
    • For Symfony HTTP Client, ensure Laravel’s symfony/http-client package is installed (^6.4).
  • Configuration:
    • Define .env variables:
      ROCKET_CHAT_DSN=rocketchat://API_TOKEN@rocketchat.example.com?channel=general
      ROCKET_CHAT_WEBHOOK_URL=https://rocketchat.example.com/hooks/WEBHOOK_ID
      
    • Map to config/services.php:
      'rocket_chat' => [
          'dsn' => env('ROCKET_CHAT_DSN'),
          'webhook_url' => env('ROCKET_CHAT_WEBHOOK_URL'),
      ],
      

Migration Path

  1. Pilot Phase (Low Risk):
    • Replace one RocketChat API call (e.g., a deployment alert) with the notifier package.
    • Test with a dedicated channel (e.g., #dev-alerts) to avoid noise.
    • Validate payload formatting and attachment rendering.
  2. Event Integration (Medium Risk):
    • Create a Laravel Event Listener to trigger RocketChat notifications:
      use Illuminate\Support\Facades\Event;
      
      Event::listen(OrderShipped::class, function (OrderShipped $event) {
          RocketChat::sendMessage(
              '#support',
              'New order shipped: #' . $event->order->id,
              new RocketChatOptions([
                  ['title' => 'Order Details', 'text' => $event->order->toJson()]
              ])
          );
      });
      
  3. Full Replacement (High Risk):
    • Replace all custom RocketChat webhook logic with the notifier package.
    • Update legacy payloads to use RocketChatOptions for consistency.
    • Deprecate old webhook endpoints in favor of the notifier’s API.

Compatibility

  • Symfony Component Versions:
    • Use symfony/http-client:^6.4 for Laravel 10+ compatibility.
    • Avoid Symfony 7+ features (e.g., Notifier component) unless wrapped.
  • RocketChat API:
    • Test against your RocketChat version (e.g., v4.x vs. v6.x) for payload/attachment support.
    • Validate webhook script compatibility (e.g., custom scripts for payload parsing).
  • PHP Version:
    • Target PHP 8.1+ for Laravel 10+ stability.
    • If using PHP 8.0, pin the package to Symfony 6.x branches.

Sequencing

  1. Prerequisites:
    • Install symfony/http-client and symfony/notifier (if not already present).
    • Set up RocketChat webhook and API token.
    • Configure .env and config/services.php.
  2. Core Integration:
    • Implement RocketChatNotifier service provider.
    • Test basic message sending (e.g., RocketChat::sendMessage()).
  3. Advanced Features:
    • Add event listeners for domain-specific notifications.
    • Customize payloads/attachments for rich messages.
  4. Observability:
    • Add logging for failed deliveries (e.g., try-catch blocks).
    • Integrate with Laravel’s Queue system for async retries.

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