mirror of
https://github.com/r-ca/kidshift-skills.git
synced 2024-10-25 17:14:03 +00:00
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import * as Alexa from 'ask-sdk-core';
|
|
|
|
class AttributeUtils {
|
|
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;
|
|
});
|
|
}
|
|
}
|
|
|
|
export default AttributeUtils;
|