Showing posts with label VXML. Show all posts
Showing posts with label VXML. Show all posts

Wednesday, September 01, 2010

VXML and Groovy's MarkupBuilder

For the last ~1.5 years I have been working with IVR applications. The framework we use is Java based and we use an Eclipse based IDE with a nice drag and drop editor to create the application's call flow. The IVR application is packaged into a .war or .ear file by the IDE and we deploy the application to a Web container like Tomcat. The IVR is then pointed at the application's entry point URL. The core flow is mapped into Servlets and each request into the application generates VXML (Voice XML) that is interpreted by the actual IVR which is responsible for handling call control and communicating with the other telephony technologies.

I think there could/should be a way to use Groovy's MarkupBuilder and most likely Gaelyk to create IVR applications with less ceremony than using the drag and drop editor. We can create static VXML very simply with Groovy's MarkupBuilder:

import groovy.xml.MarkupBuilder

def writer = new StringWriter()
def vxml = new MarkupBuilder()

vxml.vxml {
    field (name:"color") {
        grammar ("red | green | blue")
        prompt (count: 1, "Say red, green or blue.")
        prompt (count: 2, "Please say red, green or blue.")
        noinput (count: 1) {
            prompt ("I didn't hear you." )
            reprompt ()
        }
        noinput (count: 2) {
            prompt ("Sorry, I still didn't hear you.")
            reprompt ()
        }
        nomatch (count: 1) {
            prompt ("I didn't understand you." )
            reprompt ()
        }
        nomatch (count: 2) {
            prompt ("Sorry, I still didn't understand you.")
            reprompt ()
        }
    }
}

writer.toString()

Here is the output of the above:

<vxml>
    <field name='color'>
        <grammar>red | green | blue</grammar>
        <prompt count='1'>Say red, green or blue.</prompt>
        <prompt count='2'>Please say red, green or blue.</prompt>
        <noinput count='1'>
            <prompt>I didn't hear you.</prompt>
            <reprompt />
        </noinput>
        <noinput count='2'>
            <prompt>Sorry, I still didn't hear you.</prompt>
            <reprompt />
        </noinput>
        <nomatch count='1'>
            <prompt>I didn't understand you.</prompt>
            <reprompt />
        </nomatch>
        <nomatch count='2'>
            <prompt>Sorry, I still didn't understand you.</prompt>
            <reprompt />
        </nomatch>
    </field>
</vxml>


Then, if a nice, simple DSL (Domain Specific Language) is designed for building IVR applications with Groovy, we can then simplify the craft of creating IVR applications. Plus, we would gain the productivity of using Groovy when calling Web services and databases to provide dynamic data for the application. Just a crazy thought.