Creating an interaction script

The interaction script handles voice interaction with the User. This example reads the notification to the User and responds with “Hello from Voice Device”. Note that there are “Exception” code sections in this script. These are necessary in order to catch unexpected exceptions during the phone call (e.g., the user hangs up the phone, or does not respond within a reasonable amount of time):

###################################################################

# Script: HelloWorld/INTERACTION/notify

#

# This script interacts with the User via voice.

#

##################################################################

#/////////////////////////////////////////////////////////////////

# This is the main entry point for this script.  Whenever a response

# event occurs, this script is called.  This will get called for

# each recipient.

#/////////////////////////////////////////////////////////////////

main:

 

  # only log information if debug is set

  IF (EXISTS($event.debug))

    @script::log("Interaction script called")

  ENDIF

 

  # only voice Devices are handled in this script

  IF ($content.deviceclassification == "voice")

    gosub notifyVoice

  ELSE

    IF (EXISTS($event.debug))

      @script::log($event.incident_id & ": Unable to notify device " & $content.deviceclassification & ".")

    ENDIF

  ENDIF  

  

### DONE: main ###

return

 

#/////////////////////////////////////////////////////////////////

# This is the entry point to code that handles notification for

# voice devices.

#/////////////////////////////////////////////////////////////////

notifyVoice:

 

  # set the interaction result to true

  # this is used to indicate if interaction was successful

  $session.interactionResult = true

 

  # ignore if we've hit voicemail

  IF ($voiceMail)

    return

  ENDIF

 

  # play the subject and the message

  @phone::play("phrase", $content.subject)

  @phone::play("phrase", $content.message)

  

  # acknowledge the notification ($notId contains the notification

  # ID)

  @session::respondToNotification($notId, "Hello from Voice Device")

  

  # tell User that message has been acknowledged

  @phone::play("phrase", "Hello from Voice Device")

 

### DONE: notifyVoice ###

return

 

#/////////////////////////////////////////////////////////////////

# This exception handler is ONLY called if the user hangs up the

# phone prematurely.  

#/////////////////////////////////////////////////////////////////

PhoneHangupException:

 

  # only log information if debug is set

  IF (EXISTS($event.debug))

    @script::log($event.incident_id & ": Phone hangup exception.")

  ENDIF

exit

 

#/////////////////////////////////////////////////////////////////

# This exception handler is ONLY called if a phone timeout occurs

# before the User responds to a prompt.

#/////////////////////////////////////////////////////////////////

PhoneTimeoutException:

 

  # only log information if debug is set

  IF (EXISTS($event.debug))

    @script::log($event.incident_id & ": Phone Timeout exception.")

  ENDIF

  

  # forcibly hang up the phone

  @phone::hangup()

exit

Next topic: Testing the example script