import * as Alexa from 'ask-sdk-core'; class AttributeUtil { private handlerInput: Alexa.HandlerInput; constructor(handlerInput: Alexa.HandlerInput) { this.handlerInput = handlerInput; } public async saveAttributes(): Promise { await this.handlerInput.attributesManager.savePersistentAttributes(); } public async setToken(token: string): Promise { return await this.handlerInput.attributesManager.getPersistentAttributes().then((attributes) => { attributes.token = token; return attributes; }).then((attributes) => { this.handlerInput.attributesManager.setPersistentAttributes(attributes); }).finally(() => { return this.saveAttributes(); }); } public async getToken(): Promise { return await this.handlerInput.attributesManager.getPersistentAttributes().then((attributes) => { return attributes.token; }); } }