Play Different Messages | Outbound Application Tutorial | Gateway Tutorial
As stated in the previous section, the gateway is aware two starting VXML files, one for human pickup and the other for answering machine. The starting VXML file for human pickup is defined in startvxml or starturl.
Using static starting VXML fileIf you are using startvxml for your starting VXML file, the corresponding VXML file for the answering machine must be:
<startvxml file name>_ans.vxml
For example, if your startxml file name is myapp.vxml
, then the starting VXML file for the answering machine must be: myapp_ans.vxml
. These two files must reside in the same directory. If the myapp_ans.vxml
file does not exist, then myapp.vxml
is used.
As you can see in the previous section, the call control flow will first fetch the myapp.vxml file before the dialing, if the call is answered by a live human, the gateway plays the myapp.vxml file; if the call is answered by an answering machine, the gateway discard the myapp.vxml file and then fetch the myapp_ans.vxml file to play.
Using dynamically generated VXML fileIf you are using dynamically generated starting VXML file using starturl, the gateway will first fetch the VXML file with no parameter, if the call is answered by an answering machine, the gateway discards the previously fetched VXML file and will then fetch the VXML file with ans=t
.
For example, if your starturl is defined as http://mydomain/myapp/start.jsp
. The gateway will get the start vxml file by sending an HTTP request to the URL defined, i.e., http://mydomain/myapp/start.jsp
; if the call is answered by an answering machine, the gateway will send another HTTP request to the same URL with parameter ans=t
, i.e., http://mydomain/myapp/start.jsp?ans=t
The following example JSP file will play live.wav for human pickup, and play answering.wav for answering machine. The wave file must reside under the directory audio. For the time being, record any message in these two wave files. We'll add more features as this tutorial develops.
<?xml version="1.0"?> <vxml version="1.0"> <% String ans = request.getParameter("ans"); boolean isAnsweringMachine = ("t".equals(ans)); %> <form id="td"> <block> <% if (isAnsweringMachine) { %> <audio src="audio/answering.wav"/> <% } else { %> <audio src="audio/live.wav"/> <% } %> </block> </form> </vxml>
For live human pickup, this JSP file returns:
<?xml version="1.0"?> <vxml version="1.0"> <form id="td"> <block> <audio src="audio/live.wav"/> </block> </form> </vxml>
For answering machine, this JSP file returns:
<?xml version="1.0"?> <vxml version="1.0"> <form id="td"> <block> <audio src="audio/answering.wav"/> </block> </form> </vxml> </header>