AMAZON.TIME槽位相对时间确认显示友好文本的实现方案问询
Absolutely, you can fix this issue and keep support for both relative and absolute times with a couple of straightforward approaches. Let’s break down how to make Alexa use friendly, natural language for confirmations instead of those cryptic codes:
1. Use Custom Slot Values & Synonyms (Easiest Fix)
This is the most streamlined way to handle relative time phrases. You can extend the AMAZON.TIME slot to map its internal codes to human-friendly terms:
- Head to your Alexa Skill Developer Console, open the Interaction Model tab, and find your
desiredTimeslot (typeAMAZON.TIME). - Add custom slot values with synonyms that cover both user phrases and Alexa's internal codes:
- Value:
morning, Synonyms:MO,early morning,first thing in the morning - Value:
afternoon, Synonyms:AF,late afternoon,mid-afternoon - Value:
evening, Synonyms:EV,late evening,night
- Value:
- Now when a user says "afternoon", Alexa will recognize the custom value and use "afternoon" in its confirmation prompt instead of "AF".
2. Manual Code Mapping in Your Skill Backend
If you need more control, you can add a simple mapping layer in your skill's code to convert Alexa's time codes to friendly text:
- First, grab the raw user input and Alexa's resolved slot value:
const desiredTimeSlot = handlerInput.requestEnvelope.request.intent.slots.desiredTime; const userInput = desiredTimeSlot.value; // The exact phrase the user said const resolvedCode = desiredTimeSlot.resolutions?.resolutionsPerAuthority[0]?.values[0]?.value.name; // e.g., "AF" - Create a mapping object for common time codes:
const timeCodeMap = { 'MO': 'morning', 'AF': 'afternoon', 'EV': 'evening', 'NI': 'night' }; - Use this map to generate your confirmation speech:
const friendlyTime = timeCodeMap[resolvedCode] || userInput; const confirmationPrompt = `Have I understood ${friendlyTime} correctly?`; - This method works seamlessly for absolute times too—if a user says "3 PM",
userInputwill already be a friendly string, so it gets used directly.
3. Dynamic Confirmation Prompts
You can also set up dynamic confirmation for the desiredTime slot in the Alexa Console:
- In the slot's settings, switch confirmation from "Static" to "Dynamic".
- Then use the code mapping logic above to return a tailored confirmation message based on the resolved slot value.
Quick Notes
- Alexa’s
AMAZON.TIMEuses standard codes likeMO,AF,EV,NIfor relative times—make sure your mapping covers these. - Absolute times (e.g., "October 5th at 2 PM") are returned as human-readable strings by default, so no extra work is needed for those.
With any of these approaches, Alexa will confirm relative times using natural language while still accepting absolute time inputs perfectly.
内容的提问来源于stack exchange,提问作者Jannik

