This example illustrates the use of the presentation script to format messages for specific Devices. Presentation is useful if you want different devices to receive differently formatted versions of the same notification. This example targets both the SMTP Email Device and the Text Pager Device, and each will receive a slightly different message and set of response choices.
The initial script requires some changes. The choices are now stored in a persisted property of the main object, and can be accessed in the presentation script (a Device-specific item will be added). Also, the notification object's “setPresentationScript” method must be called to force the notification to use the presentation script. The changes to the code are displayed in bolded text below:
##################################################################
#
# Script: HelloWorld/PROCESS/initial
#
# This is the main entry point for this script package.
#
##################################################################
#/////////////////////////////////////////////////////////////////
# This is the main entry point for this script. Whenever a
# message is sent
# to the domain that owns this script package, this script is
# called.
#/////////////////////////////////////////////////////////////////
main:
# retrieve the notification associated with this event
@alert = @event::notification()
# Set general response choices
$main.genericChoices = "Hello"
$main.genericChoices::add("Hi")
$main.genericChoices::add("Howdy")
# create a content object for this event
@genericContent = @event::createContent()
# set the content subject and message
$genericContent.subject = "Example #4"
$genericContent.message = "Hello World!"
# persist this content (as a property of main) to be
# accessible from within the presentation script later
$genericContent.choices = $main.genericChoices
# set the notification's content to the recently created content
@alert::setContent(@genericContent)
# enable delivery notifications
@alert::setHandleDeliveryEvents(true)
# tell the notification about the response handler
@alert::setHandlerScript("response")
@alert::setPresentationScript("presentation")
# this example targets the email and pager accounts
# - filter out the phone device
@alert::setDeviceFilter("EMAIL", TRUE)
@alert::setDeviceFilter("TEXT_PAGER", TRUE)
@alert::setDeviceFilter("VOICE", FALSE)
# for this example, two Devices will be targeted. To see how
# replies work from each Device, set a counter that indicates the
# number of Devices that are being targeted. In the response
# script, decrement this counter each time a response is
# received. When the count reaches zero, set main.continue =
# true, so that this event will complete
$main.targetDevices = 2
# tell notification which recipients to target (those contained
# in the event)
@alert::link($event.recipients)
# only log information if debug is set
IF (EXISTS($event.debug))
@script::log("Processing notifications...")
ENDIF
# notify the recipients
@alert::performNotification()
# set continue flag to false and set the timeout to wait for the
# continue flag to change to true (the response handler changes
# the flag’s value to true when it is done)
$main.continue = FALSE
$main.timeout = 86400
# wait until timeout is reached or continue flag changes to TRUE
UNTIL ($main.continue, $main.timeout)
# only log information if debug is set
IF (EXISTS($event.debug))
@script::log("...end of notification processing.")
ENDIF
# ensure that all of the recipients have been removed from the
# notification
@event::delinkAll()
### DONE: main ###
No changes are required for the response object.
Next topic: Creating a presentation script