Annotated Example Part Three

This example illustrates a two-way notification by sending notifications to both the SMTP and Pager Devices with a list of response choices for the User. The example also illustrates response processing.

Using the initial script from example #2, this example targets both the SMTP Email Device and the Pager Device. As a result, filtering for the text pager must be enabled, and response choices added to the response content. 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()

 

  # create a content object for this event

  @genericContent = @event::createContent()

 

  # set the content subject and message

  $genericContent.subject = "Example #3"

  $genericContent.message = "Hello World!"

 

  # Set general response choices.  

  $genericContent.choices::add("Hi")

  $genericContent.choices::add("Howdy")

  $genericContent.choices::add("Good day")

 

  # specify which event domain this script package belongs to

  $genericContent.scriptPackage = $event.domain

 

  # 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 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 ###

Next topic: Modifying the response handler