我正在使用ASK-SDK v2创建一个基本的计算器技能。我不确定如何在新版本中将用户提供的槽值放入Lambda代码中。我能够让它与旧版本一起工作。
对话用户:打开calculate Alexa:你可以要求我进行加、减、乘、除用户:将2加3 Alexa: 2加3的和是5
下面是我的IntentSchema
{
"interactionModel": {
"languageModel": {
"invocationName": "calculate",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "AddIntent",
"slots": [
{
"name": "numA",
"type": "AMAZON.NUMBER"
},
{
"name": "numB",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"Sum of {numA} and {numB}",
"add {numA} and {numB}"
]
},
{
"name": "SubIntent",
"slots": [
{
"name": "numA",
"type": "AMAZON.NUMBER"
},
{
"name": "numB",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"difference between {numA} and {numB}",
"subtract {numA} from {numB}"
]
},
{
"name": "ProductIntent",
"slots": [
{
"name": "numA",
"type": "AMAZON.NUMBER"
},
{
"name": "numB",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"multiply {numA} and {numB}",
"product of {numA} and {numB}"
]
},
{
"name": "DivideIntent",
"slots": [
{
"name": "numA",
"type": "AMAZON.NUMBER"
},
{
"name": "numB",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"divide {numB} by {numA}",
"divide {numA} by {numB}"
]
},
{
"name": "ExponentialIntent",
"slots": [
{
"name": "numA",
"type": "AMAZON.NUMBER"
},
{
"name": "numB",
"type": "AMAZON.NUMBER"
},
{
"name": "numC",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"{numA} raised to the power of {numB} by {numC}",
"{numA} raised to the power {numB}"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
}
],
"types": []
}
}
}我在这里添加了addintenthandler。请告诉我,我从意图中获取槽值的方法是否正确,或者我是否应该使用sessionattribute
const AddIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AddIntent';
},
handle(handlerInput) {
var output1 = "";
var num1 = handlerInput.resuestEnvelope.request.intent.slots.numA.value;
var num2 = handlerInput.resuestEnvelope.request.intent.slots.numB.value;
if((num1)&&(num2)){
output1 = 'The sum of ' +num1+ ' and ' +num2+ ' is ' + (num1+num2);
}
else {
output1 = 'Enter valid number';
}
const speechText = output1;
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};Alexa回复"Unable to process skill response“欢迎任何帮助
发布于 2019-02-19 18:03:38
更新: SDK中现在有了内置函数: Alexa.getSlotValue(handlerInput.requestEnvelope,“someSlotName”的Alexa.getSlotValue() (返回字符串值)和getSlot() (返回Slot对象)
老答案:你有一个拼写错误,resuestEnvelope应该是requestEnvelope。在任何情况下,我都创建了完全相同的技能,一个计算器(在西班牙语中,但它基本上是相同的东西),并且我使用了一个称为getSlotValues()的辅助函数,我鼓励您重用它。当您必须捕获自定义插槽(处理方式不同,因为实体解析结构不同)时,它也会很好地工作:
https://github.com/germanviscuso/skill-sample-nodejs-mycalculator
https://stackoverflow.com/questions/54742339
复制相似问题