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

Rms Push Notifications Bundle Laravel Package

ddlzz/rms-push-notifications-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require richsage/rms-push-notifications-bundle:dev-master
    

    Enable the bundle in app/AppKernel.php:

    new RMS\PushNotificationsBundle\RMSPushNotificationsBundle(),
    
  2. Configuration Configure app/config/config.yml for your target platform(s). Example for GCM (Android):

    rms_push_notifications:
        android:
            gcm:
                api_key: "YOUR_GCM_SERVER_KEY"
                use_multi_curl: true
    
  3. First Use Case Inject the rms_push_notifications.notification_manager service and send a notification:

    use RMS\PushNotificationsBundle\Notification\Notification;
    
    $notification = new Notification();
    $notification->setMessage("Hello from Laravel!")
                 ->addDeviceToken("DEVICE_TOKEN_HERE");
    
    $this->get('rms_push_notifications.notification_manager')->send($notification);
    

Implementation Patterns

Core Workflow

  1. Notification Creation Use the Notification class to craft messages:

    $notification = new Notification();
    $notification->setMessage("Your order is confirmed!")
                 ->setTitle("Order Update")
                 ->setSound("default")
                 ->setBadge(1);
    
  2. Targeting Devices Add device tokens (platform-specific):

    $notification->addDeviceToken("ANDROID_TOKEN_1");
    $notification->addDeviceToken("IOS_TOKEN_2");
    
  3. Sending Notifications Dispatch via the manager:

    $this->get('rms_push_notifications.notification_manager')->send($notification);
    
  4. Batch Processing Loop through tokens and send in batches (e.g., for GCM):

    foreach ($userTokens as $token) {
        $notification->addDeviceToken($token);
        if ($notification->getDeviceTokens()->count() >= 1000) {
            $this->get('rms_push_notifications.notification_manager')->send($notification);
            $notification->clearDeviceTokens();
        }
    }
    

Integration Tips

  • Symfony Events Trigger notifications via Symfony events (e.g., kernel.terminate for delayed sends):

    $dispatcher->addListener('user.order_placed', function () use ($notificationManager) {
        $notification = new Notification();
        $notification->setMessage("Order placed!");
        $notificationManager->send($notification);
    });
    
  • Database Backing Store device tokens in a devices table (e.g., user_id, platform, token) and fetch dynamically:

    $tokens = Device::where('user_id', $userId)->pluck('token');
    
  • Custom Payloads Extend the Notification class for platform-specific payloads (e.g., deep links):

    class CustomNotification extends Notification {
        public function setDeepLink($url) {
            $this->payload['gcm']['data']['link'] = $url;
            return $this;
        }
    }
    

Gotchas and Tips

Pitfalls

  1. Deprecated Services

    • C2DM (Android): Deprecated by Google; use GCM or FCM instead.
    • Symfony 2.0: Requires the symfony2.0 branch (not dev-master).
  2. Token Management

    • Device tokens expire or change (e.g., app reinstall). Implement a token refresh mechanism (e.g., via app feedback).
  3. Rate Limits

    • GCM/FCM has quota limits. Batch sends to avoid throttling.
  4. Configuration Overrides

    • Ensure config.yml is merged correctly. Use parameters.yml for secrets:
      parameters:
          gcm_api_key: "%env(GCM_API_KEY)%"
      
      Then reference in config.yml:
      rms_push_notifications:
          android:
              gcm:
                  api_key: "%gcm_api_key%"
      

Debugging

  • Enable Logging Configure Monolog to log failed sends:

    monolog:
        handlers:
            push_notifications:
                type: stream
                path: "%kernel.logs_dir%/push_notifications.log"
                level: debug
    

    Then check logs for errors like:

    {"error": "InvalidRegistration", "message": "Invalid token"}
    
  • Dry Runs Test GCM with dry_run: true to validate payloads without sending:

    rms_push_notifications:
        android:
            gcm:
                api_key: "YOUR_KEY"
                dry_run: true
    

Extension Points

  1. Custom Platforms Extend the bundle by creating a new Platform class (e.g., for FCM):

    namespace AppBundle\Notification;
    
    use RMS\PushNotificationsBundle\Platform\AbstractPlatform;
    
    class FCMPlatform extends AbstractPlatform {
        protected $endpoint = 'https://fcm.googleapis.com/fcm/send';
        // Implement send() logic
    }
    

    Register as a service:

    services:
        app.push_notifications.fcm_platform:
            class: AppBundle\Notification\FCMPlatform
            tags:
                - { name: rms_push_notifications.platform }
    
  2. Notification Templates Create reusable templates via a factory:

    class NotificationFactory {
        public static function createOrderConfirmation($orderId) {
            $notification = new Notification();
            $notification->setTitle("Order #{$orderId}")
                         ->setMessage("Your order is on the way!")
                         ->setBadge(1);
            return $notification;
        }
    }
    
  3. Webhook Validation Validate push responses (e.g., GCM success/failure) and retry failed tokens:

    $manager->send($notification, function ($response) {
        if ($response->hasErrors()) {
            $this->retryFailedTokens($response->getErrors());
        }
    });
    
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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle