Gateway Tutorial: VXML Application | Email To Phone Alert Servlet

This is the start Servlet for the EmailToPhone application when an alert call is made. Voicent Gateway knows to call this Servlet because it is defined in the starturl parameter of the call request. The main function of this Servlet is to dynamically generate a VXML file based on the email account.

    ...

    PrintWriter pw = response.getWriter();

    pw.println("<?xml version=\"1.0\"?>");
    pw.println("<vxml version=\"1.0\">");
    pw.println("<form id=\"email\">");
    ...
    pw.println("</vxml>");
  }

For outbound call, it might be answered by a live human or an answering machine. If it is answered by an answering machine or voice mail system, the Servlet is invoked with the parameter ans=t. The following code shows that if it is answered by a live human, the system forwards the control to the gateway password.jsp file. This will validate the inbound password.

    String ans = request.getParameter("ans");
    if (! "t".equals(ans)) {
        pw.println("<submit next=\"/password.jsp\"/>");
    }

Source Code

package vx.apps.email;

import java.io.PrintWriter;
import java.io.IOException;
import javax.servlet.http.*;


public class EmailAlertServlet extends HttpServlet
{
  public void service(HttpServletRequest request, HttpServletResponse response)
    throws IOException
  {
    String newcount = request.getParameter("newemail");
    String ans = request.getParameter("ans");

    PrintWriter pw = response.getWriter();

    pw.println("<?xml version=\"1.0\"?>");
    pw.println("<vxml version=\"1.0\">");

    pw.println("<form id=\"emailalert\">");
    pw.println(" <block>");

    pw.println("<audio src=\"audio/${GW_RECORDED_VOICE}/alert_for.wav\"/>");
    pw.println("<audio><say-as interpret-as=\"myname\"/></audio>");
    pw.println("<audio src=\"/audio/${GW_RECORDED_VOICE}/u_have.wav\"/>");
    pw.println(newcount);
    pw.println("<audio src=\"audio/${GW_RECORDED_VOICE}/email.wav\"/>");
    pw.println("<audio src=\"audio/${GW_RECORDED_VOICE}/msgs.wav\"/>");

    if (! "t".equals(ans)) {
        // this is the default Voicent Gateway inbound call password
        // it can be set under gateway > setup > options > inbound
        // the password.jsp is provided by the gateway
        pw.println("<submit next=\"/password.jsp\"/>");
    }

    pw.println(" </block>");
    pw.println("</form>");

    pw.println("</vxml>");
  }
}

Previous Table of Contents Next