Notifications / Action Triggers

Introduction

Action Triggers give administrators the ability to set up actions for specific events. They are useful for notification events such as hold notifications.

To access the Action Triggers module, select AdministrationLocal AdministrationNotifications / Action triggers.

You must have Local Administrator permissions to access the Action Triggers module.

You will notice four tabs on this page: Event Definitions, Hooks, Reactors and Validators.

Event Definitions

Event Definitions is the main tab and contains the key fields when working with action triggers. These fields include:

Table 1: Action Trigger Event Definitions

Field

Description

Owning Library

The shortname of the library for which the action / trigger / hook is defined.

Name

The name of the trigger event, that links to a trigger event environment containing a set of fields that will be returned to the Validators and/or Reactors for processing.

Hook

The name of the trigger for the trigger event. The underlying action_trigger.hook table defines the Fieldmapper class in the core_type column off of which the rest of the field definitions "hang".

Enabled

Sets the given trigger as enabled or disabled. This must be set to enabled for the Action trigger to run.

Processing Delay

Defines how long after a given trigger / hook event has occurred before the associated action ("Reactor") will be taken.

Processing Delay Context Field

Defines the field associated with the event on which the processing delay is calculated. For example, the processing delay context field on the hold.capture hook (which has a core_type of ahr) is capture_time.

Processing Group Context Field

Used to batch actions based on its associated group.

Reactor

Links the action trigger to the Reactor.

Validator

The subroutines receive the trigger environment as an argument and return either 1 if the validator is true or 0 if the validator returns false.

Event Repeatability Delay

Allows events to be repeated after this delay interval.

Failure Cleanup

After an event is reacted to and if there is a failure a cleanup module can be run to clean up after the event.

Granularity

Used to group events by how often they should be run. Options are Hourly, Daily, Weekly, Monthly, Yearly, but you may also create new values.

Max Event Validity Delay

Allows events to have a range of time that they are valid. This value works with the Processing Delay to define a time range.

Message Library Path

Defines the org_unit object for a Patron Message Center message.

Message Template

A Template Toolkit template that can be used to generate output for a Patron Message Center message. The output may or may not be used by the reactor or another external process.

Message Title

The title that will display on a Patron Message Center message.

Message User Path

Defines the user object for a Patron Message Center message.

Opt-In Settings Type

Choose which User Setting Type will decide if this event will be valid for a certain user. Use this to allow users to Opt-In or Opt-Out of certain events.

Opt-In User Field

Set to the name of the field in the selected hook’s core type that will link the core type to the actor.usr table.

Success Cleanup

After an event is reacted to successfully a cleanup module can be run to clean up after the event.

Template

A Template Toolkit template that can be used to generate output. The output may or may not be used by the reactor or another external process.

Creating Action Triggers

  1. From the top menu, select AdministrationLocal AdministrationNotifications / Action triggers.

  2. Select the New Event Definition button.

    New Event Definition
  3. Select an Owning Library.

  4. Create a unique Name for your new action trigger.

  5. Select the Hook.

  6. Check the Enabled check box.

  7. Set the Processing Delay in the appropriate format. E.g. 7 days to run 7 days from the trigger event or 00:01:00 to run 1 hour after the Processing Delay Context Field.

  8. Set the Processing Delay Context Field and Processing Group Context Field.

  9. Select the Reactor and Validator.

  10. Set the Event Repeatability Delay.

  11. Select the Failure Cleanup and Granularity.

    Event Definition Details
  12. Set the Max Event Validity Delay.

  13. If you wish to send a User Message through the Message Center, set a Message Library Path. Enter text in the Message Template. Enter a title for this message in Message Title, and set a value in Message User Path.

  14. Select the Opt-In Setting Type.

  15. Set the Opt-In User Field.

  16. Select the Success Cleanup.

  17. Enter text in the Template text box if required. These are for email messages. Here is a sample template for sending 90 day overdue notices:

    [%- USE date -%]
    [%- user = target.0.usr -%]
    To: [%- params.recipient_email || user.email %]
    From: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %]
    Subject: Overdue Items Marked Lost
    Auto-Submitted: auto-generated
    Dear [% user.family_name %], [% user.first_given_name %]
    The following items are 90 days overdue and have been marked LOST.
    [%- params.recipient_email || user.email %][%- params.sender_email || default_sender %]
    [% FOR circ IN target %]
      Title: [% circ.target_copy.call_number.record.simple_record.title %]
      Barcode: [% circ.target_copy.barcode %]
      Due: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]
      Item Cost: [% helpers.get_copy_price(circ.target_copy) %]
      Total Owed For Transaction: [% circ.billable_transaction.summary.total_owed %]
      Library: [% circ.circ_lib.name %]
    [% END %]
    [% FOR circ IN target %]
      Title: [% circ.target_copy.call_number.record.simple_record.title %]
      Barcode: [% circ.target_copy.barcode %]
      Due: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]
      Item Cost: [% helpers.get_copy_price(circ.target_copy) %]
      Total Owed For Transaction: [% circ.billable_transaction.summary.total_owed %]
      Library: [% circ.circ_lib.name %]
    [% END %]
  18. Once you are satisfied with your new event trigger, click the Save button located at the bottom of the form.

A quick and easy way to create new action triggers is to clone an existing action trigger.

Creating Alternate Message Templates

As of version 3.9 there is the ability to create alternate templates for Action Triggers that will generate locale specific out for Action Triggers. If you send notices in multiple languages, we recommend putting some words to that effect in your notice templates. The template, message and message title can all be localized. To use the feature the following UI elements have been added:

  • When you double-click on an Event Definition under Notifications / Action Triggers to edit it there will be a tab option for Edit Alternate Template if the reactor is ProcessTemplate, SendEmail, or SendSMS. Note that this feature does not automatically translate existing templates, and an Evergreen administrator must create new alternate templates for each desired locale.

  • In the Patron Registration and Patron Editor screens staff members may select a locale for a patron and edit it in the Patron Preferred Language field.

  • Patrons may set their own locale in the My Account interface off the OPAC by going to Preferences -→ Personal Information and setting the Preferred Language field.

The templates used on the Edit Definition tab are the defaults that are used if there are no alternate templates available that match the preferred language. If alternate templates are available the system will use a locale that is an exact match and then if failing that use one where the language code matches and then fall back to the default one.

For example, if a patron has a locale of fr-CA and there are templates for both fr-CA and fr-FR it will use the fr-CA. If the fr-CA template was deleted it would fall back on using the fr-FR for the patron since it at least shares the same base language.

Valid locales are the codes defined in the i18n_locale table in the config schema.

Cloning Existing Action Triggers

  1. Right click on the line of the action trigger you wish to clone, and choose Clone Selected.

    1. You will be asked to confirm whether or not you wish to clone the event definition environment along with the action trigger.

  2. An editing window will open. Notice that the fields will be populated with content from the cloned action trigger. Edit as necessary and give the new action trigger a unique Name.

  3. Click Save.

Editing Action Triggers

  1. Double-click on the action trigger you wish to edit or right click on the line of the action trigger you wish to edit, and choose Edit Event Definition.

  2. The Edit Definition screen will appear. When you are finished editing, click Save at the bottom of the form. Or click Back to Notification/Action Triggers to exit without saving.

Deleting Action Triggers

  1. Right click on the line of the action trigger you wish to delete.

  2. Choose Delete Selected ofrom the action menu.

Before deleting an action trigger, you should consider disabling it through the editing form. This way you can keep it for future use or cloning.

Testing Action Triggers

  1. Go to the list of action triggers.

  2. . Double-click on the action trigger you wish to edit or right click on the line of the action trigger you wish to edit, and choose Edit Event Definition.

  3. Go to the Run Tests tab.

  4. If there is a test available, fill in the required information and click Go.

  5. View the output of the test.

If you are testing an email or SMS notification, use a test account and email as an example. Using the Test feature will actually result in the notification being sent if configured correctly. Similarly, use a test item or barcode when testing a circulation-based event like Mark Lost since the test will mark the item as lost.

Hooks

Hooks define the Fieldmapper class in the core_type column off of which the rest of the field definitions "hang".

Table 2. Hooks

Field

Description

Hook Key

A unique name given to the hook.

Core Type

Used to link the action trigger to the IDL class in fm_IDL.xml

Description

Text to describe the purpose of the hook.

Passive

Indicates whether or not an event is created by direct user action or is circumstantial.

You may also create, edit and delete Hooks but the Core Type must refer to an IDL class in the fm_IDL.xml file.

Reactors

Reactors link the trigger definition to the action to be carried out.

Table 3. Action Trigger Reactors

Field

Description

Module Name

The name of the Module to run if the action trigger is validated. It must be defined as a subroutine in /openils/lib/perl5/OpenILS/Application/Trigger/Reactor.pm or as a module in /openils/lib/perl5/OpenILS/Application/Trigger/Reactor/*.pm.

Description

Description of the Action to be carried out.

You may also create, edit and delete Reactors. Just remember that there must be an associated subroutine or module in the Reactor Perl module.

CallHTTP Reactor

This Action/Trigger reactor module allows an Evergreen administrator to create event defintions that use HTTP (or HTTPS) to contact external services and let them know that something has happened in Evergreen.

For instance, a discovery layer can be informed when a bib record is updated or when a user’s barcode changes.

CallHTTP Reactor Template Syntax

The new reactor module uses a template to define its behavior. While the template is processed by Template Toolkit, as with any A/T templates, its output format is new to Evergreen.

The template should output data that can be parsed by the Config::General Perl module. See: https://metacpan.org/pod/Config::General

Top level settings should include the HTTP method and the url.

A block called Headers can be used to supply arbitrary HTTP headers.

A block called Parameters can be used to append CGI parameters to the URL, most useful for GET form submission. Repeated parameters are allowed. If this block is used, the URL should /not/ contain any parameters, use one or the other.

A HEREDOC called content can be used with POST or PUT to send an arbitrary block of content to the remote server.

If the requested URL requires Basic or Digest authentication, the template can include top level configuration parameters to supply a user, password, realm, and hostname:port location.

A default user agent string of "EvergreenReactor/1.0" is used when sending requests. This can be overridden using the top level agent setting.

Here is an example template that could be used by a definition attached to the bib.edit hook:

method   post # Valid values are post, get, put, delete, head
url      https://example.com/api/incoming-update
agent    MySpecialAgent/0.1

user     updater
password uPd4t3StufF
realm    "Secret area"
location example.com:443

<Headers>
  Accept-Language en
</Headers>

<Parameters>
  type bib
  id   [% target.id %]
</Parameters>

content <<MARC
[% target.marc %]
MARC

Validators

Validators set the validation test to be preformed to determine whether the action trigger is executed.

Table 4. Action Trigger Validators

Field

Description

Module Name

The name of the subroutine in /openils/lib/perl5/OpenILS/Application/Trigger/Reactor.pm to validate the action trigger.

Description

Description of validation test to run.

You may also create, edit and delete Validators. Just remember that their must be an associated subroutine in the Reactor.pm Perl module.

Processing Action Triggers

To run action triggers, an Evergreen administrator will need to run the trigger processing script. This should be set up as a cron job to run periodically. To run the script, use this command:

/openils/bin/action_trigger_runner.pl --process-hooks --run-pending

You have several options when running the script:

  • --run-pending: Run pending events to send emails or take other actions as specified by the reactor in the event definition.

  • --process-hooks: Create hook events

  • --osrf-config=[config_file]: OpenSRF core config file. Defaults to: /openils/conf/opensrf_core.xml

  • --custom-filters=[filter_file]: File containing a JSON Object which describes any hooks that should use a user-defined filter to find their target objects. Defaults to: /openils/conf/action_trigger_filters.json

  • --max-sleep=[seconds]: When in process-hooks mode, wait up to [seconds] for the lock file to go away. Defaults to 3600 (1 hour).

  • --hooks=hook1[,hook2,hook3,…​]: Define which hooks to create events for. If none are defined, it defaults to the list of hooks defined in the --custom-filters option. Requires --process-hooks.

  • --granularity=[label]: Limit creating events and running pending events to those only with [label] granularity setting.

  • --debug-stdout: Print server responses to STDOUT (as JSON) for debugging.

  • --lock-file=[file_name]: Sets the lock file for the process.

  • --verbose: Show details of script processing.

  • --help: Show help information.

Examples:

  • Run all pending events that have no granularity set. This is what you tell CRON to run at regular intervals.

    perl action_trigger_runner.pl --run-pending
  • Batch create all "checkout.due" events

    perl action_trigger_runner.pl --hooks=checkout.due --process-hooks
  • Batch create all events for a specific granularity and to send notices for all pending events with that same granularity.

    perl action_trigger_runner.pl --run-pending --granularity=Hourly --process-hooks

Configure OPAC Record Email and Print

The information displayed in the printout and email is defined and generated by two new Notification/Action Triggers named biblio.record_entry.print and biblio.record_entry.email.

The printout and email will include the following bibliographic information by default:

  • Bibliographic Record ID

  • Title statement

  • Author

  • Item Type

  • Publisher

  • Publication date

  • ISBN

  • ISSN

  • UPC

If Full display is selected by the OPAC user, the following holdings information is included in the printout or email, if relevant:

  • Circulating Library

  • Item Location

  • Call Number (including prefix and suffix)

  • Monograph Parts

  • Item Status

  • Item Barcode

The bibliographic and item information included in the printout or email can be configured by modifying the respective Action Trigger templates.

For the Full display, the maximum number of copies to be displayed per record can also be configured in the Action Trigger Event Parameter field. To set the maximum number of copies for display, go to Administration → Local Administration → Notifications / Action Triggers and find the print or email notification/action trigger to modify.

  1. Double click on the action trigger you wish to modify

    Email and Print Event Definitions
  2. Select the Edit Parameters tab and in the upper left-hand corner, select New Parameter to create a new Trigger Event Parameter.

  3. In the Parameter Name field enter holdings_limit.

  4. In the Parameter Value field enter the maximum number of copies to be displayed per record.

  5. Select Save to save your changes.

    Email and Print Event Parameters