我正在尝试创建一个模型抵押贷款功能来学习API.ai webhooks,它正在调用一个计算每月抵押贷款支付的函数。由于某种原因,这不会向API.ai发送任何内容,并在JSON中显示错误消息“Webhook调用失败。错误:500内部服务器错误”。 (我知道代码效率低下,但一旦工作,我就会清理它)
这里叫它:
var bankNames = assistant.getArgument('bankName');
var arrayLength = bankNames.length;
var avgYearPercent = getRandomDouble(2.5,4.2);
var monthsLeft = 12;
var loanAmount = getRandomInt(100000,300000);
var output = '';
for (var i = 0; i < arrayLength; i++)
{ //calcMonthlyPayments(avgPercent, monthsLeft, loanAmount)
var speech = bankNames[i] + " has an outstanding loan of " + loanAmount + " and your monthly payment is currently " + String(calcMonthlyPayments(avgPercent, monthsLeft, loanAmount));
output = output.concat(speech);
}
output = '<speak>' + output + '</speak>';
assistant.ask(output);
这就是功能:
function calcMonthlyPayments(avgYearPercent, monthsLeft, loanAmount)
{
var i = (avgYearPercent/12)/100;
var r = 1/(1+i);
var L = loanAmount;
var n = monthsLeft;
var P = (L*((1-r)/(r-(Math.pow(r, n+1))))).toFixed(2);
return P;
}