【问题标题】:When I run my vxml application I get this syntax error当我运行我的 vxml 应用程序时,我得到了这个语法错误
【发布时间】:2017-03-23 05:26:12
【问题描述】:

我在运行 vxml 应用程序时收到此错误;

"ECMAScript 运行时错误:编译产生 1 个语法 错误。\n\n评估时:\n\"var acc_no = [37492414, 94190610, 23228367, 39574988, 64742440];\n\t\t\t\t\tfunction checkAccount(arr, val) {\n\t\t\t\t\treturn arr.some(arrVal => val === arrVal);\n\t\t\t\t\t\t\t\t\t\t\t} \"";

这是我出现错误的 vxml 脚本:

<?xml version="1.0" encoding="UTF-8"?> 
<vxml xmlns:voxeo="http://community.voxeo.com/xmlns/vxml"
      version="2.1" xml:lang="en-US"
       xml:base="http://webhosting.voxeo.net/201985/www/">


    <property name="inputmodes" value="dtmf"/> 
    <property name="termchar" value="#"/>
    <property name="interdigittimeout" value="2s"/>
    <property name="bargein" value="false"/>
    <var name = "accountNumber"/>
    <var name = "pinNumber"/> 


    <form id="userAuth" scope="document">
        <var name="iMaxTries" expr="3"/>
        <var name="iTriesAcc" expr="0"/>
        <var name="iTriesPin" expr="0"/>
        <var name="fatal" expr="'We are having technical difficulties validating your credentials. Try back later.'"/>

    <catch event="event.pinNumber.invalid">
    <!-- increment the attempt counter; if the count is exceeded, disconnect -->
        <assign name="iTriesPin" expr="iTriesPin+1"/>
        <if cond="iMaxTries == iTries">
            <value expr="fatal"/>
            <disconnect/>
        <else/>
    <!-- clear is unnecessary on a nomatch, but we use the same code to handle a bad filled -->
            <clear namelist="pinNumber"/>
            <reprompt/>
        </if>
    </catch>
    <catch event="event.accountNumber.invalid">
    <!-- increment the attempt counter; if the count is exceeded, disconnect -->
        <assign name="iTriesAcc" expr="iTriesAcc+1"/>
        <if cond="iMaxTries == iTries">
            <value expr="fatal"/>
            <disconnect/>
        <else/>
    <!-- clear is unnecessary on a nomatch, but we use the same code to handle a bad filled -->
            <clear namelist="accountNumber"/>
            <reprompt/>
        </if>
    </catch>
    <!-- exec this on the first and second noinput/nomatch -->
    <!-- each event has its own counter -->
    <catch event="noinput">
        I'm sorry. I didn't get you.
        <reprompt />
    </catch>

    <!-- exec this on the third nomatch -->
    <catch event="nomatch">
        <throw event="event.password.invalid"/>
    </catch>

    <!-- silently disconnect on the third noinput -->
    <catch event="noinput" count="3">
        <disconnect/>
    </catch>


    <field name="accountNumber" type="digits?length=8">
        <prompt> Please enter your account number followed by the pound key. </prompt>
            <grammar mode="dtmf" version="1.0" root="pin"
                tag-format="semantics/1.0">
                <rule id="digit" scope="public" >
                    <one-of>
                        <item> 0 </item>
                        <item> 1 </item>
                        <item> 2 </item>
                        <item> 3 </item>
                        <item> 4 </item>
                        <item> 5 </item>
                        <item> 6 </item>
                        <item> 7 </item>
                        <item> 8 </item>
                        <item> 9 </item>
                   </one-of>
               </rule>

               <rule id="pin" scope="public">
                    <tag>out=""</tag>
                        <item repeat="8">
                            <ruleref uri="#digit"/>
                            <tag>out += rules.latest( );</tag>
                       </item>
               </rule>
           </grammar>


        <filled> 
               <script> <![CDATA[
                    var acc_no = [37492414, 94190610, 23228367, 39574988, 64742440];
                    function checkAccount(arr, val) {
                    return arr.some(arrVal => val === arrVal);
                                            }
                ]]> </script>

                <block>
                    <var name="chk_acc" expr="checkAccount(acc_no, accountNumber);"/>

                    <if cond="chk_acc =='true'">
                        <goto next="#pinNumber"/>
                    <else/>
                        <prompt>Sorry, Account number not recognised. </prompt>
                        <throw event="event.accountNumber.invalid"/>
                    </if>
                </block>

         </filled>
    </field>

    <field name="pinNumber" type="digits?length=4">
        <prompt> please enter your four digit pin followed by the pound key. </prompt>
        <grammar mode="dtmf" version="1.0" root="pin"
         tag-format="semantics/1.0">
         <rule id="digit" scope="public" >
            <one-of>
               <item> 0 </item>
               <item> 1 </item>
               <item> 2 </item>
               <item> 3 </item>
               <item> 4 </item>
               <item> 5 </item>
               <item> 6 </item>
               <item> 7 </item>
               <item> 8 </item>
               <item> 9 </item>
            </one-of>
         </rule>

         <rule id="pin" scope="public">
            <tag>out=""</tag>
            <item repeat="4">
               <ruleref uri="#digit"/>
               <tag>out += rules.latest( );</tag>
            </item>
         </rule>
       </grammar>

          <filled>

            <script> <![CDATA[
                    var pin_no = [2414, 0610,8367, 4988, 2440];
                    function checkPin(arr, val) {
                    return arr.some(arrVal => val === arrVal);
                                            }
                ]]> </script>

                <block>
                    <var name="chk_pin" expr="checkPin(pin_no, pinNumber);"/>

                    <if cond="chk_pin =='false'">
                        <prompt>Sorry, you have entered is an invalid pin. Please try again </prompt>
                        <throw event="event.pinNumber.invalid"/>    

                    </if>
                </block>

          </filled>
    </field>

    <filled mode="all" namelist="accountNumber pinNumber">


    <script> <![CDATA[
        var accDetails = [
        {acc_name: 'Lawrence Burkins', account: 37492414, pin: 2414, acc_type: 'checking', acc_bal: 2372351.74 , acc_br:'Montreal'},
        {acc_name: 'Ola Macaulay', account: 94190610, pin: 0610, acc_type: 'checking', acc_bal: 908242.49 , acc_br:'Tisdale'},
        {acc_name: 'Judy Cefalu', account: 23228367, pin: 8367, acc_type: 'checking', acc_bal: 15700526.57 , acc_br:'Toronto'},
        {acc_name: 'Mellisa Garcia', account: 39574988, pin: 4988, acc_type: 'checking', acc_bal: 568201.26 , acc_br:'Prince Albert'},
        {acc_name: '', account: 64742440, pin: 2440, acc_type: 'checking', acc_bal: 1952000.00 , acc_br:'Fort McMurray'},
                        ];

        function accDetails(details) { 
                return details.account === accountNumber ;
                            }
                var newDetail = accDetails.find(accDetails);
                var myDetail = [newDetail];
                var myBal = myDetail.slice(0, 4);

    ]]> </script>

        <var name = "accountBalance" expr = "myBal.toString()"/>

        <prompt>
        Your Checking account balance is <prosody rate="slow"><say-as type="currency"> $ + <value class="currency" expr="accountBalance"/> </say-as></prosody>
        </prompt>
        <goto next="after_bal.vxml"/>   
    </filled>
    </form>

 </vxml>

我还是 vxml 和 ecmascript 的新手。

【问题讨论】:

  • 取决于 VXML 浏览器。例如,GVP MCP 使用旧版本的 SpiderMonkey,因此新的 Javascript 功能无法在其上运行。您的 VXML 浏览器支持什么版本的 Javascript?

标签: ecmascript-5 vxml


【解决方案1】:

有问题的 ECMAScript 在语法上似乎是正确的:

var acc_no = [37492414, 94190610, 23228367, 39574988, 64742440];
                    function checkAccount(arr, val) {
                    return arr.some(arrVal => val === arrVal);
                                        }

我建议打破这种零碎的做法并降低 VXML 代码的复杂性来调试它。使用带有一个简单字段的非常基本的 VXML 文件,将上面的 ECMAScript 放入填充部分,然后查看是否出现相同的错误。如果这样做,请在代码中将脚本进一步向上移动(即不在填充部分中)并再次检查是否遇到相同的错误。

由于换行等原因,错误语句有点混乱。当您第一次看到错误消息时,它看起来像吗?

【讨论】:

    猜你喜欢
    • 2022-08-15
    • 2021-05-04
    • 1970-01-01
    • 2014-10-25
    • 1970-01-01
    • 2022-06-25
    • 2021-01-14
    • 1970-01-01
    • 2015-02-04
    相关资源
    最近更新 更多