How to send notifications to users (using OssnNotifications class)

Rishi B Posted in Component Development 6 years ago

Hey everyone, I'm working on a custom component and am having trouble figuring out exactly how to dispatch a notification to a user. I was hoping there was some simple function I could call that took care of everything. Can I use OssnNotifications->add() in this way, or do I need to first setup some kind of hooks and/or callback functions? Thanks

Replies
gb Rishi B Replied 6 years ago

@Villianer, it's hard to tell exactly what you're asking, but as Z-Man explained, existing events that trigger notifications already provide links to the content being referenced. You may want to look at the ossn_notifications table to see how different types of notifications are handled (the 'type' field specifically) and also refer to Arsalan's posts below and the OssnNotifications class. For example, if you look at the ossn_notifications table, you'll see records with types such as like 'like:post' or 'comment:post'. The links to these notifications will already take you the post or comment in question (in this example). If you want to create a new type of OssnNotification, follow Arsalan's instructions.

German Michael Zülsdorff Replied 6 years ago

@Villianer
Let's say you posted 'Christmas without snow is not a real Christmas', and you got a notification 'Rudolph Reindeer' commented on your post'
All you have to do is click on that notification and you'll be forwarded to your posting.
So what's missing? And to stay with my example: What's a little description supposed to look like in this case?

us Villianer Velasquez Replied 6 years ago

oops i certainly did not mean to post that two times. my apologies

us Villianer Velasquez Replied 6 years ago

Hello guys,
I was reading along here and I came up with a question that honestly i haven't been able to answer myself since I have not the time to research on it. My users have been complaining that they do not see what post the notifications are for in the drop down menu for them. Is there a way to maybe put a small description there of the post or what have you so they can see what the notification is for. if that even makes sense. :-)

Like if someone likes a post on the news feed and it sends a notification, what post is it for?

us Villianer Velasquez Replied 6 years ago

is there a way to add a small description to the notifications because at the moment my users complain about not being able to see what post the notifications are for when they first see them in the notifications drop down.

Indonesian Arsalan Shah Replied 6 years ago

The callback you mentioned is when wall post is created the function is triggered the above callback will only work when the wall post is created.

If you see the OssnNotifications you will find if there is no hook for notification:add the notifications are not added.

The type is a unique identification for the notification for example type can be 'mycomponentnotification'

us Randy Jung Replied 6 years ago

I too am interested in this...any info is greatly appricieated

gb Rishi B Replied 6 years ago

Thanks Arsalan. Can you explain what the type argument is? Maybe an example?

Also, I've noticed that some components use callback functions rather than hooks to dispatch notifications, which seems to be done via ossn-trigger-callback (underscores, not dashes). What's the difference in this case? I'm basically just trying to get the bare minimum working as far as notifications go, any more example code would be very much appreciated.

follow-up edit: so what I'm trying to do is dispatch a notification when a wall post (to the newsfeed) is created and after my component's code has been run (aside from the notification I would like to add, the component is working fine). Would I use a hook of type 'post:created'? I see there is already a callback function registered for that type in OssnNotifications/ossn_com.php:32:

ossn_register_callback("wall", "post:created", "ossn_notification_walltag");

is it ok to register another callback, or would I use a hook? and how does one figure out which to use?

thanks!

Indonesian Arsalan Shah Replied 6 years ago

The correct way is to call OssnNotification->add() however you need some hooks like notification:view, and notification:add

<?php

function init_function(){
    ossn_add_hook('notification:view', 'notification:type', 'notification_view');
    ossn_add_hook('notification:add', 'notification:type', 'notification_add_config');    
}
function notification_view($hook, $type, $return, $params){
            see the notifcation:view of other components
            return //   
}   
function notification_add_config($hook, $type, $return, $params){
            $params['owner_guid'] = $params['notification_owner']
            ..
            ..
            .. 
            return $params
}

then you can add following to add notifcation

    $notification = new OssnNotifications;
    $notification->add(type, guid of user who will see notification, subject guid which cause this notification....);
Premium Version

Due to the many requests in the past for additonal features and components we have decided to develope a premium version. Features like Hashtags, Videos, Polls, Events, Stories, Link Preview, etc included in it.

$199 (Life Time)
Learn More

Other Questions