In one of my intents X, I need to collect some additional information before the intent can proceed. I'd like to "freeze" the intent X, forward the user to a different dialog intent Y, and then resume X.
My thought was to store the original intent X in a session attribute, call Y's handle function, and then return to the intent stored in the attribute. But how do I return to it?
In the NodeJS SDK, there's no public function that will dispatch an intent object to the right handler. It looks like this is handled internally by a GenericRequestDispatcher object, but this isn't public.
I was able to sort of make this work by calling skill.invoke() a second time, and fiddling around with the response. But this seems like a terrible hack:
handlerInput.requestEnvelope.request.intent = frozenIntentFromSession; // in case the current intent updated the attributes, pass them to the new one const sessionAttributes = handlerInput.attributesManager.getSessionAttributes(); handlerInput.requestEnvelope.session.attributes = sessionAttributes; const response = await skill.invoke(handlerInput.requestEnvelope); // in case the frozen intent updates the attributes, return them in the new response handlerInput.attributesManager.setSessionAttributes(response.sessionAttributes); // just return the "response" field, which will get re-wrapped in a response object by the original call to skill.invoke() return response.response;
Plus I'm not sure it would work if you're returning to a dialog intent that needs to elicit slots, since Alexa will still think it's in the previous intent.
I've read this, but it only works when the user specifically invokes X again.
This used to be possible with the NodeJS SDK 1.x, by "emitting" the desired intent. But with 2.x it no longer seems obvious how to do it.