the*_*ver 3 alexa aws-lambda alexa-skill alexa-skills-kit alexa-voice-service
在以下示例中:如果用户说太妃糖,那不应该翻译成糖果吗?我问,因为传递给我的意图的价值是“太妃糖”。所以不确定我有什么不对。
types":[
{
"name":"SHOPPING_LIST",
"values":[
{
"id":null,
"name":{
"value":"candy",
"synonyms":[
"toffee"
]
}
},
{
"name":"GetPrice",
"samples":[
"Get me the price of {item}",
"tell me the price of {item}",
],
"slots":[
{
"name":"item",
"type":"SHOPPING_LIST"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我们需要在您的后端代码中处理实体解析。更多信息可以在这里参考:https : //developer.amazon.com/blogs/alexa/post/5de2b24d-d932-4c6f-950d-d09d8ffdf4d4/entity-resolution-and-slot-validation
您可以在代码中添加,
this.attributes.item = slotValue(this.event.request.intent.slots.item);
Run Code Online (Sandbox Code Playgroud)
另外,将此添加到您的处理函数之外,
function slotValue(slot, useId){
let value = slot.value;
let resolution = (slot.resolutions && slot.resolutions.resolutionsPerAuthority && slot.resolutions.resolutionsPerAuthority.length > 0) ? slot.resolutions.resolutionsPerAuthority[0] : null;
if(resolution && resolution.status.code == 'ER_SUCCESS_MATCH'){
let resolutionValue = resolution.values[0].value;
value = resolutionValue.id && useId ? resolutionValue.id : resolutionValue.name;
}
return value;
}
Run Code Online (Sandbox Code Playgroud)
现在,当您的用户输入太妃糖时,它将被翻译为糖果。
归档时间: |
|
查看次数: |
1102 次 |
最近记录: |