save/remember an Alexa user's intent confirmation response?

Issue

I have a confirmation prompt for one of my Alexa skill’s intents, and now I need it to "remember" the user’s answer and not ask the user again. Essencially, we want the user to be prompted only on the very first time they use the skill, and then never again. Is that possible?

I’m hoping I don’t have to do a total code re-write, and can just update my existing code. Here is my intent’s javascript code (simplified) for the lambda function for the skill:

    'myIntent': function() {
    
    // there is a required prompt setup in the language interaction model (in the Alexa Skill Kit platform) 
    // To use it we "deligate" it to Alexa via the delegate dialoge directive.
    
    if (this.event.request.dialogState === 'STARTED') {
        // Pre-fill slots: update the intent object with slot values for which
        // you have defaults, then emit :delegate with this updated intent.
        this.emit(':delegate');
    } else if (this.event.request.dialogState !== 'COMPLETED'){
        this.emit(':delegate');
    } else {
        // completed
        var intentObj = this.event.request.intent;
        if (intentObj.confirmationStatus !== 'CONFIRMED') {
            // not confirmed
            if (intentObj.confirmationStatus !== 'DENIED') {
                // Intent is completed, not confirmed but not denied
                this.emit(':tell', "You have neither confirmed or denied. Please try again.");
            } else {
                // Intent is completed, denied and not confirmed
                this.emit(':ask', 'I am sorry but you cannot continue.');
            }
        } else {
            // intent is completed and confirmed. Success!
            var words = "You have confirmed, thank you!";
            this.response.speak(words);
            this.emit(':responseReady');
        }
    }
},

Thanks for any help!

Solution

You can persist/save/remember alexa user’s data using persistent attributes.

I recommend you to follow alexa skill sample tutorial zero to hero it summarise everything you need to know about developing a skill on Alexa with examples & videos.

And what you need from this tutorial is the Part 4 – Persistence

And then, it will be as easy as:

attributesManager.setPersistentAttributes(sessionAttributes);
await attributesManager.savePersistentAttributes();

Answered By – callmemath

Answer Checked By – Cary Denson (AngularFixing Admin)

Leave a Reply

Your email address will not be published.