Jump to content

Developer Documentation

Sending Notifications to Users

1. Create an extension

The first step is to create a Notifications extension. In the Developer Center for your application go to Extensions > core and click the "+" button on the "Notifications" row. A file will be created in your application's extensions/core/Notifications folder with a skeleton to get you started. Open that file and follow the instructions within it to add your notification types to the Notification Options screen and create the method(s) which will control what gets displayed when the user clicks on the notification icon in the header.

 

2. Create an Email Template

You must create the email templates for what will get sent to users who have opted to receive emails for your notification. Follow the instructions from Steps 1-2 of the Emails guide. For your templates, use notification_key as the key (where key is the notification key you specify in getConfiguration()). For example: the notification type new_status (in the core application) uses the email templates notification_new_status which for it's subject uses the language string mailsub__core_notification_new_status.

 

3. Send the Notification

The actual code to send the notification is very simple:

$notification = new \IPS\Notification( \IPS\Application::load('app'), 'key', $item, $params ); 
$notification->recipients->attach( \IPS\Member::load(1) ); 
$notification->send();
  • $item
    Should be an object of the thing the notification is about, which is used to prevent the same notification being sent more than once or NULL if not applicable. If it is a content item (it doesn't have to be, but if it is) the notification will automatically remove the recipient if they don't have permission to read the item or are ignoring the user who posted it.
  • $params
    Any parameters that you want to pass to the email template.

You call $notification->recipients->attach() for each member you want to send the notification to, passing an \IPS\Member object.


  Report Document


×
×
  • Create New...