Today we are excited to announce the general availability of Multi-Value Slots, taking a step toward enabling Alexa Skills to understand more complex commands and utterances. As skill developers, you spend a lot of time developing interactions to be more natural and conversational so your customers can have a memorable experience with your skill. One thing that makes conversations more natural is the ability to speak out multiple values of the same type in a single sentence, similar to what we do in our daily conversations. For example, my partner and I could be discussing dinner plans, and I would say, “What can we cook with potatoes and broccoli for dinner?” If you want your customers to be able to have similar conversations with your Alexa skill, you can use Multi-Value Slots in your skill.
Without Multi-Value Slots, here’s how you might have implemented that conversation within your skill.
Customer : Alexa, open recipe suggestions.
Alexa : Welcome to recipe suggestions. Tell me the first ingredient you have today?
Customer : I have potatoes.
Alexa : Got it. what’s the second ingredient you want today?
Customer : Some broccoli
Alexa : Got it. Based on the ingredients you have, Italian Potatoes and Broccoli sounds like a good idea.
With Multi-Value Slots, your Alexa Skill can collect multiple slot values for one slot in the intent. So your conversation looks like this
Customer : Alexa, open recipe suggestions
Alexa : Welcome to recipe suggestions. What are the ingredients you have today?
Customer : I have some potatoes and broccoli.
Alexa : Awesome. As per your ingredients, you can cook Italian Potatoes and Broccoli today.
Multi-Value Slots reduce the amounts of turns in a conversation. Instead of having to ask the customer multiple questions or stringing together multiple slots to get the desired values, you can now use a single slot and capture all the values with Multi-Value Slots.
To enable Multi-Value Slots within your skill, here’s what you need to do
2. Clicking on the slot opens up the Slot Detail page. Here ingredients is a custom slot type named Vegetables that I created. On this page, enable the Multi-Value setting to indicate that the slot can collect multiple values. Once done, save and build your model.
3. To handle and process the slot values in your skill’s backend, we will have to make some changes to the backend code. For this skill, I am using the ASK SDK in Nodejs hosted in a Lambda function. We start off by defining a getFirstResolvedEntityValue function, which looks at the resolutionsPerAuthority slot object and retrieves entity with highest confidence score.
const getFirstResolvedEntityValue = (element) => {
const [firstResolution = {}] = element.resolutions.resolutionsPerAuthority || [];
return firstResolution && firstResolution.status.code === 'ER_SUCCESS_MATCH'
? firstResolution.values[0].value.name
: null;
};
4. Once we retrieve the entities, we will call the getFirstResolvedEntityValue helper function and get a list of all the values. We can now concatenate all the multiple slot values in a single string or use it for further processing.
// Concatenates all captured slot values to a single string.
const getReadableSlotValue = (handlerInput, slotName) => {
const rootSlotValue = Alexa.getSlotValueV2(handlerInput.requestEnvelope, slotName);
const PAUSE = '<break time="0.25s"/>';
const slotValueStr = !rootSlotValue
? 'None'
: Alexa.getSimpleSlotValues(rootSlotValue)
.map(
(slotValue) =>
getFirstResolvedEntityValue(slotValue) || `${slotValue.value}`
)
.join(' ');
return `${slotName} ${PAUSE} ${slotValueStr}`;
};
5. And finally, within the SuggestRecipeIntentHandler, we will call the getReadableSlotValue function and pass the ingredients slot. This will return us the single string generated and we can use it to inform the customer that we are searching for recipes.
// Handler for SuggestRecipe Intent which uses Multi-value slots to populate slot values.
const SuggestRecipeIntentHandler = {
canHandle(handlerInput) {
return (
Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' &&
Alexa.getIntentName(handlerInput.requestEnvelope) === 'SuggestRecipeIntent'
);
},
handle(handlerInput) {
const ingredientResponse = getReadableSlotValue(handlerInput, 'ingredients');
const speakOutput = `Searching for recipes with ${ingredientResponse}`;
return handlerInput.responseBuilder.speak(speakOutput).getResponse();
},
};
And that’s it, your skill can now capture multiple slot values and enable natural conversations with your customers. You can also refer to our cookbook for sample code on implementing Multi-Value Slots in your skill. As you leverage the power of Multi-Value Slots to create more engaging experiences, it’s important to understand how it works in different scenarios so you can design the right experience for your skill. Here are a few tips to enable you to use them even better.
let listControl = new MultiValueListControl({
id: 'myShoppingList',
validation: function(vals) { // validation function
...
},
listItemIDs:['Pepperoni', 'Cheese', 'Sausage', 'Olives'], // slotIDs of the slotType to suggest/present
slotType: 'PizzaToppings', //
confirmationRequired: () => true,
prompts: {
confirmValue: () => 'Is that all?',
},
});
rootControl.addChild(mvsControl);
One benefit of using MultiValueListControl is that it can also help validate input values from customers. Here’s how that conversation would look
Customer: Add pepperoni and cheese to my pizza.
Alexa: OK, added pepperoni and cheese, is that all?
Customer: Can you add anchovies as well?
Alexa: Sorry, we don’t have anchovies as a topping. Please choose a value from pepperoni, cheese, sausage, or olives.
Customer: Olives.
Alexa: OK, added olives. Is that all?
You can learn more about MultiValueListControl here
By implementing Multi-Value Slots and following these best practices, you will be able to design voice experiences where your customers can have natural conversations. You can learn more about Multi-Value Slots in our technical documentation and the overview video.