<?xml version="1.0"?>
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml">
  <log expr="'Started test VXML script'" />

  <var name="TestGoto" expr="'MainMenu'"/>
  <var name="TestWAV"  expr="'../callgen/ogm.wav'"/>

    <!-- Main menu -->
  <menu id="MainMenu">

    <!-- Set this property for the time to wait for input -->
    <property name="timeout" value="30s"/>

    <!-- A prompt outputs to the remote -->
    <prompt bargein="false">
      <!-- Audio plays the URI in src, or if absent uses speech synthesis of the body text -->
      <audio src="file:menu_prompt.wav">
        Welcome to the OPAL I V R example.
      </audio>
    </prompt>

    <!-- The next attribute here indicats what <form> to go to when the menu is selected -->
    <choice dtmf="1" next="#PlayFile">
      Press 1 to play an announcement
    </choice>
    
    <choice dtmf="2" next="#RecordFile">
      Press 2 to re-cord a message
    </choice>
    
    <choice dtmf="3" next="#DoTransfer">
      Press 3 to transfer call
    </choice>
    
    <choice dtmf="4" next="#GetOperator">
      Press 4 to speak to an operator
    </choice>
    
    <choice dtmf="0" next="#HangUp">
      Press 0 to disconnect
    </choice>
    
    <!-- This section is executed when a timeout occurs -->
    <noinput>
      <audio src="file:menu_timeout.wav">
        Nothing entered, disconnecting.
      </audio>
      
      <!-- hang up the call -->
      <disconnect/>
    </noinput>

    <!-- This section is executed when does not match any <choice> -->
    <nomatch>
      <audio src="file:menu_nomatch.wav">
        Please enter 1 to 4 or 0.
      </audio>

      <!-- To play main menu again must explicitly go there, or it moves to next node -->
      <goto nextitem="MainMenu"/>
    </nomatch>
  </menu>

  <!-- This form is demonstrates how to just play some things -->
  <form id="PlayFile">
    <log expr="'Playing WAV file'"/>
    
    <audio expr="application.TestWAV"/>
    <break time="5s"/>
    <audio expr="application.TestWAV"/>
    
    <!-- No stack, have to go back to main menu explicitly  -->
    <goto expritem="application.TestGoto"/>
  </form>

  <!-- This form demonstrates how to record a message -->
  <form id="RecordFile">
    <log expr="'Recording message'"/>
    
    <record name="LeftMessage" dtmfterm="true" finalsilence="5s" maxtime="60s">
      <prompt>
        <audio src="file:../callgen/ogm.wav">
          Please leave a message.
        </audio>
      </prompt>

      <!-- This section is executed when the recording completes -->
      <filled>
        <log expr="'Recorded '+LeftMessage$.duration+' seconds'"/>

        <audio src="file:message_recorded.wav">
          Message recorded.
        </audio>

        <!-- No stack, have to go back to main menu explicitly  -->
        <goto next="#MainMenu"/>
      </filled>
    </record>
  </form>

  <!-- This form demonstrates how to do a simple call transfer -->
  <form id="GetOperator">
    <log expr="'Transfer to operator'"/>
    
    <transfer type="blind" dest="sip:500@ekiga.net">
      <!-- This message is played just before the transfer -->
      <audio src="file:next_operator.wav">
        Please wait while we transfer you to the first available operator.
      </audio>
      
      <!-- This is executed of the transfer does not succeed -->
      <error>
        <audio src="file:transfer_failed.wav">
          Transfer to operator failed.
        </audio>

        <!-- No stack, have to go back to main menu explicitly  -->
        <goto expr="'#'+application.TestGoto"/>
      </error>
    </transfer>
  </form>

  <!-- This form demonstrates how to do a more complicated transfer -->
  <form id="DoTransfer">
    <log expr="'Doing transfer'"/>
    
    <!-- A field is a place to enter digits -->
    <field name="enteredDigits">
      
      <!-- A grammar is a description of the input. We do not support any of the
           standards at this point, only a custom grammer that will accept n to m
           digits with something as a termiantor. -->
      <grammar mode="dtmf" type="X-OPAL/digits">
        minDigits=1;
        maxDigits=5;
        terminators=#
      </grammar>
      
      <prompt>
        <!-- If prompt does not contain an <audio> then just speaks the text -->
        Please enter the number of the person you wish to connect to.
      </prompt>
    </field>
    
    <filled>
      <!-- A <value> evaluates the expression then speaks it using speech synthesis -->
      <value expr="'Entered '+enteredDigits" />
      
      <!-- Transfer to the calculated expression. Note that we only support string
           concatenation ('+' operator) at this time. -->
      <transfer type="false" destexpr="'sip:'+enteredDigits+'@ekiga.net'" />
    </filled>

    <!-- This happens if a timeout occurs -->
    <noinput>
      <audio src="file:transfer_timeout.wav">
        Nothing entered, returning to main menu.
      </audio>
      <goto next="#MainMenu"/>
    </noinput>

    <!-- This is executed of the transfer does not succeed -->
    <error>
      <audio src="file:transfer_failed.wav">
        Transfer failed.
      </audio>
      <goto next="#MainMenu"/>
    </error>
  </form>

  <!-- This form demonstrates how to play a mesage and hang up -->
  <form id="HangUp">
    <log expr="'Hanging up'"/>
    
    <audio src="file:goodbye.wav">
      Good bye.
    </audio>

    <!-- Seems obvious -->
    <disconnect/>
  </form>
</vxml>
