At end of active session of user I wants to remove all sessionAttributes using handlerInput.attributesManager
.
How to remove all sessions at end of AMAZOn.StopIntent
At end of active session of user I wants to remove all sessionAttributes using handlerInput.attributesManager
.
How to remove all sessions at end of AMAZOn.StopIntent
Alexa ends it's active session when there is no input from the user even after reprompt, or the response itself has a shouldEndSession
set to true
, or there is an error in the response. In all these cases the sessionAttributes
are all cleared. So you don't have to explicitly clear it.
The user has open the skill again to interact with the skill and that will be a new user session with no sessionAttributes
itself.
Now if you want to end the session which in turn clears the sessionAttributes you do:
In ask-nodejs-sdk v2, don't specify a reprompt, this will set shouldEndSession
set to true
automatically.
return handlerInput.responseBuilder
.speak("Bye")
.getResponse();
In ask-nodejs-sdk v1, use :tell
, this will set shouldEndSession
set to true
automatically.
this.emit(':tell', 'Bye');
Here I found the solution,
handlerInput.attributesManager.setSessionAttributes({})
return handlerInput.responseBuilder
.speak("Goody Bye")
.withSimpleCard('', "Goody Bye")
.withShouldEndSession(true)
.getResponse()