Introduction to CCXML, Part IV
Accessing Values Returned from Dialogs
Another concept that we need to grasp for the example that we will be looking at in a few minutes in the method by which VoiceXML dialogs can pass form field values back to the calling CCXML interpreter. This is done by specifying the list of variables in the namelist attribute of the <exit> element (within the VoiceXML file; not the CCXML file):
<exit namelist="name address phone"/>
We can read in these returned variables in CCXML within the dialog.exit event handler. Looking at the second event handler listed in our previous example and also listed below:
<transition name="evt" state="'playing_terms'" event="dialog.exit"> <assign name="current_state" expr="'running_main_dialog'"/> <var name="age" expr="evt.age"/> <if cond="age > 21"> <dialogstart src="'main.vxml'"/> <else/> <exit/> </if> </transition>
Calling Card Application with CCXML
Now we're going to tie everything we've learned about CCXML up to this point to develop an application that functions like a calling card: you dial a number, enter your calling card number, and then dial the number you wish to call.
For this application, we want to do the following:
- answer the incoming call
- start the VoiceXML dialog that collects the caller's PIN code and the number they want to call
- dial the phone number (if their PIN code matched)
- Join the two call legs when the remote party answers the phone
You can view the full source of the application here.
During execution, the application will be in one of five states. The table below lists the state and their related events as well as the next state.
Notice that there are two separate events that might occur while in the dialing state. Either the outbound call will be connected, or it will fail. Also, you'll notice that we're handling the connection.CONNECTION_CONNECTED event in two different places. The first occurrence is triggered when the incoming call is answered and connected. The second occurrence is triggered when the outbound call (using the number they specified) is connected. In the first occurrence, we start the VoiceXML dialog that collects the caller's PIN code and phone number to dial. In the second occurrence, we're calling the <join> elements to join the inbound and outbound call legs together.
You can view the full source of the VoiceXML dialog that collects and returns the caller's PIN code and outbound phone number here.
Some things to notice in this new application:
Placing the outbound call:
<transition name="evt" state="'getting_phone_number'" event="dialog.exit"> <assign name="phone_number" expr="evt.phone_number"/> <if cond="phone_number.length == 10"> <assign name="current_state" expr="'dialing'"/> <createcall dest="phone_number"/> <else/> <exit/> </if> </transition>
The <transition> element above sets the local variable phone_number with the return value from evt.phone_number. If the phone number is 10 digits long, then the state changes to dialing and an outbound call is initiated to the specified number with the <createcall> element.
Joining the Call Legs:
<transition name="evt" state="'dialing'" event="connection.CONNECTION_CONNECTED"> <assign name="outgoing_callid" expr="evt.callid"/> <join sessionid1="incoming_callid" sessionid2="outgoing_callid"/> </transition>
The <transition> element above joins the inbound and outbound call legs with the <join> element when the outbound call is connected. If the call is not connected for whatever reason (no answer, busy signal, disconnected number), then the <transition> element listed below is executed:
<transition state="'dialing'" event="connection.CONNECTION_FAILED"> <log expr="'Failed making outbound call'"/> <exit/> </transition>
This event handler simply logs the error and exits the CCXML application, disconnecting the call.
If you've made it through the entire CCXML series so far, then you already have a good grasp of the CCXML language. Now you know how to create simple two-party conference calls with the <join> and element. The next and final tutorial in this series will demonstrate how to create multi-party conference calls using the <createconference> element.
About Jonathan Eisenzopf
Jonathan is a member of the Ferrum Group, LLC which specializes in Voice Web consulting and training. Feel free to send an email to firstname.lastname@example.org regarding questions or comments about this or any article.
Page 2 of 2