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

Linked In Notifier Laravel Package

symfony/linked-in-notifier

Symfony Notifier integration for LinkedIn. Configure a LINKEDIN_DSN with your LinkedIn access token and user ID to send notifications via LinkedIn through Symfony’s notifier system.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup for Laravel

  1. Install the Package (via Composer):

    composer require symfony/linked-in-notifier
    

    Note: Laravel may require additional adapters for Symfony dependencies.

  2. Configure DSN in .env:

    LINKEDIN_DSN=linkedin://ACCESS_TOKEN:USER_ID@default
    
  3. Set Up Symfony Notifier in Laravel: Since Laravel lacks native Symfony Notifier support, use a bridge like spatie/laravel-symfony-notifier or manually integrate the transport:

    use Symfony\Component\Notifier\Notifier;
    use Symfony\Component\Notifier\Transport\LinkedInTransport;
    
    $notifier = new Notifier();
    $transport = new LinkedInTransport($_ENV['LINKEDIN_DSN']);
    $notifier->send(new Message('Hello from Laravel!'), $transport);
    
  4. First Use Case: Send a Notification Trigger a notification via a Laravel controller or command:

    use Symfony\Component\Notifier\Message\ChatMessage;
    
    $message = new ChatMessage('Your application was viewed!');
    $notifier->send($message, $transport);
    

Implementation Patterns

Workflows

  1. Authentication Flow:

    • Obtain a LinkedIn API token via OAuth (use LinkedIn’s OAuth guide).
    • Store the token securely (e.g., Laravel’s env or a secrets manager like laravel/vault).
  2. Notification Types:

    • Chat Messages: Send direct messages to users (e.g., job application updates).
      $message = new ChatMessage('Interview scheduled for June 10!');
      $notifier->send($message, $transport);
      
    • Profile Updates: Trigger notifications for profile views or connection requests (requires webhook setup; see Gotchas).
  3. Event-Driven Notifications:

    • Use Laravel’s Event system to dispatch notifications:
      event(new JobApplicationViewed($user, $recruiter));
      
      Then listen and send via Notifier:
      JobApplicationViewed::listen(function ($event) {
          $message = new ChatMessage("Recruiter {$event->recruiter->name} viewed your profile!");
          $notifier->send($message, $transport);
      });
      
  4. Batch Processing:

    • Queue notifications for efficiency (Laravel Queues + Symfony Notifier):
      $notifier->send(
          new ChatMessage('Weekly digest'),
          $transport,
          ['delay' => 3600] // Delay 1 hour
      );
      

Integration Tips

  • Laravel-Symfony Bridge:

    • Replace Symfony’s HttpClient with Laravel’s Http facade:
      use Illuminate\Support\Facades\Http;
      
    • Mock Messenger with Laravel Queues by extending the transport:
      class LaravelLinkedInTransport extends LinkedInTransport
      {
          public function __construct(string $dsn)
          {
              parent::__construct($dsn);
              $this->client = Http::withOptions(['timeout' => 10]);
          }
      }
      
  • Webhook Handling:

    • Use Laravel’s Route::post('/linkedin/webhook', ...) to verify and process LinkedIn webhooks:
      Route::post('/linkedin/webhook', function (Request $request) {
          $challenge = $request->input('oauth_challenge');
          return response()->json(['oauth_challenge' => $challenge]);
      });
      
    • Validate signatures using LinkedIn’s webhook verification.
  • Testing:

    • Mock the transport in Laravel tests:
      $transport = $this->createMock(LinkedInTransport::class);
      $transport->method('send')->willReturn(true);
      $notifier = new Notifier([$transport]);
      

Gotchas and Tips

Pitfalls

  1. Symfony Dependency Conflicts:

    • The package assumes Symfony’s HttpClient and Messenger. Laravel may throw errors if these are missing.
    • Fix: Use a custom transport class (as shown above) or install Symfony’s components via Composer:
      composer require symfony/http-client symfony/messenger
      
  2. Token Expiry:

    • LinkedIn access tokens expire (typically 60 days). Implement a token refresh mechanism:
      // Example: Refresh token via Laravel command
      Artisan::command('linkedin:refresh-token', function () {
          $token = LinkedIn::refreshAccessToken();
          config(['services.linkedin.token' => $token]);
      });
      
  3. Rate Limits:

    • LinkedIn enforces rate limits. Implement retries with exponential backoff:
      use Symfony\Component\Notifier\Exception\TransportException;
      
      try {
          $notifier->send($message, $transport);
      } catch (TransportException $e) {
          if ($e->getCode() === 429) {
              sleep(10); // Retry after 10 seconds
              retry();
          }
      }
      
  4. Webhook Challenges:

    • LinkedIn webhooks require challenge validation. Laravel’s middleware must return the challenge verbatim:
      Route::post('/webhook', function (Request $request) {
          $challenge = $request->input('oauth_challenge');
          return response()->json(['oauth_challenge' => $challenge]);
      });
      
    • Gotcha: Forgetting to return the challenge will fail LinkedIn’s verification.
  5. User ID Format:

    • LinkedIn USER_ID must be a numeric ID (e.g., 123456789), not an email or vanity URL.
    • Fix: Fetch the ID via LinkedIn’s API after OAuth:
      $user = Http::withToken($accessToken)->get('https://api.linkedin.com/v2/me')->json();
      $userId = $user['id']; // e.g., "123456789"
      

Debugging Tips

  • Enable Notifier Debugging:

    $notifier = new Notifier([$transport], [
        'debug' => true,
    ]);
    

    This logs raw API responses to storage/logs/laravel.log.

  • Check LinkedIn API Status:

  • Validate DSN Format:

    • Ensure the DSN follows linkedin://ACCESS_TOKEN:USER_ID@default. A malformed DSN will throw:
      Symfony\Component\Notifier\Exception\InvalidArgumentException
      

Extension Points

  1. Custom Message Types: Extend Symfony\Component\Notifier\Message\MessageInterface for LinkedIn-specific payloads:

    class LinkedInJobAlertMessage implements MessageInterface
    {
        public function __construct(private string $jobId, private string $title) {}
    
        public function getContent(): string
        {
            return "New job alert: {$this->title} (ID: {$this->jobId})";
        }
    }
    
  2. Add Rich Media: LinkedIn supports rich messages with images/buttons. Extend the transport:

    class RichLinkedInTransport extends LinkedInTransport
    {
        public function send(MessageInterface $message, array $failedRecipients = []): void
        {
            $payload = [
                'text' => $message->getContent(),
                'attachments' => [
                    [
                        'title' => 'Apply Now',
                        'url' => 'https://example.com/job/{$jobId}',
                    ],
                ],
            ];
            $this->client->post('/v2/conversations', $payload);
        }
    }
    
  3. Queue Notifications: Dispatch notifications to Laravel Queues for async processing:

    class SendLinkedInNotification implements ShouldQueue
    {
        use Dispatchable, InteractsWithQueue, Queueable;
    
        public function handle()
        {
            $notifier->send($this->message, $this->transport);
        }
    }
    
  4. Monitor Deliveries: Track failed notifications with Laravel’s failed_jobs table:

    $notifier->send($message, $transport)->then(
        function () { Log::info('Notification sent'); },
        function ($e) { Log::error('Notification failed: '.$e->getMessage()); }
    );
    
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai