Page 1 of 1

inline variables

Posted: Mon Feb 05, 2007 5:20 pm
by brent.russell
I am trying to set a variable at the top of my script, kind of like a configuration area and in there I want to specify some variables and later use them. However I want to add on to the variable as shown below

<var name="url" expr="'http://site.com:8080" />

Attempt 1:

Code: Select all

<prompt timeout="8s">
   <audio src=url."/voice_overs/VO2_.mp3">Please enter your cell phone number after the tone</audio>
</prompt>
Attempt 2:

Code: Select all

<prompt timeout="8s">
   <audio src=<value expr="document.tempPhoneNumber"/>."/voice_overs/VO2_.mp3">Please enter your cell phone number after the tone</audio>
</prompt>
Attempt 3:

Code: Select all

<prompt timeout="8s">
   <audio src="<value expr="document.tempPhoneNumber"/>/voice_overs/VO2_.mp3">Please enter your cell phone number after the tone</audio>
</prompt>
Obviously these are not going to work. Anyone help me out here?

easiest way to include javascript in your IVR application

Posted: Tue Feb 06, 2007 12:46 am
by support
Brent,

The easiest way to include javascript in your IVR application is to use the src attribute of the <script> tag. This allows you to reference an external javascript file that will load when the document is first parsed. You can include any valid javascript including functions, arrays and object declarations. Here is a simple IVR example:

script.js

Code: Select all

var test = 'asdf';
page1.vxml

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">
    <script src="script.js"/>
    <form>
        <block>
            The value of test is <value expr="test"/>
        </block>
    </form>  
</vxml>
Regards,
Plum Support

Posted: Tue Feb 06, 2007 1:08 pm
by brent.russell
I was not really asking about including javascript. What I need to do is make the src of an audio tage be a variable.



<audio src="http://www.site.com/voice_overs/VO2_.mp3">hello</audio>

simple IVR example using standard javascript notation

Posted: Tue Feb 06, 2007 1:25 pm
by support
Brent,

Apologies for misinterpreting your question. The correct approach to get dynamic URLs for audio (or any other tag that references remote files) is to use the expr attribute of the <audio> tag. The expr attribute will be parsed as javascript when the audio is played. This allows you to use standard javascript notation to concatenate the two strings. Here is a simple IVR example:

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">

<var name="url" expr="'http://site.com:8080'"/>

<form>
    <block>
        <prompt>
            <audio expr="url+'/voice_overs/VO2_.mp3'">Please enter your cell phone number after the tone</audio>
        </prompt>
    </block>
</form>

</vxml>
Regards,
Plum Support

Posted: Tue Feb 06, 2007 1:32 pm
by brent.russell
Thank you! So do almost all tags allow for the expr parameter? I noticed that the submit tag also does.

Posted: Tue Feb 06, 2007 1:40 pm
by brent.russell
I ran into another issue. I need to use the variable 2 times within a submit tag now:

<submit expr="document.url+'/index.php'" namelist="source user_name password request_type phone_number" method="post" fetchaudio="http://site.com:8080/voice_overs/unsubscribing.mp3"/>

As you can see I used expr in place of next as the documentation says however I need to use my variable for the fetchaudio. Now I am confused on what to do.

Thank you,
Brent

with limitations of IVR, better to use PHP for base URL

Posted: Tue Feb 06, 2007 2:47 pm
by support
Brent,

You have hit a limitation of VoiceXML. The best option for your IVR application is to use PHP and skip the use of javascript for the base url of these:

Code: Select all

<?php
$BASEURI = "http://site.com:8080";
echo("<?xml version=\"1.0\"?>\n");
?>
<vxml version="2.0">

<form>
    <block>
        <prompt>
            <audio src="<?php echo($BASEURI)?>/voice_overs/VO2_.mp3">Please enter your cell phone number after the tone</audio>
        </prompt>
        <submit src="<?php echo($BASEURI)?>/index.php" namelist="source user_name password request_type phone_number" method="post" fetchaudio="<?php echo($BASEURI)?>/voice_overs/unsubscribing.mp3"/> 
    </block>
</form>

</vxml>
Regards,
Plum Support