作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试构建一个非常基本的 EMI 计算器。我想在不同的 intent 中捕获贷款金额和利率,然后做数学部分。但是,在捕获贷款金额并确认相同后,程序不会移动以捕获利率。
我只能达到 Alexa 确认贷款金额值(value)的程度。
请帮我理解为什么?
const Alexa = require('ask-sdk-core');
//Launch request and welcome message.
const LaunchRequestHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle(handlerInput) {
const speakOutput = 'Hello! Welcome to your E.M.I. Calculator. Please tell me the loan amount you want to calculate the E.M.I. for';
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
}
};
//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}.`;
// return handlerInput.responseBuilder.speak(speakOutput);
// return handlerInput.responseBuilder.speak(speakOutput).getResponse();
}
};
//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){
let interestRateCaptured = false;
while (!interestRateCaptured){
const speakOutput = 'Please tell me the interest rate';
interestRateCaptured = true;
return handlerInput.responseBuilder
.speak(speakOutput).getResponse();
}
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();
}
}```
最佳答案
欢迎堆叠 溢出 !
您的代码中有一些错误,我会尝试一一描述/修复它们。
您的 CaptureLoanAmountHandler
以简单结束 .speak
命令,这意味着 Alexa 会在她说完您让她说话的句子后立即关闭 session 。为了保持 session 打开,添加 .reprompt
到响应构建器(您也可以将 .shouldEndSession
与 false
参数一起使用,但从 UX 的 Angular 来看 .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
在单个处理程序运行中都可用。为了在其他 intent 中访问它们,您需要将它们存储在
SessionAttributes
中。
关于javascript - 尝试在 Alexa 中获取贷款金额和利率并计算 EMI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62688137/
我需要 Euribor 利率来计算网站上的抵押贷款利率。有谁知道是否有提供此数据的服务,可能是 XML 格式?RSS 提要可以,免费或付费。谢谢! 最佳答案 有这样的服务的商业供应商: http://
我是一名优秀的程序员,十分优秀!