Created
April 26, 2020 09:39
-
-
Save kinisoftware/0d9ab28a792beea7162c0bf232a4ee0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as alexa from 'ask-sdk-core'; | |
| import {HandlerInput} from 'ask-sdk-core'; | |
| import {Response} from 'ask-sdk-model'; | |
| import {SessionAttributes} from '../model/sessionAttributes'; | |
| export const saveAttributesResponseInterceptor = { | |
| async process(handlerInput: HandlerInput, response: Response) { | |
| if (!response) return; // avoid intercepting calls that have no outgoing response due to errors | |
| const {attributesManager, requestEnvelope} = handlerInput; | |
| const sessionAttributes: SessionAttributes = attributesManager.getSessionAttributes(); | |
| const shouldEndSession = | |
| typeof response.shouldEndSession === 'undefined' ? true : response.shouldEndSession; //is this a session end? | |
| if (shouldEndSession || alexa.getRequestType(requestEnvelope) === 'SessionEndedRequest') { | |
| // skill was stopped or timed out | |
| console.log('Saving to persistent storage:' + JSON.stringify(sessionAttributes.tvShows)); | |
| attributesManager.setPersistentAttributes({tvShows: sessionAttributes.tvShows}); | |
| await attributesManager.savePersistentAttributes(); | |
| } | |
| }, | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment