kidshift-skills/src/attributeUtil.ts

31 lines
996 B
TypeScript
Raw Normal View History

2024-07-16 23:56:22 +00:00
import * as Alexa from 'ask-sdk-core';
class AttributeUtil {
private handlerInput: Alexa.HandlerInput;
constructor(handlerInput: Alexa.HandlerInput) {
this.handlerInput = handlerInput;
}
public async saveAttributes(): Promise<void> {
await this.handlerInput.attributesManager.savePersistentAttributes();
}
public async setToken(token: string): Promise<void> {
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<string> {
return await this.handlerInput.attributesManager.getPersistentAttributes().then((attributes) => {
return attributes.token;
});
}
}