How to use ask-sdk - 10 common examples

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 alexa / alexa-cookbook / feature-demos / skill-demo-list-events / lambda / custom / index.js View on Github external
handle(handlerInput, error) {
    const request = handlerInput.requestEnvelope.request;

    console.log(`Original Request was: ${JSON.stringify(request, null, 2)}`);
    console.log(`Error handled: ${error}`);

    return handlerInput.responseBuilder
      .speak('Sorry, I had trouble doing what you asked.  Please ask for it again.')
      .reprompt('Sorry, I had trouble doing what you asked.  Please ask for it again.')
      .getResponse();
  },
};

// exports

const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
  .addRequestHandlers(
    AmazonCancelStopHandler,
    AmazonHelpHandler,
    LaunchRequestHandler,
    SkillEventHandler,
    ItemEventHandler,
    ListEventHandler,
    SessionEndedHandler,
    UnhandledHandler,
  )
  .addErrorHandlers(ErrorHandler)
  .withApiClient(new Alexa.DefaultApiClient())
  .withCustomUserAgent('cookbook/list-events/v1')
  .lambda();
github alexa / alexa-cookbook / feature-demos / skill-demo-list-access / lambda / custom / index.js View on Github external
return (listIsEmpty);
  }

  // get first item
  const item = list.items[0];
  const updateRequest = {
    value: item.value,
    status: listStatuses.COMPLETED,
    version: item.version,
  };
  return listClient.updateListItem(listId, item.id, updateRequest);
}

// exports

const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
  .addRequestHandlers(
    AmazonCancelStopHandler,
    AmazonHelpHandler,
    LaunchRequestHandler,
    CompleteTopToDoHandler,
    TopToDoHandler,
    SessionEndedHandler,
  )
  .addErrorHandlers(ErrorHandler)
  .withApiClient(new Alexa.DefaultApiClient())
  .withCustomUserAgent('cookbook/list-access/v1')
  .lambda();
github internetarchive / internet-archive-voice-apps / functions / src / platform / alexa / handler / index.js View on Github external
module.exports = (actions) => {
  // TODO: we don't need it for session attributes
  // turn on once we will have persistent attributes
  const region = process.env.AWS_REGION || 'us-west-1';
  debug('set AWS region', region);

  const dynamoDbPersistenceAdapter = new DynamoDbPersistenceAdapter({
    createTable: true,
    dynamoDBClient: new AWS.DynamoDB({ apiVersion: 'latest', region }),
    tableName: process.env.DYNAMO_DB_SESSION_TABLE || 'InternetArchiveSessions',
  });

  const handlers = handlersBuilder(actions);
  debug(`We can handle intents: ${handlers.map(({ intent }) => `"${intent}"`).join(', ')}`);

  let lambda = Alexa.SkillBuilders.custom()
    .addRequestHandlers(...handlers)
    .addErrorHandlers(ErrorHandler)
    .addRequestInterceptors(
      () => pipeline.stage(pipeline.PROCESS_REQUEST)
    )
    .addRequestInterceptors(LogInterceptor)
    .addResponseInterceptors(
      () => pipeline.stage(pipeline.IDLE)
    )
    .withPersistenceAdapter(dynamoDbPersistenceAdapter)
    .lambda();

  // wrap all log services

  if (process.env.DASHBOT_KEY) {
    // for the moment doesn't work
github alexa / alexa-cookbook / feature-demos / skill-demo-progressive-response / lambda / custom / index.js View on Github external
for (let i = startIndex; i < Math.min(events.length, startIndex + PAGINATION_SIZE); i += 1) {
    speechOutputContent += `<p>${events[i]}</p>`;
    cardOutputContent += `${events[i]}\n`;
  }
  return {
    speechOutputContent,
    cardOutputContent,
  };
}

function sleep(milliseconds) {
  return new Promise(resolve =&gt; setTimeout(resolve, milliseconds));
}

// 4. Exports handler function and setup ===================================================
const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
  .addRequestHandlers(
    LaunchRequestHandler,
    AmazonCancelStopNoHandler,
    AmazonHelpHandler,
    InProgressGetFirstEventHandler,
    GetFirstEventHandler,
    AmazonYesHandler,
    SessionEndedHandler,
  )
  .addErrorHandlers(ErrorHandler)
  .withApiClient(new Alexa.DefaultApiClient())
  .withCustomUserAgent('cookbook/progressive-response/v1')
  .lambda();
github alexa / alexa-cookbook / feature-demos / skill-demo-list-events / lambda / custom / index.js View on Github external
// exports

const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
  .addRequestHandlers(
    AmazonCancelStopHandler,
    AmazonHelpHandler,
    LaunchRequestHandler,
    SkillEventHandler,
    ItemEventHandler,
    ListEventHandler,
    SessionEndedHandler,
    UnhandledHandler,
  )
  .addErrorHandlers(ErrorHandler)
  .withApiClient(new Alexa.DefaultApiClient())
  .withCustomUserAgent('cookbook/list-events/v1')
  .lambda();
github alexa / alexa-cookbook / feature-demos / skill-demo-progressive-response / lambda / custom / index.js View on Github external
}

// 4. Exports handler function and setup ===================================================
const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
  .addRequestHandlers(
    LaunchRequestHandler,
    AmazonCancelStopNoHandler,
    AmazonHelpHandler,
    InProgressGetFirstEventHandler,
    GetFirstEventHandler,
    AmazonYesHandler,
    SessionEndedHandler,
  )
  .addErrorHandlers(ErrorHandler)
  .withApiClient(new Alexa.DefaultApiClient())
  .withCustomUserAgent('cookbook/progressive-response/v1')
  .lambda();
github alexa / alexa-cookbook / feature-demos / skill-demo-list-access / lambda / custom / index.js View on Github external
}

// exports

const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
  .addRequestHandlers(
    AmazonCancelStopHandler,
    AmazonHelpHandler,
    LaunchRequestHandler,
    CompleteTopToDoHandler,
    TopToDoHandler,
    SessionEndedHandler,
  )
  .addErrorHandlers(ErrorHandler)
  .withApiClient(new Alexa.DefaultApiClient())
  .withCustomUserAgent('cookbook/list-access/v1')
  .lambda();
github taimos / ask-sdk-test / examples / skill-sample-nodejs-dynamodb / helloworld.ts View on Github external
&amp;&amp; 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 taimos / ask-sdk-test / examples / skill-sample-nodejs-profileapi / helloworld.ts View on Github external
const mobile = await upsServiceClient.getProfileMobileNumber();

            const speechText = `Hello, ${givenName} ${name}. Your e-mail is ${email} and your phone number is ${mobile}`;
            return handlerInput.responseBuilder.speak(speechText).getResponse();
        } catch (e) {
            return handlerInput.responseBuilder.speak('Hello, world! I am not allowed to view your profile.').getResponse();
        }
    }

}

export const handler : LambdaHandler = SkillBuilders.custom()
    .addRequestHandlers(
        new LaunchRequestHandler(),
    )
    .withApiClient(new DefaultApiClient())
    .lambda();
github taimos / ask-sdk-test / examples / skill-sample-nodejs / helloworld.ts View on Github external
public handle(handlerInput : HandlerInput) : Response {
        const speechText = 'Hello World!';

        const attributes = handlerInput.attributesManager.getSessionAttributes();
        attributes.foo = 'bar';
        attributes.count = 1;
        handlerInput.attributesManager.setSessionAttributes(attributes);

        return handlerInput.responseBuilder
            .speak(speechText)
            .withSimpleCard('Hello World', speechText)
            .getResponse();
    }
}

export const handler : LambdaHandler = SkillBuilders.custom()
    .addRequestHandlers(
        new LaunchRequestHandler(),
        new HelloWorldIntentHandler(),
    )
    .lambda();

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