如何使用起始和结束数字循环遍历字段,在使用或不使用PHP的情况下将输入保存到VXML中的数组?
Psuedo代码类似于:
get startNo from caller
get endNo from caller
loop i from startNo to endNo
audio prompt 'prompt' + i + '.wav'
save input to results[i]
end loop
save results to database at end of loop or upon hangup
我知道如何获取开始和结束数字以及如何保存到数据库,这是我不确定的循环。
要求/其他说明:
答案 0 :(得分:3)
您的VXML看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<vxml version = "2.1">
<var name="currNo" expr="startNo"/>
<var name="userResponse"/>
<form id="getUserInput">
<field name="F_1" cond="currNo <= endNo">
<grammar srcexpr="currNo + '.xml'" type="application/grammar-xml"/>
<prompt>
<audio expr="currNo + '.wav'"/>
</prompt>
</field>
<filled>
<assign name="userReponse" expr="F_1"/>
<goto next="#handleResponse"/>
</filled>
</form>
<form id="handleResponse">
<block>
<!-- Send each result to PHP app as you get them -->
<!-- This way you will not loose any result on error or hangup -->
<!-- Assumes you have some user ID to associate the result with -->
<submit next="handleUserResponse.php" namelist="userId userResponse"/>
<!-- Increment counter -->
<assign name="currNo" expr="currNo + 1"/>
<!-- If the counter is greater than endNo then we are done -->
<if cond="currNo > endNo>
<submit next="endApplication.vxml"/>
<!-- Otherwise we loop back to get another response -->
<else/>
<goto next="#getUserInput"/>
</if>
</block>
</form>
</vxml>
这使您可以很好地了解如何处理循环并提交结果。我没有包含任何错误处理。