0

I'm new to Alexa skills so I may be taking the wrong approach here for dialog management, but I am trying to determine the user's response in the following manner using conditionals within YesIntent and NoIntent handlers. I am hosting and testing all within the Alexa Developer Console. Here is a basic happy path scenario where they already said yes, they are interested in the event and I am now asking if they want to be texted the info:

const YesIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
        && (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.YesIntent');
    },
    async handle(handlerInput) {
        const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
        const { askedUserIfTheyWantText, textUser } = sessionAttributes;
        let speakOutput;

        if (askedUserIfTheyWantText === undefined) { // I have yet to ask
            speakOutput = 'Alright, want me to text you the info?';
            sessionAttributes.askedUserIfTheyWantText = true;
            handlerInput.attributesManager.setSessionAttributes(sessionAttributes);
        } else if (askedUserIfTheyWantText) { // I already asked and they said yes
            // assume I already have number, so I will now text them
            const successfullyTextedUser = await textUserInfo();
            if (successfullyTextedUser) speakOutput = 'Texted you the info!';
            else speakOutput = 'There was a problem texting you the info.';
        }

        return handlerInput.responseBuilder
            .speak(speakOutput)
            .getResponse();
    }
}

The problem is that askedUserIfTheyWantText never updates to true (remains undefined) so Alexa keeps asking "Alright, want me to text you the info?". What am I doing wrong?? As I said, I'm testing (via text) in the Alexa Developer Console.

S Q
  • 129
  • 7

2 Answers2

2

Looks like your response is ending the session—therefore losing all sessionAttributes.

You need to add a .reprompt(speakOutput) call if you want the session left open, or configure your skill to work with DynamoDB and use persistentAttributes.

Timothy Aaron
  • 3,059
  • 19
  • 22
  • I tried for like 30 minutes to find documentation to explain this... to no avail. The best I could come up with was https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/blob/e62421c/ask-sdk-core/lib/response/ResponseBuilder.ts#L29 (through line 43). `speak` responds and closes the session, adding `reprompt` keeps the session open and after waiting 8 seconds follows up with the reprompt copy. – Timothy Aaron Apr 14 '20 at 02:31
1

I don't know if this would work but you could take the user's response in a slot value and then call that slot value instead of using session attributes.

MC HAMMER
  • 13
  • 1
  • 3