0

How to concat varible in VXML. consider following example VXML,

<?xml version="1.0" encoding="UTF-8"?>
<vxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.w3.org/2001/vxml" version="2.0" xsi:schemaLocation="http://www.w3.org/2001/vxml  http://www.w3.org/TR/voicexml20/vxml.xsd">
    <form>
        <block>
            <audio src="{url1}"/>
            <audio src="{url2}"/>
        </block>
        <field name="dtmf">
            <option dtmf="1" value="1"/>
            <option dtmf="2" value="2"/>
            <option dtmf="2" value="3"/>
            <filled>
                <submit next="{url3}" namelist="action toneId dtmf" method="get"/>
            </filled>
        </field>
        <noinput>
            <reprompt/>
        </noinput>
        <nomatch>
            <reprompt/>
        </nomatch>
    </form>
</vxml>

{url3} = {some string} + {some variable=value}, I want to get like this, There are url3 get concating two value.

Thilina Sampath
  • 3,615
  • 6
  • 39
  • 65

2 Answers2

1

Change:

<submit next="{url3}" namelist="action toneId dtmf" method="get"/>

to

<submit expr="{some string} + {some variable=value}" namelist="action toneId dtmf" method="get"/>

or for a more concrete example:

<submit expr="'http://yourserver.com/api/' + servletName" namelist="action toneId dtmf" method="get"/>
Jim Rush
  • 4,143
  • 3
  • 25
  • 27
  • please tell me how to get – Thilina Sampath Sep 02 '15 at 19:32
  • I think I'm confused by your request. If you mean you want the input value to be in the url, replace my use of servleName with the fieldname, dtmf as it will be set to the input value. You are already providing the input as part of the request arguments. – Jim Rush Sep 02 '15 at 23:00
  • Thank that is I want but want know little bit about concrete two **vxml** variable. – Thilina Sampath Sep 03 '15 at 03:35
  • 1
    Variable concatenation is a feature of Javascript, not VoiceXML. You can concatenate anywhere you can use Javascript in VoiceXML. For example, expression or script block. To concatenate two values, you can use the + operator so long as one of the arguments is a string. If not, add an empty string to the beginning: '' + varX + varY – Jim Rush Sep 03 '15 at 16:58
1

The previous answer is correct, but let me add an additional line or two that shows how to use namelist and field.

<field name="dtmf">

That name is a bit confusing.You're defining a variable name, and "dtmf" is used elsewhere in the document; let's call it "response" instead to avoid problems.

<field name="response">

You allow for options, which is fine:

<option dtmf="1" value="1"/>
<option dtmf="2" value="2"/>
<option dtmf="2" value="3"/>

Of course the values can be anything, such as

<option dtmf="1" value="meat"/>
<option dtmf="2" value="fish"/>
<option dtmf="2" value="dairy"/>

and I want to point out here that the value above does not accept an ECMAScript value; it's just plain text, one of the oddities of VoiceXML.

Set up the values of the other variables you want to send:

<var name="toneId" expr="12"/>
<var name="action" expr="'scream'"/>

And expr does require an ECMAScript expression. "toneID" is set to a Number and "action" has been set to a String. You can also do this instead, if you need to:

<var name="foo" expr="'scream'"/>
<var name="action" expr="foo"/> 

The field "response" will be filled in automatically with the value the user selected. You can also use the so-called "shadow variables" if you like and send them instead; see the VoiceXML spec http://www.w3.org/TR/2004/REC-voicexml20-20040316/#dml2.3.1.

Finally, as Jim says,

<submit expr="'http://example.com/api/' + servletName" namelist="action toneId response" method="get"/>

Hope this helps.