Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class SayGoodbyeHandler implements RequestHandler {
public canHandle(handlerInput : HandlerInput) : boolean {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'SayGoodbye';
}
public async handle(handlerInput : HandlerInput) : Promise {
const attributes = await handlerInput.attributesManager.getPersistentAttributes();
return handlerInput.responseBuilder.speak(`Bye ${attributes.foo}!`).getResponse();
}
}
export const handler : LambdaHandler = SkillBuilders.custom()
.withPersistenceAdapter(new DynamoDbPersistenceAdapter({
tableName: 'TestTable',
partitionKeyName: 'userId',
attributesName: 'mapAttr',
}))
.withApiClient(new DefaultApiClient())
.addRequestHandlers(
new SayHelloHandler(),
new SayGoodbyeHandler(),
)
.lambda();
':saveState'(forceSave : boolean) : void {
if (this.isOverridden()) {
return;
}
if (forceSave && this.handler.state) {
this.attributes.STATE = this.handler.state;
}
const response = this.handler.response.response;
if (response.shouldEndSession || forceSave || this.handler.saveBeforeResponse) {
if (!dynamoDbPersistenceAdapter) {
dynamoDbPersistenceAdapter = new DynamoDbPersistenceAdapter({
createTable : true,
dynamoDBClient : this.handler.dynamoDBClient,
partitionKeyName : 'userId',
attributesName : 'mapAttr',
tableName : this.handler.dynamoDBTableName,
});
}
dynamoDbPersistenceAdapter.saveAttributes(this.event, this.attributes).then(() => {
this.handler.promiseResolve(response);
}).catch((error) => {
if (error) {
return this.emit(':saveStateError', error);
}
});
} else {
console.log('Warning: Application ID is not set');
}
try {
if (this.appId && (requestAppId !== this.appId)) {
console.log(`The applicationIds don\'t match: ${requestAppId} and ${this.appId}`);
const error = createAskSdkError('In validating request', 'Invalid ApplicationId: ' + this.appId);
if (typeof this.callback === 'undefined') {
this._context.fail(error);
} else {
this._callback(error);
}
}
if (this.dynamoDBTableName && (!this._event.session.sessionId || this._event.session.new)) {
if (!dynamoDbPersistenceAdapter) {
dynamoDbPersistenceAdapter = new DynamoDbPersistenceAdapter({
createTable : true,
dynamoDBClient : this.dynamoDBClient,
partitionKeyName : 'userId',
attributesName : 'mapAttr',
tableName : this.dynamoDBTableName,
});
}
dynamoDbPersistenceAdapter.getAttributes(this._event)
.then((data) => {
Object.assign(this._event.session.attributes, data);
EmitEvent.call(this);
})
.catch((error) => {
const err = createAskSdkError(this.constructor.name, 'Error fetching user state: ' + error);
if (typeof this._callback === 'undefined') {