Amazon Alexa is gradually starting to get more traffic. As a developer, you can surely take advantage of it. In this article, let’s see how to handle dates in Alexa skill development.
Before we begin, if you are completely new to Alexa skill development then please check out this blog to know the basics of developing skill in Alexa by clicking here. And if you are someone who doesn’t want to develop a skill in Alexa but curious about how it works then check this article.
If you have made up your mind to develop skills on Alexa, then surely you cannot escape date handling (at least in the longer run). So this article is going to be focussed only on the date and that does not include time. Handling time is kind of a complex part that I will be discussing in future blogs.
There are two ways to handle dates on Alexa. They are
- Using AMAZON.DATE slot
- Using three separate slots for the day, month, and year.
If your requirement is quite clear and you need to capture the exact date that the user says then this is the straightforward solution. This comes with an added advantage where users can also say “today”, ”tomorrow”, ”yesterday”, ”last Sunday”, etc instead of saying the complete date every time. There are many other leverages that you can make use of, using this official documentation by Alexa.
Three separate slots for the day, month and year
What if you need to get only the month, date or year, or a combination of these three? That is exactly what we are going to see now. Let us understand using an example skill, where we will be getting the date of birth from the user.
Create an intent with whatever name you want, in my case I name it as RegisterBirthdayIntent. Then add the sample utterances as shown above which includes the place holder for month day and year. You can find Intent Slots filled with the names of the slots without slot type. Select AMAZON.Ordinal, AMAZON.Month and AMAZON.FOUR_DIGIT_NUMBER for the day, month, and year respectively. If required, Click the edit dialog button to make the slot required and add appropriate phrases.
Finally, proceed with the usual drill of saving the model and building it. In the backend (lambda), get the slot values and handle them appropriately as required.
Imagine you don’t have a built-in slot type called AMAZON.Month, then what will you do? In that case, we can make use of the custom slot.
In this article, you learned how to handle dates on Alexa. To sum it up, use date slot type for dates or use three separate slot types for the day, month and year respectively.