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

To help you get started, we’ve selected a few ask-sdk-core 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 javichur / alexa-skill-clean-code-template / lambda / custom / index.js View on Github external
LOC.t = require(`./strings/${lang}.js`); // eslint-disable-line import/no-dynamic-require
        LOC.langSkill = lang;
        return;
      } catch (e) {
        // console.log(`Error reading strings. lang: ${lang}`);
      }
    }

    // default lang
    LOC.langSkill = Settings.DEFAULT_LANGUAGE;
    LOC.t = require(`./strings/${LOC.langSkill}.js`); // eslint-disable-line import/no-dynamic-require
  },
};


const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
  .addRequestHandlers(
    LaunchRequestHandler,
    HelloWorldIntentHandler,
    HelpIntentHandler,
    CheckPermissionsIntentHandler,
    SaveSessionIntentHandler,
    LoadSessionIntentHandler,
    SaveDynamoDBIntentHandler,
    LoadDynamoDBIntentHandler,
    ColorIntentHandler,
    EventHandler, // taps en pantalla APL
    CancelAndStopIntentHandler,
    FallbackIntentHandler, // to Respond Gracefully to Unexpected Customer Requests
    GlobalHandlers.SessionEndedRequestHandler,
    UseApiRequestHandler, // API sample
github alexa / alexa-cookbook / feature-demos / skill-connections / provider-demo / lambda / custom / index.js View on Github external
const ErrorHandler = {
    canHandle(handlerInput, error) {
        // handle all type of exceptions
        return true;
    },
    handle(handlerInput, error) {
        console.log("==== ERROR ======");
        console.log(`Error handled: ${error}`);

        return handlerInput.responseBuilder
            .speak('Sorry, error occurred')
            .getResponse();
    },
};

exports.handler = Alexa.SkillBuilders
  .custom()
  .addRequestHandlers(
    PrintWebPageTaskHandler,
    LaunchRequestHandler,
    SessionEndedRequestHandler,
    HelpIntentHandler,
    CancelAndStopIntentHandler,
  )
  .addErrorHandlers(ErrorHandler)
  .withCustomUserAgent('cookbook/connections-provider/v1')
  .lambda();
github alexa / skill-sample-nodejs-hello-world / code / index.js View on Github external
},
    handle(handlerInput, error) {
        console.log(`~~~~ Error handled: ${error.stack}`);
        const speakOutput = `Sorry, I had trouble doing what you asked. Please try again.`;

        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();
    }
};

// The SkillBuilder acts as the entry point for your skill, routing all request and response
// payloads to the handlers above. Make sure any new handlers or interceptors you've
// defined are included below. The order matters - they're processed top to bottom.
exports.handler = Alexa.SkillBuilders.custom()
    .addRequestHandlers(
        LaunchRequestHandler,
        HelloWorldIntentHandler,
        HelpIntentHandler,
        CancelAndStopIntentHandler,
        SessionEndedRequestHandler,
        IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
        ) 
    .addErrorHandlers(
        ErrorHandler,
        )
    .lambda();
github alexa / alexa-cookbook / feature-demos / skill-demo-dynamic-location / lambda / custom / index.js View on Github external
function fixHeadingForLocale(heading, locale){
    //special replacement for es-*
    if(locale.startsWith('es')){
        heading = heading.replace('norteeste', 'noreste');
        heading = heading.replace('norteoeste', 'noroeste');
        heading = heading.replace('norte-noreste', 'nor-noreste');
        heading = heading.replace('norte-noroeste', 'nor-noroeste');
    }
    return heading;
}

// This handler acts as the entry point for your skill, routing all request and response
// payloads to the handlers above. Make sure any new handlers or interceptors you've
// defined are included below. The order matters - they're processed top to bottom.
exports.handler = Alexa.SkillBuilders.custom()
    .addRequestHandlers(
        LaunchRequestHandler,
        MyLocationIntentHandler,
        HelpIntentHandler,
        CancelAndStopIntentHandler,
        SessionEndedRequestHandler)
    .addErrorHandlers(
        ErrorHandler)
    .addRequestInterceptors(LocalisationRequestInterceptor)
    .withCustomUserAgent('cookbook/dynamic-location/v1')
    .lambda();
github KayLerch / moustask / example / skill-sample-nodejs-fact / _dist / mars_facts / lambda / custom / index.js View on Github external
postProcess: 'sprintf',
        sprintf: values,
      });
      if (Array.isArray(value)) {
        return value[Math.floor(Math.random() * value.length)];
      }
      return value;
    };
    const attributes = handlerInput.attributesManager.getRequestAttributes();
    attributes.t = function translate(...args) {
      return localizationClient.localize(...args);
    };
  },
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
  .addRequestHandlers(
    GetNewFactHandler,
    HelpHandler,
    ExitHandler,
    FallbackHandler,
    SessionEndedRequestHandler,
  )
  .addRequestInterceptors(LocalizationInterceptor)
  .addErrorHandlers(ErrorHandler)
  .lambda();

// translations
const deData = {
  translation: {
github Xzya / alexa-typescript-starter / lambda / custom / index.ts View on Github external
import * as Alexa from "ask-sdk-core";
import * as Intents from "./intents";
import * as Errors from "./errors";
import * as Interceptors from "./interceptors";
import * as HelloIntents from "./intents/hello";

export const handler = Alexa.SkillBuilders.custom()
    .addRequestHandlers(
        // Intents.Debug,

        // Default intents
        Intents.Launch,
        Intents.Help,
        Intents.Stop,
        Intents.SessionEnded,
        Intents.SystemExceptionEncountered,
        Intents.Fallback,

        // Hello intents
        HelloIntents.HelloWorld
    )
    .addErrorHandlers(
        Errors.Unknown,
github javichur / alexa-skill-clean-code-template / lambda / custom / index.js View on Github external
GlobalHandlers.SessionEndedRequestHandler,
    UseApiRequestHandler, // API sample

    PurchaseHandlers.WhatCanIBuyIntentHandler, // purchase handlers
    PurchaseHandlers.TellMeMoreAboutProductIntentHandler,
    PurchaseHandlers.BuyIntentHandler,
    PurchaseHandlers.BuyResponseHandler,
    PurchaseHandlers.PurchaseHistoryIntentHandler,
    PurchaseHandlers.RefundProductIntentHandler,
    PurchaseHandlers.CancelProductResponseHandler,

    GlobalHandlers.IntentReflectorHandler, // last
  )
  .addRequestInterceptors(myLocalizationInterceptor, initPurchaseHandlers) // lang & purchase
  .addErrorHandlers(GlobalHandlers.ErrorHandler)
  .withApiClient(new Alexa.DefaultApiClient()) // API to get user permissions and in-skill purchases
  .lambda();
github internetarchive / internet-archive-voice-apps / functions / src / platform / alexa / response / index.js View on Github external
media.forEach(m => {
        const previousToken = m.previousTrack ? m.previousTrack.contentURL : null;
        debug('previous token', previousToken);
        if (mediaResponseOnly) {
          // https://developer.amazon.com/docs/custom-skills/audioplayer-interface-reference.html#playbacknearlyfinished
          debug('card is not allowed');
        } else {
          debug('render card', m.name, m.description);
          if (m.imageURL) {
            handlerInput.responseBuilder.withStandardCard(m.name, m.description, m.imageURL);
          } else {
            handlerInput.responseBuilder.withSimpleCard(m.name, m.description);
          }
        }

        const art = new Alexa.ImageHelper()
          .withDescription(m.name)
          .addImageInstance(m.imageURL)
          .getImage();

        // TODO: we could find better image for background
        const backgroundImage = art;

        debug('playback audio', m.contentURL);
        handlerInput.responseBuilder.addAudioPlayerPlayDirective(
          // behavior,
          previousToken ? 'ENQUEUE' : 'REPLACE_ALL',
          m.contentURL,
          // token (This token cannot exceed 1024 characters)
          m.contentURL,
          // offsetInMilliseconds
          m.offset,
github nitzzzu / alexa-local-skills / skills / subsonic / index.js View on Github external
return handlerInput.responseBuilder.getResponse();
    }
};

const ErrorHandler = {
    canHandle() {
        return true;
    },
    handle(handlerInput, error) {
        console.log(`Error handled: ${error.message}`);

        return handlerInput.responseBuilder.speak("Sorry, I can't understand the command. Please say again.").getResponse();
    }
};

module.exports = Alexa.SkillBuilders.custom()
    .addRequestHandlers(
        LaunchRequestHandler,
        SearchIntentHandler,
        HelpIntentHandler,
        AudioPlayerHandler,
        PauseIntentHandler,
        ResumeIntentHandler,
        RepeatIntentHandler,
        LoopOnIntentHandler,
        LoopOffIntentHandler,
        StopIntentHandler,
        SessionEndedRequestHandler
    )
    .addErrorHandlers(ErrorHandler)
    .withSkillId(config.SUBSONIC_SKILL_ID)
    .create();
github JargonInc / jargon-sdk-nodejs / packages / alexa-skill-sdk / tst / responseBuilder / jrb.spec.ts View on Github external
it('does not merge reprompt content due to boolean parameter override', async () => {
  let jrb = new JRB(ResponseFactory.init(), resourceManager, mergeOptions)
  jrb.reprompt(ri('hello'), { playBehavior: 'REPLACE_ALL' })
  jrb.reprompt(ri('hello'), false)

  let response = await jrb.getResponse()
  let os = response.reprompt!.outputSpeech
  validateOutputSpeech(os, helloResult)
})