我正在尝试构建一个非常基本的EMI计算器。我想分别捕获贷款金额和利率,然后做数学部分。但是,在获取贷款金额并确认相同金额之后,该程序将无法获取利率。
我只能到达Alexa确认贷款金额的值。
请帮助我理解为什么?
Unset Printing Notations. (* In CoqIDE, you're told to set this from the view menu instead *)
Check N.discr.
(* Shows you that the notation stands for sig *)
答案 0 :(得分:2)
欢迎堆叠溢出!
您的代码中存在一些错误,我将尝试一一描述/修复它们。
您的CaptureLoanAmountHandler
以简单的.speak
命令结束,这意味着Alexa在您说完一句话之后就立即关闭会话。为了使会话保持打开状态,请将.reprompt
添加到响应构建器中(您也可以将.shouldEndSession
与false
参数一起使用,但是从UX的角度来看,.reprompt
更好)并为用户添加一些与技能互动的线索:
//capture the loan amount, save it in local variable and confirm to user the amount.
const CaptureLoanAmountHandler = {
canHandle(handlerInput){
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'captureloanamount';
},
async handle(handlerInput){
const currencyName = handlerInput.requestEnvelope.request.intent.slots.currency.value;
const loanAmount = handlerInput.requestEnvelope.request.intent.slots.loanamount.value;
const speakOutput = `Ok, I have captured the loan amount as ${currencyName} ${loanAmount}. Now tell me your interest rate`;
return handlerInput
.responseBuilder
.speak(speakOutput)
.reprompt('Say: interest rate is...')
.getResponse();
}
};
您的CaptureInterestRateHandler
不应包含while
循环。在您的代码中,由于您在第一次运行中将防护设置为true
,因此它将仅运行一次;)
//Prompt user for interest rate and capture it
const CaptureInterestRateHandler = {
canHandle(handlerInput){
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'captureinterestrate';
},
async handle(handlerInput){
const iRate = handlerInput.requestEnvelope.request.intent.slots.roi.value;
const speakOutput1 = `Ok, I have captured the interest rate as ${iRate}`;
return handlerInput.responseBuilder.speak(speakOutput1).getResponse();
}
}
我想在收集所有输入数据时应该做一些计算。
根据您的评论:
//capture the loan amount, save it in local variable and confirm to user the amount.
我假设您希望以后在其他Intent处理程序中看到贷款金额值-恐怕您不会:(。所有变量,甚至const
在单个处理程序运行中都可用。为了访问它们出于其他目的,您需要将它们存储在SessionAttributes
中。
除了看上去更接近Dialog-扰流板警报-它只是在幕后进行所有与对话框相关的魔术,最后您获得了对;)的要求