Gateway Outbound Application Tutorial: VXML Detect Which Key was Pressed

With dynamically generated VXML files, you can pretty much do whatever you want with your application. In this sample, we'll collect key press 1 - 5 from our customer. The following is the updated start.jsp file:

<?xml version="1.0"?>
<vxml version="1.0">
<% 
    String ans = request.getParameter("ans");
    boolean isAnsweringMachine = ("t".equals(ans));
%>
<form id="td">
<% if (isAnsweringMachine) { %>
  <block>
    <audio src="audio/answering.wav"/>
  </block>
<% } else { %>
  <field name="rating">
    <prompt timeout="10s">
      <block>
        <audio src="audio/live.wav"/>
      </block>
    </prompt>
    <dtmf>
      1 | 2 | 3 | 4 | 5
    </dtmf>
    <filled>
      <submit next="recordrating.jsp" namelist="rating"/>
    </filled>
  </field>
<% } %>
</form>
</vxml>

This start.jsp file will generate the follow VXML for live human pickup:
 

<?xml version="1.0"?>
<vxml version="1.0">
<form id="td">
  <field name="rating">
    <prompt timeout="10s">
      <block>
        <audio src="audio/live.wav"/>
      </block>
    </prompt>
    <dtmf>
      1 | 2 | 3 | 4 | 5
    </dtmf>
    <filled>
      <submit next="recordrating.jsp" namelist="rating"/>
    </filled>
  </field>
</form>
</vxml>

As you can see the key press is captured by VXML file's "rating" field. This value is then submitted to the next JSP file called recordrating.jsp.

 

<?xml version="1.0"?>
<vxml version="1.0">
 
<% 
    String key = request.getParameter("rating");
    int ratetotal = 1;
    Integer RateTotal = (Integer) application.getAttribute("rate" + key);
    if (RateTotal != null)
        ratetotal = RateTotal.intValue() + 1;
    application.setAttribute("rate" + key, new Integer(ratetotal));
%>

<form id="td">
  <block>
    <audio src="audio/thankyou.wav"/>
  </block>
</form>
</vxml>

Here we simply record the key press as application attributes. A thank you message is returned the gateway. It should be quite easy to change the code such that the key press is saved to a relational database, for example.

You can test your recordrating.jsp with your browser using the following address:

http://localhost:8155/ocall/myapp/recordrating.jsp?rating=3


Previous Table of Contents Next