Search code examples
alexa-skills-kitalexa-slot

Getting Relative Time in Alexa


I'm trying to develop an Alexa skill, and I need to get the relative time, eg: "5 minutes ago".

I have defined a time slot for my skill which accepts time like 5 minutes, 6.30 am or 4 in the morning. But I'm not able to accept a time like 5 minutes ago. I new to Alexa and can some one help me out with this

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

Solution

  • You could add a {modifier} slot that can take several keywords like "ago" and "from now". The intent could then have something like the following utterances:

    {
      "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": []
        }
      ]
    }
    

    with the following custom modifier type:

    "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"
            ]
          }
        }
      ]
    }