How to use ask-sdk-runtime - 10 common examples

To help you get started, we’ve selected a few ask-sdk-runtime 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 alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-core / lib / attributes / AttributesManagerFactory.ts View on Github external
public static init(options : {
        requestEnvelope : RequestEnvelope,
        persistenceAdapter? : PersistenceAdapter,
    }) : AttributesManager {
        if (!options.requestEnvelope) {
            throw createAskSdkError(
                'AttributesManagerFactory',
                'RequestEnvelope cannot be null or undefined!',
            );
        }

        let thisRequestAttributes : {[key : string] : any} = {};
        let thisSessionAttributes : {[key : string] : any} = options.requestEnvelope.session
                                                           ? options.requestEnvelope.session.attributes
                                                             ? JSON.parse(JSON.stringify(options.requestEnvelope.session.attributes))
                                                             : {}
                                                           : undefined;
        let thisPersistentAttributes : {[key : string] : any};
        let persistentAttributesSet = false;

        return {
            getRequestAttributes() : {[key : string] : any} {
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-core / lib / skill / CustomSkill.ts View on Github external
public async invoke(requestEnvelope : RequestEnvelope, context? : any) : Promise {
        if (this.skillId != null && requestEnvelope.context.System.application.applicationId !== this.skillId) {
            throw createAskSdkError(
                this.constructor.name,
                'CustomSkill ID verification failed!',
            );
        }

        const input : HandlerInput = {
            requestEnvelope,
            context,
            attributesManager : AttributesManagerFactory.init({
                requestEnvelope,
                persistenceAdapter : this.persistenceAdapter,
            }),
            responseBuilder : ResponseFactory.init(),
            serviceClientFactory : this.apiClient
                ? new ServiceClientFactory({
                    apiClient : this.apiClient,
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-core / lib / attributes / AttributesManagerFactory.ts View on Github external
async deletePersistentAttributes() : Promise {
                if (!options.persistenceAdapter) {
                    throw createAskSdkError(
                        'AttributesManager',
                        'Cannot delete PersistentAttributes without persistence adapter!');
                }

                await options.persistenceAdapter.deleteAttributes(options.requestEnvelope);

                thisPersistentAttributes = undefined;
                persistentAttributesSet = false;
            },
        };
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-core / lib / attributes / AttributesManagerFactory.ts View on Github external
async savePersistentAttributes() : Promise {
                if (!options.persistenceAdapter) {
                    throw createAskSdkError(
                        'AttributesManager',
                        'Cannot save PersistentAttributes without persistence adapter!');
                }

                if (persistentAttributesSet) {
                    await options.persistenceAdapter.saveAttributes(options.requestEnvelope, thisPersistentAttributes);
                }
            },
            async deletePersistentAttributes() : Promise {
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-core / lib / util / RequestEnvelopeUtils.ts View on Github external
export function getDialogState(requestEnvelope : RequestEnvelope) : string {
    if (getRequestType(requestEnvelope) === 'IntentRequest') {
        return (requestEnvelope.request as IntentRequest).dialogState;
    }

    throw createAskSdkError(
        'RequestEnvelopeUtils',
        `Expecting request type of IntentRequest but got ${getRequestType(requestEnvelope)}.`);
}
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-core / lib / util / RequestEnvelopeUtils.ts View on Github external
export function getSlot(requestEnvelope : RequestEnvelope, slotName : string) : Slot {
    if (getRequestType(requestEnvelope) === 'IntentRequest') {
        const slots : {[key : string] : Slot} = (requestEnvelope.request as IntentRequest).intent.slots;
        if (slots != null) {
            return slots[slotName];
        }

        return null;
    }

    throw createAskSdkError(
        'RequestEnvelopeUtils',
        `Expecting request type of IntentRequest but got ${getRequestType(requestEnvelope)}.`);

}
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-core / lib / attributes / AttributesManagerFactory.ts View on Github external
setPersistentAttributes(persistentAttributes : {[key : string] : any}) : void {
                if (!options.persistenceAdapter) {
                    throw createAskSdkError(
                        'AttributesManager',
                        'Cannot set PersistentAttributes without persistence adapter!');
                }

                thisPersistentAttributes = persistentAttributes;
                persistentAttributesSet = true;
            },
            async savePersistentAttributes() : Promise {
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-core / lib / util / ViewportUtils.ts View on Github external
export function getViewportDpiGroup(dpi : number) : ViewportDpiGroup {
    if (isBetween(dpi, 0, 121)) {
        return 'XLOW';
    } else if (isBetween(dpi, 121, 161)) {
        return 'LOW';
    } else if (isBetween(dpi, 161, 241)) {
        return 'MEDIUM';
    } else if (isBetween(dpi, 241, 321)) {
        return 'HIGH';
    } else if (isBetween(dpi, 321, 481)) {
        return 'XHIGH';
    } else if (isBetween(dpi, 481, Number.MAX_VALUE)) {
        return 'XXHIGH';
    }

    throw createAskSdkError('ViewportUtils', `unknown dpi group value ${dpi}`);
}
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-core / lib / attributes / AttributesManagerFactory.ts View on Github external
getSessionAttributes() : T {
                if (!options.requestEnvelope.session) {
                    throw createAskSdkError(
                        'AttributesManager',
                        'Cannot get SessionAttributes from out of session request!');
                }

                return thisSessionAttributes as T;
            },
            async getPersistentAttributes(useSessionCache : boolean = true) : Promise<{[key : string] : any}> {
github alexa / alexa-skills-kit-sdk-for-nodejs / ask-sdk-core / lib / util / RequestEnvelopeUtils.ts View on Github external
export function isNewSession(requestEnvelope : RequestEnvelope) : boolean {
    const session : Session = requestEnvelope.session;
    if (session) {
        return session.new;
    }

    throw createAskSdkError(
        'RequestEnvelopeUtils',
        `The provided request doesn't contain a session.`);
}

ask-sdk-runtime

Base runtime package for Alexa Skills Kit SDK

Apache-2.0
Latest version published 2 years ago

Package Health Score

61 / 100
Full package analysis