CallXML 2.0 Development Guide Home  |  Frameset Home

  tutorial Hello world with ColdFusion  |  TOC  |  tutorial Multi-party conferencing in CallXML   
This documentation is for CallXML 2, which has been superceded by CallXML 3. The CallXML 2 language is not being updated any longer. CallXML 3, however, has many new features and is actively being enhanced. If you're writing a new CallXML application, you should use CallXML 3. Click here for the CallXML 3.0 documentation.

Tutorial: Hello World with ASP

This Lesson will step you through the creation and deployment of a "hello world" application using a server-side scripting language such as ASP, ColdFusion, PHP, PERL, etc. In the last Lesson, we used ColdFusion, but this time around we will look at ASP. This Lesson is based on the things you accomplished in the standard voxeo Lessons. If you do not have a basic knowledge of Callxml, you'll need to backtrack, and check out the previous Lessons. This Lesson also assumes that you have a basic knowledge of ASP, and that you have access to a web server that is running ASP as a service.

Note: Be aware that the Voxeo webhosting service does not have provisions for any file extensions other than .xml, .gsl, and .grammar files. Attempting to run any of the following tutorials when the files live at webhosting.voxeo.net simply won't work. If you do wish to run these tutorials, then you will need to find a host that supports the appropriate markup language. If you do not have a webserver in-house to accomadate this, then a simple Google search for '(PHP/JSP/whatever) hosting' should turn up dozens of possible candidates for you to mull over.


In this Lesson, we will:


Step 1: returning to our virtual answering machine

What we are really doing in this Lesson is making our answering machine application from Lesson 6 a little more "caller friendly." The idea is to actually say "hello" to the caller before they record a message for us. So let's start where we left off in that Lesson:


<?xml version="1.0" encoding="UTF-8" ?>
<callxml version="2.0">

  <block>
    <playaudio value="http://www.myserver.com/greeting.wav"/>

    <recordaudio format="audio/wav"
value="mailto:my-email@my-email-server.com"
termdigits="#"
maxtime="60s"
maxsilence="10s"
beep="TRUE"/>

<ontermdigit value="#">
  <text> Your message has been sent.</text>
</ontermdigit>

<onmaxtime>
  <text> You have reached maxtime.  Message sent.</text>
</onmaxtime>

<onmaxsilence>
  <text> Maxsilence exceeded.  Message sent.</text>
</onmaxsilence>

  </block>

</callxml>


Step 2: using ASP to access a database file

Before we can read our greeting to the caller, we will have to determine who the caller is, and then search the database file for a match. This process is a combination of callxml and ASP:


  <%@ LANGUAGE = VBScript %>


We are going to put this as our first line in our script, which tells the browser that we are using ASP.


<%


This indicates the start of a block of ASP code, and %> indicates the end of the block.


  Dim ConnectionToDB, DatabaseRecord

  Set ConnectionToDB = Server.CreateObject("ADODB.Connection")
  ConnectionToDB.Open "voxeo.community.Lesson.9.db"


Whoa. There is quite a bit of activity happening here, and none of it looks like callxml. This is pure ASP actually, and these three lines open up an ODBC connection to a database file. We are not going to cover it here, but the database file will have to be established through the ODBC Data Sources resource in your webserver's Control Panel folder.
The first line above allocates memory for two variables, one called "ConnectionToDB" and another called "DatabaseRecord". The second line takes our connection variable and turns it into an object using a standard ASP method (i.e., the variable is now an ODBC object). The third line actually opens the database connection to the ODBC resource called "voxeo.community.Lesson.9.db"; however, this database could be called "People I Know" or "Callers".


  SQLStr = "select * from PeopleIKnow Where CallerID = '" & _
    Request.QueryString("session.callerid") & "'"

  set DatabaseRecord = ConnectionToDB.Execute (SQLStr)


Our two lines of code get even more interesting. The first line alone contains five new references to us. Let's take them in order:


Well, that takes care of the first line, but what about the second one? Here we are actually going "execute" the string that we just made. We are sending it off to our previously opened database connection, and we are going to store the results in a variable called "DatabaseRecord". Now, this record could have multiple results, but we are only expecting to get one (or zero) matches back. Also note that the "& _" is for concatenating strings across multiple lines.


TextMessage = DatabaseRecord("Message")

response.write "<assign var=""Message""
value=""" & TextMessage & """/>"


Here we are mixing ASP and callxml (finally). We create an ASP variable named "TextMessage" from our DatabaseRecord variable. Notice here that "Message" refers to another column in the database (just like CallerID). Then we use the ASP object response.write, which simply outputs text, to create a callxml variable named "Message" via the <assign> element. Notice that we have to use "" instead of " around the attribute values -- this is how ASP escapes the quote.


  ConnectionToDB.Close
  set ConnectionToDB = nothing


All that we have to do from the ASP side at this point is close our database connection. As you can see, this is a snap.


Step 3: Mix the two languages together

So now we have two separate pieces of code, but they need to be linked together. Before this happens, however, we are going to add in one more line of code to our callxml portion:


  <text>$Message;</text>


Remember how we just made a callxml variable named "Message"? Well, there it is. Now we will have a caller-specific greeting read over the phone. Here is what our final script is going to look like:


<%@ LANGUAGE = VBScript %>

<?xml version="1.0" encoding="UTF-8" ?>
<callxml version="2.0">

<%
  Dim ConnectionToDB, DatabaseRecord

  Set ConnectionToDB = Server.CreateObject("ADODB.Connection")
  ConnectionToDB.Open "voxeo.community.Lesson.9.db"

  SQLStr = "Select * from PeopleIKnow Where CallerID = '" & _
    Request.QueryString("session.callerid") & "'"

  set DatabaseRecord = ConnectionToDB.Execute (SQLStr)

  TextMessage = DatabaseRecord("Message")

  response.write "<assign var=""Message""
value=""" & TextMessage & """/>"

  ConnectionToDB.Close
  set ConnectionToDB = nothing
%>

  <block>
    <text>$Message;</text>
    <playaudio value="http://www.myserver.com/greeting.wav"/>

    <recordaudio format="audio/wav"
value="mailto:my-email@my-email-server.com"
termdigits="#"
maxtime="60s"
maxsilence="10s"
beep="TRUE"/>

    <ontermdigit value="#">
      <text> Your message has been sent.</text>
    </ontermdigit>

    <onmaxtime>
      <text> You have reached maxtime.  Message sent.</text>
    </onmaxtime>

    <onmaxsilence>
      <text> Maxsilence exceeded.  Message sent.</text>
    </onmaxsilence>

  </block>
</callxml>


Notice that we put the ASP portion after the <callxml> element. This is becuase we want to use the callxml <assign> element from within the ASP section of code. All that you have to do is save this file as "helloworld.asp" (remembering to create and register a database file before trying to run the application).


Step 4: Upload, and try it out

Your server-side scripted callxml hello world application is now done. Call the number associated with your callxml application, and you'll find that you no longer have to call that local bank for the time.

  CallXML 2.0 source code.


What we covered




  ANNOTATIONS: EXISTING POSTS
0 posts - click the button below to add a note to this page

login
  tutorial Hello world with ColdFusion  |  TOC  |  tutorial Multi-party conferencing in CallXML   

© 2011 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site