kidshift-skills/src/AttributeUtils.ts

33 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-07-16 23:56:22 +00:00
import * as Alexa from 'ask-sdk-core';
2024-07-16 23:56:59 +00:00
class AttributeUtils {
2024-07-16 23:56:22 +00:00
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;
});
}
}
2024-07-16 23:56:59 +00:00
export default AttributeUtils;