Skip to content

Instantly share code, notes, and snippets.

@kinisoftware
Created April 26, 2020 09:35
Show Gist options
  • Select an option

  • Save kinisoftware/99b58b1004c13e1348ee938cad56191d to your computer and use it in GitHub Desktop.

Select an option

Save kinisoftware/99b58b1004c13e1348ee938cad56191d to your computer and use it in GitHub Desktop.
import * as alexa from 'ask-sdk-core';
import {HandlerInput} from 'ask-sdk-core';
import {SessionAttributes} from '../model/sessionAttributes';
export const loadAttributesRequestInterceptor = {
async process(handlerInput: HandlerInput) {
const {attributesManager, requestEnvelope} = handlerInput;
if (alexa.isNewSession(requestEnvelope)) {
const persistentAttributes = await attributesManager.getPersistentAttributes();
let sessionAttributes: SessionAttributes;
if (!('tvShows' in persistentAttributes)) {
sessionAttributes = {
firstTime: true,
tvShows: [],
};
} else {
sessionAttributes = {
firstTime: false,
tvShows: persistentAttributes.tvShows,
};
}
console.log('Loading from persistent storage: ' + JSON.stringify(sessionAttributes));
attributesManager.setSessionAttributes(sessionAttributes);
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment