How to tie into the notification system?

  1. 4 years ago

    The code is a little over my head. I am trying to understand the best way to tie into the API system. The only way I figured it out is to insert a trigger event into the core code. I don't understand how the variables get passed through to the handler. I tried inserting my own variable as a test and it contains content from another variable. I am trying to build a plugin and have a rough skeleton going, but this part is a roadblock for me. Also, I would rather not have to insert a new trigger notification, so if anyone knows a better way with the existing codebase, please let me know.

    Here is the link I am using:

    $this->trigger("remoteNotification", array($testVar)); 
    public function handler_activityModel_remoteNotification($testVar)
  2. What are you trying to do? If you're just trying to add a notification there's support for that

    If you're trying to hook into it in order to modify/override something with the notification itself, yeah you may need to do some manual work. We always welcome pull requests on github :)

  3. Edited 4 years ago by 19eighties

    @Thirtysixway, I am trying to add push notifications using a third party API. Basically it would function like sending an email. I am stumped on how to hook in properly. I have something sort of working based on the SMTP plugin now, but I am getting phpmailer errors and it's a little hackish since I have to scrub the message for the URL to send from the email template, etc. I would like to be able to add the notification like the others so that they comply with the rest of the system.

  4. I figured out the phpmailer error was unrelated and is probably my php config. The code I have works fine on a remote host.

    So I'm wondering if I hook into the sendemailbefore trigger, can I somehow get the URL to the new post as a defined entity? Scrubbing the email template with regex may not always be reliable.

  5. Edited 4 years ago by 19eighties

    To revisit what I said earlier:

    @19eighties Here is the link I am using:

    $this->trigger("remoteNotification", array($testVar)); 
    public function handler_activityModel_remoteNotification($testVar)

    I'd like to be able to pass the $member, $item and $activity variables to the "remoteNotification" handler in the plugin script. However, ideally I would not need to add a trigger into the core code since it is a manual edit. I would also need to get the user's preference to check if they enabled push notifications. The other option I found that kind of works is the built-in "sendEmailBefore" trigger, but I would also need the $item variable and perhaps $member and $activity.

  6. Toby

    4 Jun 2015 Administrator
    Edited 4 years ago by Toby

    This should do the trick: f1fbacd

    Now you can implement something like:

    public function handler_activityModel_sendNotification($sender, $activity, $member)
        if (!empty($member["preferences"]["push.".$activity["type"]])) {
            // do your thing here, all info you need should be in $activity and $member
  7. @Toby , thanks for the response. I tried inserting a trigger almost identical to that one (different name) in that location and nothing would happen. Then I moved it to the spot above the email code section and it worked. I think I still could not pass variable through to the handler in the plugin even after moving the trigger. I'll try again and report back. :)

  8. Edited 4 years ago by 19eighties

    @Toby, I tried it, so I noticed I did not include $sender in the handler function, and including $sender made $activity and $member available. Why does $sender have that effect?

    I just realized my mail send issue on my localhost is probably what is preventing the trigger from executing where you placed it and where I had it earlier, so now that issue makes sense.

  9. Toby

    4 Jun 2015 Administrator

    The first parameter passed to event listeners is always the sender of the event, so in this case it will be the instance of the ETActivityModel class.


or Sign Up to reply!