Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Expose Notification Id within Message Data #31632

Merged
merged 5 commits into from
Feb 28, 2020

Conversation

harlan-zw
Copy link
Contributor

@harlan-zw harlan-zw commented Feb 28, 2020

This is a pretty edge case scenario so i'll start with what i'm trying to do.

I'm logging all notifications that the application is sending (similar to Telescope), and i'd like to setup webhooks with my providers (mailgun, twilio, etc) so I can mark off notifications statuses as well as opens, clicks, etc. Currently these are implemented using theIlluminate\Notifications\Events\* events

public function handle(NotificationSending $event)
    {
        Notification::forceCreate([
            'notification_id' => $event->notification->id,
            'status' => Notification::STATUS_SENDING,
            'channel' => $event->channel,
            'notifiable_id' => $event->notifiable->getKey(),
            'to' => $event->notifiable->routeNotificationFor($event->channel)
        ]);
    }

Starting with the mail implementation, within the context of the two Mail Events: Illuminate\Mail\Events\MessageSent and Illuminate\Mail\Events\MessageSending, there is no way of referencing exactly which instance of a Notification class has sent it. For my implementation to work I need the message id so I can match them up with the webhook calls.

public function handle(MessageSent $event)
    {
        // find the notification for the given id and set the message id
        Notification::where('notification_id', $event->data['__laravel_notification_id'])
                ->update(['message_id' => $event->message->getId()]);
    }

Hopefully this makes sense, i'm sure there's other use cases for exposing the id beyond my own.

@taylorotwell taylorotwell merged commit 6979b11 into laravel:6.x Feb 28, 2020
voku added a commit to voku/framework that referenced this pull request Mar 2, 2020
* upstream/6.x: (21 commits)
  Revert "[6.x] migrate --seed should seed the same database (laravel#31678)" (laravel#31685)
  [6.x] Allow easier customization of the queued mailable job (laravel#31684)
  [6.x] migrate --seed should seed the same database (laravel#31678)
  [6.x] Make newPivotQuery public (laravel#31677)
  [6.x] update changelog
  Fix flakey memcached tests (laravel#31646)
  Fixed phpdoc
  formatting
  [6.x] Expose Notification Id within Message Data (laravel#31632)
  [6.x] Add support for Arr::hasAny (laravel#31636)
  Fix phpdoc
  [6.x] update changelog
  [6.x] update changelog
  Fix styling for phpdoc
  Create resolve method which loads deferred providers if needed
  Revert "Call make instead of resolve to load deffered providers"
  Call make instead of resolve to load deffered providers
  Add test that failes to load deffered provider of implementation while accessing class through interface
  Use correct locale when resolving Faker from the container (laravel#31615)
  clean-up-some-methods
  ...

# Conflicts:
#	src/Illuminate/Database/DatabaseServiceProvider.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants