How to use the ask-sdk.DynamoDbPersistenceAdapter function in ask-sdk

To help you get started, we’ve selected a few ask-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taimos / ask-sdk-test / examples / skill-sample-nodejs-dynamodb / helloworld.ts View on Github external
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();
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-v1adapter / lib / responseHandlers.ts View on Github external
':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 {
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-v1adapter / lib / adapter.ts View on Github external
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') {

ask-sdk

Standard distribution package for Alexa Skills Kit SDK

Apache-2.0
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis