We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

inline variables

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
brent.russell
Posts: 50
Joined: Wed Oct 04, 2006 1:34 pm
Location: SOCAL
Contact:

inline variables

Post 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?

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

easiest way to include javascript in your IVR application

Post 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
Last edited by support on Sat Feb 20, 2010 3:36 pm, edited 3 times in total.

brent.russell
Posts: 50
Joined: Wed Oct 04, 2006 1:34 pm
Location: SOCAL
Contact:

Post 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>

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

simple IVR example using standard javascript notation

Post 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
Last edited by support on Wed Jan 13, 2010 4:28 pm, edited 2 times in total.

brent.russell
Posts: 50
Joined: Wed Oct 04, 2006 1:34 pm
Location: SOCAL
Contact:

Post by brent.russell »

Thank you! So do almost all tags allow for the expr parameter? I noticed that the submit tag also does.

brent.russell
Posts: 50
Joined: Wed Oct 04, 2006 1:34 pm
Location: SOCAL
Contact:

Post 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

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

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

Post 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

Post Reply