Processing Events and Handling Responses

As illustrated in the following figure, the event processing and response handling portions of the business process are scriptable:

This section describes these scripting contexts.

Process Event

Once the runtime receives an event, it persists the event and starts a business process.  Based on the event’s domain, a script package is selected and an initial script is run.  The purpose of an initial script is to define how the business process should behave.

For example, for one event domain the system might generate notifications based on a specified recipient and await responses.  For another domain, the system might simply log the event’s occurrence and terminate.

Script Inputs

The inputs into a process script are:

@event

The event information will be accessible through an event script object. This object will contain the following information by default:

The object will also contain any other tokens injected with a message.

@main

This script object is used to pass context information between scripts and can be considered a container for global variables. Initially it contains no context information.

Script Package Structure

Events are initially processed by ‘process’ scripts. Each package may contain only one ‘process’ script.

Examples

Example 1: Hello World: writes to a log file each time an event is injected into its domain:

1   main:

2   @script::setLog("../logs/HelloWorld.log")

3   @script::log("Hello World!")

4   ### DONE: main ###

Annotation:

1.  Specifies the start of the script.

2.  Specifies the name of the log file.

3.  Statement to write to the log file.

Example 2: Send Notification: sends a notification to the list of recipients injected with the event.

1   main:

2   @alert = @event::notification()

3   @genericContent = @event::createContent()

4   $genericContent.message = "Hello World!"

5   @alert::setContent(@genericContent)

6   @alert::setHandlerScript("response")

7   @alert::link($event.recipients)

8   @alert::performNotification()

9   $main.continue = FALSE

10  $main.timeout = 86400

11  UNTIL ($main.continue, $main.timeout)

12  @event::delinkAll()

13  ### DONE: main ###

Annotation:

2.  Creates a notification script object.

3.  Creates an empty content script object for the notification.

4.  Adds content for the notification. The message field is a reserved variable in the content script object and is a required field. Device engines require that the message variable is present in the content script object.

5.  Associates the newly populated content with the notification.

6.  Associates a script within this script package that will be used to handle responses to this notification.

7.  Configures the notification recipients based upon the injected event.

8.  Performs the notification.

9-11.  Blocks and waits for a handler script to continue execution.

12.  Removes all recipients from this event.

Handle Responses

Users may respond to notifications, and the handling of their responses is also scriptable.  For example, a particular response may cause a business process to generate further notifications, while other responses may cause the business process to terminate.  

Each Device Notification can generate multiple notification events. Immediately after a notification is delivered to its service provider, a SUCCESSFUL_DELIVERY event is sent back by the Device Engine. If the notification is unable to be delivered after the configured number of retries then a DELIVERY_FAILURE event is sent back by the Device Engine. When a User responds to a notification, then a RECEIVED_RESPONSE is sent. These events are processed by the handler script that has been associated with the notification.

Script Inputs

The inputs into a handler script are:

The response object contains the context around the response. For information about the variables within the response object, see Reserved names generated during notification.

Script Package Structure

Script Packages can contain multiple handler scripts; each notification created in scripting should be associated to a handler script. A handler script can process multiple delivery events for notifications.

Example

Example 1: Handling Successful Delivery: initiates the main business process to continue upon the receipt of a successful delivery event:

1   main:

2   IF ( $response.response_event =="SUCCESSFUL_DELIVERY" )

3   $main.continue = TRUE

4   ENDIF

Annotation:

1.  Specifies the start of the script.

2.  Determines the delivery event that was sent to the handler script.

3.  Assigns the value of the $main.continue variable to TRUE. This causes the continuation of the main business process.

 

Next topic: Enhancing Notification Content