2017-07-18 88 views
5

我正在尝试开发一个Alexa技能,我需要获取相对时间,例如:“5分钟前”。在Alexa中获取相对时间

我为我的技能定义了一个时间段,接受时间如5 minutes,6.30 am4 in the morning。但我无法接受像5 minutes ago这样的时间。我新Alexa的,可以有一个人帮我这个

{ 
    "slots": [ 
    { 
     "name": "time", 
     "type": "AMAZON.TIME" 
    } 
    ], 
    "intent": "ReportTime" 
} 
+0

下面@Connum回答是一个很好的开始。请注意,除非您要求邮政编码信息并且可以自行处理,否则您可能会遇到与时区相关的问题,请参阅以下主题:https://stackoverflow.com/questions/44072625/how-do-i-get-a-users- date-time-or-timezone-information-for-an-alexa-skill –

回答

3

你可以“从现在开始”添加{modifier}插槽,可以采取几个关键字,例如“前”和。那么这样做的目的可能有类似如下的话语:

{ 
    "name": "TimeTest", 
    "samples": [ 
    "what happened {time} {modifier}", 
    "what will happen {time} {modifier}" 
    ], 
    "slots": [ 
    { 
     "name": "time", 
     "type": "AMAZON.TIME", 
     "samples": [] 
    }, 
    { 
     "name": "modifier", 
     "type": "custom_time_modifier", 
     "samples": [] 
    } 
    ] 
} 

与以下自定义修改器类型:

"types": [ 
{ 
    "name": "custom_time_modifier", 
    "values": [ 
    { 
     "id": null, 
     "name": { 
     "value": "ago", 
     "synonyms": [ 
      "in the past" 
     ] 
     } 
    }, 
    { 
     "id": null, 
     "name": { 
     "value": "from now", 
     "synonyms": [ 
      "in the future" 
     ] 
     } 
    } 
    ] 
} 
+0

这太好了。非常感谢(Y) –