在以下示例中: 如果用户说太妃糖,那不应该被翻译成糖果吗?我问,因为我的意图的价值是“太妃糖”。所以不确定我的错误。
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"
}
]
}
答案 0 :(得分:5)
我们需要在后端代码中处理实体解析。 更多内容可以在这里提到: 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);
另外,在处理程序函数
之外添加它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;
}
现在,当您的用户输入太妃糖时,它将被翻译为糖果。
答案 1 :(得分:3)
一般的响应JSON结构如下所示,因此要在一行中提取它
source = intent.slots.source.resolutions.resolutionsPerAuthority [0] .values [0] .value.name;
"request": {
"type": "IntentRequest",
"requestId": "amzn1.ech****************************************************************************************",
"timestamp": "2019-03-13T08:34:46Z",
"locale": "en-US",
"intent": {
"name": "STMDStreamStartIntent",
"confirmationStatus": "NONE",
"slots": {
"source": {
"name": "source",
"value": "source 1",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.e************************************************",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "source1",
"id": "SOURCE_ONE"
}
}
]
}
]
},
"confirmationStatus": "NONE",
"source": "USER"
}
}
}
}
希望这将是简单而有用的。