2017-07-18 90 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) –