1 = Notifications / Action Triggers =
7 indexterm:[action triggers, event definitions, notifications]
9 Action Triggers give administrators the ability to set up actions for
10 specific events. They are useful for notification events such as hold notifications.
12 To access the Action Triggers module, select *Administration* -> *Local Administration* -> *Notifications / Action triggers*.
16 You must have Local Administrator permissions to access the Action Triggers module.
19 You will notice four tabs on this page: <<event_definitions, Event Definitions>>, <<hooks, Hooks>>, <<reactors, Reactors>> and <<validators, Validators>>.
24 == Event Definitions ==
26 Event Definitions is the main tab and contains the key fields when working with action triggers. These fields include:
28 === Table 1: Action Trigger Event Definitions ===
31 |==============================================
32 |*Field* |*Description*
33 | Owning Library |The shortname of the library for which the action / trigger / hook is defined.
34 | 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, Validators>> and/or <<reactors, Reactors>> for processing.
35 | <<hooks, 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''.
36 | Enabled |Sets the given trigger as enabled or disabled. This must be set to enabled for the Action trigger to run.
37 | Processing Delay |Defines how long after a given trigger / hook event has occurred before the associated action (``Reactor'') will be taken.
38 | 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_.
39 | Processing Group Context Field |Used to batch actions based on its associated group.
40 | <<reactors, Reactor>> |Links the action trigger to the Reactor.
41 | <<validators, Validator>> |The subroutines receive the trigger environment as an argument (see the linked Name for the environment definition) and returns either _1_ if the validator is _true_ or _0_ if the validator returns _false_.
42 | Event Repeatability Delay |Allows events to be repeated after this delay interval.
43 | 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.
44 | 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.
45 | 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.
46 | Message Library Path |Defines the org_unit object for a Patron Message Center message.
47 | 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.
48 | Message Title |The title that will display on a Patron Message Center message.
49 | Message User Path |Defines the user object for a Patron Message Center message.
50 | 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.
51 | 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.
52 | Success Cleanup |After an event is reacted to successfully a cleanup module can be run to clean up after the event.
53 | 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.
54 |==============================================
57 == Creating Action Triggers ==
59 . From the top menu, select *Administration* -> *Local Administration* -> *Notifications / Action triggers*.
60 . Click on the _New_ button.
62 image::media/new_event_def.png[New Event Definition]
64 . Select an _Owning Library_.
65 . Create a unique _Name_ for your new action trigger.
67 . Check the _Enabled_ check box.
68 . 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_.
69 . Set the _Processing Delay Context Field_ and _Processing Group Context Field_.
70 . Select the _Reactor_ and _Validator_.
71 . Set the _Event Repeatability Delay_.
72 . Select the _Failure Cleanup_ and _Granularity_.
73 . Set the _Max Event Validity Delay_.
75 image::media/event_def_details.png[Event Definition Details]
77 . 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_.
78 . Select the _Opt-In Setting Type_.
79 . Set the _Opt-In User Field_.
80 . Select the _Success Cleanup_.
82 image::media/event_def_details_2.png[Event Definition Details]
84 . 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:
88 [%- user = target.0.usr -%]
89 To: [%- params.recipient_email || user.email %]
90 From: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %]
91 Subject: Overdue Items Marked Lost
92 Auto-Submitted: auto-generated
94 Dear [% user.family_name %], [% user.first_given_name %]
95 The following items are 90 days overdue and have been marked LOST.
96 [%- params.recipient_email || user.email %][%- params.sender_email || default_sender %]
97 [% FOR circ IN target %]
98 Title: [% circ.target_copy.call_number.record.simple_record.title %]
99 Barcode: [% circ.target_copy.barcode %]
100 Due: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]
101 Item Cost: [% helpers.get_copy_price(circ.target_copy) %]
102 Total Owed For Transaction: [% circ.billable_transaction.summary.total_owed %]
103 Library: [% circ.circ_lib.name %]
106 [% FOR circ IN target %]
107 Title: [% circ.target_copy.call_number.record.simple_record.title %]
108 Barcode: [% circ.target_copy.barcode %]
109 Due: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]
110 Item Cost: [% helpers.get_copy_price(circ.target_copy) %]
111 Total Owed For Transaction: [% circ.billable_transaction.summary.total_owed %]
112 Library: [% circ.circ_lib.name %]
115 . Once you are satisfied with your new event trigger, click the _Save_ button located at the bottom of the form.
120 A quick and easy way to create new action triggers is to clone an existing action trigger.
123 === Cloning Existing Action Triggers ===
125 . Check the check box next to the action trigger you wish to clone.
126 . Click _Clone Selected_ on the top left of the page.
127 . 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.
130 === Editing Action Triggers ===
132 . Double-click on the action trigger you wish to edit.
133 . The edit screen will appear. When you are finished editing, click _Save_ at the bottom of the form. Or click _Cancel_ to exit the screen without saving.
137 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.
140 === Deleting Action Triggers ===
142 . Check the check box next to the action trigger you wish to delete
143 . Click _Delete Selected_ on the top-right of the page.
145 === Testing Action Triggers ===
147 . Go to the list of action triggers.
148 . Click on the blue link text for the action trigger you'd like to test.
150 image::media/test_event_def.png[Blue Link Text]
152 . Go to the Test tab.
153 . If there is a test available, fill in the required information.
154 . View the output of the test.
156 image::media/test_event_def_output.png[Test Output]
158 WARNING: 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.
164 Hooks define the Fieldmapper class in the core_type column off of which the rest of the field definitions ``hang''.
167 ==== Table 2. Hooks ====
170 |=======================
171 | *Field* | *Description*
172 | Hook Key | A unique name given to the hook.
173 | Core Type | Used to link the action trigger to the IDL class in fm_IDL.xml
174 | Description | Text to describe the purpose of the hook.
175 | Passive | Indicates whether or not an event is created by direct user action or is circumstantial.
176 |=======================
178 You may also create, edit and delete Hooks but the Core Type must refer to an IDL class in the fm_IDL.xml file.
185 Reactors link the trigger definition to the action to be carried out.
187 ==== Table 3. Action Trigger Reactors ====
190 |=======================
191 | Field | Description
192 | 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`.
193 | Description | Description of the Action to be carried out.
194 |=======================
196 You may also create, edit and delete Reactors. Just remember that there must be an associated subroutine or module in the Reactor Perl module.
198 ==== CallHTTP Reactor ====
200 This Action/Trigger reactor module allows an Evergreen administrator to
201 create event defintions that use HTTP (or HTTPS) to contact external services
202 and let them know that something has happened in Evergreen.
204 For instance, a discovery layer can be informed when a bib record is updated
205 or when a user's barcode changes.
207 ===== CallHTTP Reactor Template Syntax =====
209 The new reactor module uses a template to define its behavior. While the
210 template is processed by Template Toolkit, as with any A/T templates, its
211 output format is new to Evergreen.
213 The template should output data that can be parsed by the Config::General Perl
214 module. See: https://metacpan.org/pod/Config::General
216 Top level settings should include the HTTP *method* and the *url*.
218 A block called *Headers* can be used to supply arbitrary HTTP headers.
220 A block called *Parameters* can be used to append CGI parameters to the URL,
221 most useful for GET form submission. Repeated parameters are allowed. If
222 this block is used, the URL should /not/ contain any parameters, use one or
225 A HEREDOC called *content* can be used with POST or PUT to send an arbitrary block
226 of content to the remote server.
228 If the requested URL requires Basic or Digest authentication, the template can
229 include top level configuration parameters to supply a *user*, *password*, *realm*,
230 and hostname:port *location*.
232 A default user agent string of "EvergreenReactor/1.0" is used when sending requests.
233 This can be overridden using the top level *agent* setting.
235 Here is an example template that could be used by a definition attached to the
240 method post # Valid values are post, get, put, delete, head
241 url https://example.com/api/incoming-update
242 agent MySpecialAgent/0.1
247 location example.com:443
270 Validators set the validation test to be preformed to determine whether the action trigger is executed.
272 ==== Table 4. Action Trigger Validators ====
275 |=======================
276 | Field | Description
277 | Module Name | The name of the subroutine in `/openils/lib/perl5/OpenILS/Application/Trigger/Reactor.pm` to validate the action trigger.
278 | Description | Description of validation test to run.
279 |=======================
281 You may also create, edit and delete Validators. Just remember that their must be an associated subroutine in the Reactor.pm Perl module.
283 [#processing_action_triggers]
284 == Processing Action Triggers ==
286 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:
289 /openils/bin/action_trigger_runner.pl --process-hooks --run-pending
292 You have several options when running the script:
294 * --run-pending: Run pending events to send emails or take other actions as
295 specified by the reactor in the event definition.
297 * --process-hooks: Create hook events
299 * --osrf-config=[config_file]: OpenSRF core config file. Defaults to:
300 /openils/conf/opensrf_core.xml
302 * --custom-filters=[filter_file]: File containing a JSON Object which describes any hooks
303 that should use a user-defined filter to find their target objects. Defaults to:
304 /openils/conf/action_trigger_filters.json
306 * --max-sleep=[seconds]: When in process-hooks mode, wait up to [seconds] for the lock file to go
307 away. Defaults to 3600 (1 hour).
309 * --hooks=hook1[,hook2,hook3,...]: Define which hooks to create events for. If none are defined, it
310 defaults to the list of hooks defined in the --custom-filters option.
311 Requires --process-hooks.
313 * --granularity=[label]: Limit creating events and running pending events to
314 those only with [label] granularity setting.
316 * --debug-stdout: Print server responses to STDOUT (as JSON) for debugging.
318 * --lock-file=[file_name]: Sets the lock file for the process.
320 * --verbose: Show details of script processing.
322 * --help: Show help information.
326 * Run all pending events that have no granularity set. This is what you tell
327 CRON to run at regular intervals.
330 perl action_trigger_runner.pl --run-pending
333 * Batch create all "checkout.due" events
336 perl action_trigger_runner.pl --hooks=checkout.due --process-hooks
339 * Batch create all events for a specific granularity and to send notices for all
340 pending events with that same granularity.
343 perl action_trigger_runner.pl --run-pending --granularity=Hourly --process-hooks
346 [[configure_opac_email_print]]
347 == Configure OPAC Record Email and Print ==
349 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”. Notification/Action Triggers are found under *Admin -> Local Administration.*
351 The printout and email will include the following bibliographic information by default:
353 * Bibliographic Record ID
363 If *Full display* is selected by the OPAC user, the following holdings information is included in the printout or email, if relevant:
365 * Circulating Library
367 * Call Number (including prefix and suffix)
372 The bibliographic and item information included in the printout or email can be configured by modifying the respective Action Trigger templates.
374 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 *Admin -> Local Administration -> Notifications / Action Triggers* and find the print or email notification/action trigger to modify.
376 . Select the hyperlinked name of the Notification/Action Trigger to view the Trigger Event Environment.
378 image::media/ope_event_defs.png[Email and Print Event Definitions]
380 . Select the *Event Parameters* tab and in the upper right-hand corner, select *New* to create a new Trigger Event Parameter.
381 . In the _Parameter Name_ field enter holdings_limit.
382 . In the _Parameter Value_ field enter the maximum number of copies to be displayed per record.
383 . Select *Save* to save your changes.
385 image::media/ope_event_params.png[Email and Print Event Parameters]