We recently introduced the FallbackIntent, which is triggered when a customer speaks an utterance that doesn’t align with your interaction model. For more information about the FallbackIntent, check out our technical documentation. To help you get started quickly, here are three steps you can follow to add the intent to ensure your skill can respond gracefully to unexpected utterances.
The FallbackIntent is a built-in intent, so you don’t need to provide any sample utterances. To add the intent using the Alexa Developer Portal, follow these steps:
If you prefer to use the Alexa Skills Kit Command Line Interface (ASK CLI) or want to add the FallbackIntent directly to the JSON interaction model, copy this code into the interaction model under InteractionModel > LanguageModel > Intents:
{
"name": "AMAZON.FallbackIntent",
"samples": []
},
Note – since the AMAZON.FallbackIntent is only available in the en-US locale, do not add the FallbackIntent to any language models except for en-US. It is acceptable to have different models for different locales, even if the same AWS Lambda function is used to service all the requests.
In the JavaScript code provided to handle the FallbackIntent, we reference the name of the skill. To support this code, create a constant to store the skill name, if you don’t have one already for that.
const SKILL_NAME = 'Space Facts';
Next, add the message that Alexa will speak when the FallbackIntent is triggered, plus the reprompt message. We recommend referencing the name of the skill so that if a customer doesn’t realize that they are talking to the skill, they are reoriented before being provided a suggestion of what they could say next. Some suggested starting values are (note the backticks for FALLBACK_MESSAGE):
const FALLBACK_MESSAGE = `The ${SKILL_NAME} skill can't help you with that. It can help you discover facts about space if you say tell me a space fact. What can I help you with?`;
const FALLBACK_REPROMPT = 'What can I help you with?';
Update these messages to align with how your skill speaks and what your skill does, although you should retain a few aspects to the messaging. First, express that the skill can’t help with the utterance spoken. You won’t be provided with what your customer said, but rest assured that Alexa determined it does not match any of your existing intent models. Next, make a suggestion on how the skill can assist the customer. Finally, don’t forget to end with a question!
After the code has been prepared, add the following code to your skill:
const FallbackHandler = {
// 2018-May-01: AMAZON.FallackIntent is only currently available in en-US locale.
// This handler will not be triggered except in that locale, so it can be
// safely deployed for any locale.
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest'
&& request.intent.name === 'AMAZON.FallbackIntent';
},
handle(handlerInput) {
return handlerInput.responseBuilder
.speak(FALLBACK_MESSAGE)
.reprompt(FALLBACK_REPROMPT)
.getResponse();
},
};
This code identifies that it can handle the FallbackIntent, and then returns the appropriate message. You might also consider providing a dynamic fallback message similar to what you may currently do with your help message. The fallback message should not be identical to the help message, as the HelpIntent handler would be triggered if the customer asked for help. The FallbackIntent would be triggered by the customer asking for something other than help, so without a clear transition, the customer could get confused as to why a help response is being provided.
Once the code has been updated, scroll down to where the handlers are registered (hint: search for addRequestHandlers). Typically this is found at the very bottom of the code file. Once you’ve found where the handlers are being registered, add the FallbackHandler. We suggest you put it second from the bottom, right before the SessionEndedRequest handler.
Here’s an example of how to register the new handler:
.addRequestHandlers(
LaunchRequestHandler,
CancelStopHandler,
HelpHandler,
FallbackHandler,
SessionEndedHandler,
)
If you are still using version 1 of the ASK Software Development Kit (SDK) for Node.js, you can still add support for the FallbackIntent by add this to your handlers:
'AMAZON.FallbackIntent': function () {
this.response
.speak(FALLBACK_MESSAGE)
.listen(FALLBACK_REPROMPT);
this.emit(':responseReady');
},
Afterwards, reach out to us through the Alexa Developer Forums to let us know what’s holding you back from migrating to the new SDK.
Save your changes, and deploy your code to your test environment. Next, test your skill. While the exact tests you use will depend on your skill, a simple test (assuming your skill does not provide weather information) is:
Now that you have added the FallbackIntent and FallbackHandler to your skill, submit it for certification.
You should also periodically review the how customers are interacting with your skill, especially when the FallbackIntent is triggered. Visit the Intent History page for your skill to see aggregated, anonymized frequent utterances and the intents those utterances resolved to. You can find more information about Intent History here.
For more information, check out the following resources: