I am creating a custom skill for Alexa. I want to close the session on AMAZON.StopIntent
. How can I achieve this with below code?
const ExitHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest'
&& (request.intent.name === 'AMAZON.StopIntent');
},
handle(handlerInput) {
return handlerInput.responseBuilder
.speak('bye!')
.reprompt('bye!')
.getResponse();
},
};
Ask Alexa to quit the skill.Say "Alexa, cancel," or "Alexa, quit," to exit the current Alexa skill.
To publish a skill that is in a Certified status, navigate to Certification > Submission. When publishing your skill, you have the following options: Publish now. Start the process now of publishing the skill to the Alexa Skills Store.
To disable your skill, go to the Alexa app and select Skills then choose Your Skills. Select the skill and choose Disable skill. If you wish to delete your skill, go to the Skills You've Made page, select the skill and choose Delete.
A skill session begins when a user invokes your skill and Alexa sends your skill a request. The request contains a session object that uses a Boolean value called new to indicate that this is a new session. Your skill receives the request and returns a response for Alexa to speak to the user.
Alexa ends the session when shouldEndSession flag is set to true in the response JSON.
...
"shouldEndSession": true
...
In your response builder can you try with the helper function withShouldEndSession(true)
return handlerInput.responseBuilder
.speak('bye!')
.withShouldEndSession(true)
.getResponse();
Response builder helper functions are listed here
In your code snippet you would end the session just by removing the reprompt line:
return handlerInput.responseBuilder
.speak('bye!')
.getResponse();
so the suggested solution below works but it's redundant:
return handlerInput.responseBuilder
.speak('bye!')
.withShouldEndSession(true)
.getResponse();
The code above is often used in the opposite scenario, when you want to keep the session open without a reprompt:
return handlerInput.responseBuilder
.speak('bye!')
.withShouldEndSession(false)
.getResponse();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With