diff --git a/src/index.ts b/src/index.ts index 5393d33..9a76cba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,8 +21,21 @@ const HelloWorldIntentHandler = { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName(handlerInput.requestEnvelope) === 'HelloWorldIntent'; }, - handle(handlerInput: Alexa.HandlerInput) { - const speakOutput = 'Hello World!'; + async handle(handlerInput: Alexa.HandlerInput) { + + const attributesManager = handlerInput.attributesManager; + + const attributes = await attributesManager.getPersistentAttributes(); + + if (attributes.counter === undefined) { + attributes.counter = 0; + } else { + attributes.counter += 1; + } + + attributesManager.setPersistentAttributes(attributes); + + const speakOutput = 'Hello World! You have invoked this skill ' + attributes.counter + ' times.'; return handlerInput.responseBuilder .speak(speakOutput)