CallXML 3.0 Development GuideHome  |  Frameset Home

  tutorial Hello World with PHP  |  TOC  |  tutorial Hello World with ASP  

Tutorial: Hello world with ColdFusion

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 PHP, but this time around we will look at ColdFusion. This Lesson is based on the things you accomplished in the standard Voxeo tutorials. If you do not have a basic knowledge of Callxml, you'll need to go through previous Lessons, else you might just be left in the dust. This Lesson also assumes that you have a basic knowledge of ColdFusion, and that you have access to a web server that is running ColdFusion 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: creating our initial callxml structure

From our previous tutorials, we now recognize the following structure as a normal starting point:


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

  <do>
  </do>

</callxml>

One of the benefits of ColdFusion is that syntactically, it mixes with CallXML fluidly. Thus, we can start our ColdFusion script out in the same way as our normal callxml scripts.


Step 2: Using ColdFusion elements to determine the current date/time


Before we can read the date and time to the caller, we will have to store that value in a ColdFusion variable.


<do>
  <cfset TodaysDate = Now()>


Here we set our variable "TodaysDate" using the Now() function. Now we will want to parse that variable and output some text to the caller via the callxml text-to-speech element.


  <cfoutput>
  <say>
  </say>
  </cfoutput>


Here we see the preparatory tags for our eventual output. Everything we do will be between the ColdFusion "cfoutput" tags because we are using ColdFusion variables, and between the callxml <say> tags because we want to read the information that is being output.


    <cfif #DatePart("h", TodaysDate)# less than 10>
      oh
      #Datepart("h", TodaysDate)#
      hundred hours
      and
      #DatePart("n", TodaysDate)#
      minutes.
    <cfelse>
      #DatePart("h", TodaysDate)#
      hundred hours and
      #DatePart("n", TodaysDate)#
      minutes.
    </cfif>


These lines implement a conditional statement that examines the hour (since we are using a 24 hour format without AM or PM). If that hour is less than 10, we want to tack on the word "oh" so that it reads "oh 8 hundred hours" instead of "8 hundred hours." So if the current time were 2:45pm, it would read "14 hundred hours and 45 minutes." The output lines have been separated to make it easier to read -- there does not have to be a carriage return between the ColdFusion functions and the normal output.


      The date is
      #DayofWeekAsString(DayOfWeek(TodaysDate))#,
      #MonthAsString(Month(TodaysDate))#,
      #Day(TodaysDate)#
      #DatePart("yyyy", TodaysDate)#.

      There are
      #DaysInMonth(TodaysDate)#
      days in this month.
      We are in week
      #Week(TodaysDate)#
      of the year
      #Year(TodaysDate)#


Here we have some more complex ColdFusion date/time functions. Still, they are ultimately just sending output that is read over the phone. They could all be on the same line, but have been separated for clarity. If the date were 24 August 2000, this would read: "The date is Thursday, August 24 2000. There are 31 days in this month. We are in week 35 of the year 2000."


      <cfset DaysLeft = #DaysinYear(TodaysDate)# -
                        #DayofYear(TodaysDate)#>

      There are
      #DaysLeft#
      days left in this year.


While we are here, we might as well tell the caller how many days are left in the current year. To do that we have to set another variable, using a bit of simple math to subtract the current day from the total days in the year. Again, the output lines have been separated for clarity only. If the date were 24 August 2000, this snippet would read: "There are 129 days left in this year."


  </do>
</callxml>


These lines generate callxml that close our block and callxml script. The resulting file should read:


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

  <do>
  <cfset TodaysDate = Now()>

  <cfoutput>
    <say>

    <cfif #DatePart("h", TodaysDate)# less than 10>
      oh #Datepart("h", TodaysDate)# hundred hours and
      #DatePart("n", TodaysDate)# minutes.
    <cfelse>
      #DatePart("h", TodaysDate)# hundred hours and
      #DatePart("n", TodaysDate)# minutes.
    </cfif>

      The date is #DayofWeekAsString(DayOfWeek(TodaysDate))#,
      #MonthAsString(Month(TodaysDate))#, #Day(TodaysDate)#
      #DatePart("yyyy", TodaysDate)#.

      There are #DaysInMonth(TodaysDate)# days in this month.
      We are in week #Week(TodaysDate)# of the year
      #Year(TodaysDate)#.

      <cfset DaysLeft = #DaysinYear(TodaysDate)# -
                        #DayofYear(TodaysDate)#>

      There are #DaysLeft# days left in this year.

    </say>
    </cfoutput>
  </do>
</callxml>


Notice that we consolidated some our lines (again, you can mix variables and callxml output on the same line). Now all that we need to do is save this file as "helloworld-time.cfm".



Step 3: 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 3.0 source code.


What we covered