This part of the example demonstrates how to send one-way notifications to target recipients.
For this example, modify the initial script and add additional code as shown below so that a notification can be sent. Best practices for script development and debugging are to include code that tests for the existence of the $event.debug tag, and write statements to a log file if present.
This example targets the SMTP email account, and sends a one-way notification:
##################################################################
#
# 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()
# create a content object for this event
@genericContent = @event::createContent()
# set the content subject and message
$genericContent.subject = "Example #2"
$genericContent.message = "Hello World!"
# 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")
# this example targets only the email account - filter
# out the other devices
@alert::setDeviceFilter("EMAIL", TRUE)
@alert::setDeviceFilter("TEXT_PAGER", FALSE)
@alert::setDeviceFilter("VOICE", FALSE)
# 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
# now 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 ###
Next topic: Creating a response handler