AMAZON.Number内置槽无法捕获序数词的技术问题咨询
Hey there! You’re absolutely not making a mistake here—this is a common gotcha with Alexa’s built-in slot types. The AMAZON.Number slot is built to capture cardinal numbers (like "1", "five", or "twenty"), not ordinal terms such as "first", "second", or "third" by default.
Luckily, there are a few solid solutions to handle this scenario:
1. Use the Built-in AMAZON.Ordinal Slot Type
Alexa actually has a dedicated slot type for ordinal inputs! AMAZON.Ordinal is designed specifically to recognize terms like "first", "second", "1st", "2nd", and even phrases like "the third one". When a user says one of these, the slot will return the corresponding cardinal number as its value (e.g., "first" becomes "1", "tenth" becomes "10"). This is the simplest and most reliable approach since it leverages Alexa’s pre-trained model for ordinal recognition.
2. Create a Custom Slot Type
If you need more control over the exact ordinal terms your skill accepts (or if you’re working with a limited set of options), you can create a custom slot type. Here’s how:
- In the Alexa Developer Console, navigate to your skill’s interaction model.
- Create a new custom slot (e.g.,
OrdinalChoice) and add all relevant ordinal terms as slot values (include synonyms like "1st" for "first", "2nd" for "second" to cover more user variations). - Update your intent to use this custom slot instead of
AMAZON.Number. - In your backend code, map the slot’s value to the corresponding index in your list (e.g., "first" → index 0 or 1, depending on how you’ve structured your list).
3. Post-Processing in Your Backend Code
If you want to stick with AMAZON.Number for some reason, you can add logic to convert ordinal text inputs to numbers. For example:
- Extract the raw user utterance or the slot’s resolved value from the request object.
- Use a lookup map to convert ordinal strings to their numeric equivalents:
const ordinalToNumber = { "first": 1, "second": 2, "third": 3, // Add as many as you need "1st": 1, "2nd": 2 }; const userInput = request.intent.slots.YourSlot.value.toLowerCase(); const selectedNumber = ordinalToNumber[userInput] || parseInt(userInput); - Just note that this requires maintaining the lookup map and handling edge cases where the user’s input doesn’t match any entries.
Whichever method you choose, be sure to test with a variety of user utterances to ensure your skill correctly captures and interprets ordinal inputs!
内容的提问来源于stack exchange,提问作者AkshayM

