Tropo Scripting Development Guide Home  |  Frameset Home


event  return value


Represents the result of a system operation.


usage

event( attempt: String,
    choice: String,
    name: String,
    recordURI: String,
    value: String )


parameters

attempt Data Type: String Default: (none) Optional
This allows you to set behavior for an individual attempt (the number of possible attempts is defined by the attempts method). In the following JavaScript example, attempts is defined as 3, so it will repeat the prompt three times. For event.attempt 1 and event.attempt 2, different behavior as been defined (two different says); on the third attempt, if the caller still does not return valid input, the call will just disconnect.

answer()
ask("What's your favorite color?", {
    attempts:3,
    choices:"red, blue, green",
    onBadChoice:function(event) {
        switch(event.attempt) {
        case 1:
            say("We don't support that color. You can say red, blue or green.")
        case 2: 
            say("It’s really simple, man. Just say red, blue or green."
        }
    }

choice Data Type: String Default: none Optional
Please note that the event structure has additional information available in a "choice" object. Specifically, there is an "event.choice" object that itself has the following fields:
  • event.choice.concept - Only tags or concepts returned from recognition.
  • event.choice.interpretation - Full semantic interpretation of the results.
  • event.choice.utterance - What the caller actually input before interpretation.
  • event.choice.confidence - The ASR engine's confidence in the result
  • event.choice.xml - The raw NLSML result returned from the underlying MRCP engine.
name Data Type: String Default: none Optional
Depending on the event that ends the method, the event.name attribute will be set to:

choice, record, timeout, badChoice, hangup, silenceTimeout, or error.
recordURI Data Type: String Default: (none) Optional
This returns either the location of a recording when working with text (e.g. when used with log) or audibly returns what was actually recorded (e.g. when used with a say on a voice call), such as in this JavaScript example:

answer()	
record("Please leave your message at the beep.", {
    beep:true, timeout:10, silenceTimeout:7, maxTime:60,
        onRecord: function(event) {
            log("Recording result = " + event.recordURI)
            say("You said " + event.recordURI)
        }
})
value Data Type: String Default: none Optional
The event.value attribute will be set for choice and record events, as will event.recordURI as appropriate. The rules are:

  • If choice and record are on, return event.name = choice, event.value = grammar result, and event.recordURI = recordURI
  • If choice is on but not record, return event.name = choice, event.value = grammar result, and event.recordURI = null
  • If record is on but not choice, return event.name = record, event.value = recordURI, and event.recordURI = recordURI



code samples

JavaScript example showing event.value and event.choice.interpretation
ask("Welcome to the Tropo company directory. Who are you trying to reach?", {
    choices:"department(support, engineering, sales), person(jose, jason, adam)",
    onChoice: function(event) {
    say("You said " + event.choice.interpretation + ", which is a " + event.value);
    }
});


Ruby example showing event.value and event.choice.interpretation
ask "Welcome to the Tropo company directory.  Who are you trying to reach?", {
    :choices => "department(support, engineering, sales), person(jose, jason, adam)",
    :onChoice => lambda { |event| 
    say("You said " + event.choice.interpretation + ", which is a " + event.value)    
    }
}


PHP example showing event.value and event.choice.interpretation
<?php
ask("Welcome to the Tropo company directory. Who are you trying to reach?", array(
    "choices"=>"department(support, engineering, sales), person(jose, jason, adam)",
    "onChoice" => "choiceFCN"
    )
);
function choiceFCN($event) {
    say("You said " . $event->choice->interpretation . ", which is a " . $event->value);
    }
?>


Python example showing event.value and event.choice.interpretation
def choiceFCN(event):
    if (event.name == "choice"):
        say("You said " + event.choice.interpretation + ", which is a " + event.value)

event = ask("Welcome to the Tropo company directory.  Who are you trying to reach?", {
   "choices":"department(support, engineering, sales), person(jose, jason, adam)",
   "onChoice":choiceFCN})


Groovy example showing event.value and event.choice.interpretation
ask("Welcome to the Tropo company directory.  Who are you trying to reach?", [
    choices: "department(support, engineering, sales), person(jose, jason, adam)",
    onChoice: { event->
        say "You said " + event.choice.interpretation + ", which is a " + event.value}
])



additional links

none


  ANNOTATIONS: EXISTING POSTS
0 posts - click the button below to add a note to this page

login



© 2012 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site