【发布时间】:2019-03-19 23:00:42
【问题描述】:
我正在研究一种从银行名称和分行检索银行 ifsc 代码的简单技能。我已经实现了多轮对话,这意味着在插槽被填满之前涉及到对话。我在交互模型中有两个插槽。他们是银行和分支机构。两个插槽都需要。我为 BANK 槽提供了 200 条话语。
该技能首先提示用户输入银行名称。如果用户提供了无效的银行名称,例如“我不知道”。它识别出它不是有效的银行名称,并再次提示用户输入银行名称。但在这个过程中,它用“我不知道”填充 BRANCH 槽。我想保持插槽被填充的顺序。 BRANCH 槽不应该被填充,除非并且直到 BANK 槽被填充。我想确保 BRANCH 是一个有效的街道地址(这是 BRANCH 的 slotType)。如何强制执行填充槽值的顺序?请在下面找到 lambda 代码:
const InProgressIfscCodeIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
handlerInput.requestEnvelope.request.intent.name === 'ifscCode' &&
handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED'
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.getResponse();
}
};
const CompletedIfscCodeIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
handlerInput.requestEnvelope.request.intent.name === 'ifscCode'
},
async handle(handlerInput) {
if (!handlerInput.requestEnvelope.request.intent.slots.BANK.value) {
return handlerInput.responseBuilder
.speak("Let me know which IFSC code for which bank are you looking for ?")
.reprompt("Let me know which IFSC code for which bank are you looking for ?")
.addElicitSlotDirective('BANK')
.getResponse();
} else {
const bankName = handlerInput.requestEnvelope.request.intent.slots.BANK.value;
const branch = handlerInput.requestEnvelope.request.intent.slots.BRANCH.value;
// retrieve the bank details by calling the API
const bankDetails = await getBankDetails(bankName, branch);
console.log('--- length of the bank ---', bankDetails.banks.length);
if (bankDetails.banks.length > 0) {
console.log('-- bank details --', bankDetails);
const speechText = `IFSC code of the ${bankName}, ${branch} is
<break time="2s"/>
<emphasis level="strong"><say-as interpret-as='spell-out'>${bankDetails.banks[0].IFSC}</say-as></emphasis>.
<break time="2s"/>Try again for different bank by invoking open ifsc code finder.`;
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withShouldEndSession(true)
.getResponse();
} else {
const speechText = "We were not able to get the bank details. Please try again by invoking open ifsc code finder.";
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withShouldEndSession(true)
.getResponse();
}
}
}
};
此外,字符串“我不知道”不是有效的街道地址。到目前为止,为 100 万个地址训练模型不是可行的选择。我的问题是 BANK 插槽的无效值不应用作分支。我想在这里添加验证。请帮助我理解这里的内容。
谢谢
【问题讨论】:
标签: node.js aws-lambda alexa alexa-skills-kit