Code Monkey home page Code Monkey logo

alexa-nodekit's Introduction

alexa-nodekit

Amazon Echo Alexa's App Kit NodeJS Implementation

Build Status

Usage

// Require module.
var alexa = require('alexa-nodekit');

/**
 * Store values from Echo Request.
 *
 * @param {Object} req.body The request body object coming from the Echo.
 *
 * @return {undefined} No Response.
 */
alexa.launchRequest(req.body);
alexa.intentRequest(req.body);
alexa.sessionEndedRequest(req.body);

/**
 * Respond to the Echo requests. The Content-Length header must be included in each response.
 *
 * @param {String} speech The string that Alexa should state to the user. Up to 8000 characters and no more than 24 kb.
 * @param {Object} card The card object to generate for echo.amazon.com.
 * @param {String} card.title The card title.
 * @param {String} card.subtitle The card subtitle.
 * @param {String} card.content The card content.
 * @param {Boolean} endSession Wether this response should end the session or not.
 * @param {Function} callback The callback function.
 *
 * @return {Function} The callback function.
 */
// Launch or Intent Response.
alexa.response('Welcome to my app, you can say things like <action> or <action>.', {
  title: 'Launch Card Title',
  subtitle: 'Launch Card Subtitle',
  content: 'Launch Card Content'
}, false, function (error, response) {
  if(error) {
    return console.log(error);
  }
  console.log(response);
});

// Session Ended Response.
alexa.response(function (error, response) {
  if(error) {
    return console.log(error);
  }
  console.log(response);
});

Examples

Example of Launch Request/Response using ExpressJS.

var alexa = require('alexa-nodekit');

// Route request and response ends up here.
exports.route = function (req, res) {
   // Grab the necessary values from the Echo request.
   alexa.launchRequest(req.body);
   // Store the session and/or user data

   // Respond to the Echo
   alexa.response('Welcome to my app, you can say things like <action> or <action>.', {
     title: 'Launch Card Title',
     subtitle: 'Launch Card Subtitle',
     content: 'Launch Card Content'
   }, false, function (error, response) {
     if(error) {
       return res.status(400).jsonp({message: error});
     }
     return res.jsonp(response);
   });
};

Example of Intent Request/Response using ExpressJS.

var alexa = require('alexa-nodekit');

// Same route used as launch, request and response ends up here.
exports.route = function (req, res) {
   // Grab the necessary values from the Echo request.
   alexa.intentRequest(req.body);
   // Check session and/or user data
   // Check the Intent Name and Intent Slots to decide on what logic to kick off.

   // Respond to the Echo
   alexa.response('I am an Echo response based on your intent.', {
     title: 'Intent Card Title',
     subtitle: 'Intent Card Subtitle',
     content: 'Intent Card Content'
   }, true, function (error, response) {
     if(error) {
       return res.status(400).jsonp({message: error});
     }
     return res.jsonp(response);
   });
};

Example of Session Ended Request/Response using ExpressJS.

var alexa = require('alexa-nodekit');

// Same route used as launch and intent, request and response ends up here.
exports.route = function (req, res) {
   // Grab the necessary values from the Echo request.
   alexa.sessionEndedRequest(req.body);
   // Check session and delete it.

   // Respond to the Echo
   alexa.response(function (error, response) {
     if(error) {
       return res.status(400).jsonp({message: error});
     }
     return res.jsonp(response);
   });
};

Testing

$ npm test

Contributions

  • Fork it (https://github.com/YOUR_USERNAME/alexa-nodekit/fork).
  • Create your feature branch (git checkout -b my-new-feature).
  • Commit your changes (git commit -am 'Added some feature.').
  • Push to the branch (git push origin my-new-feature).
  • Create a new pull request.

License

alexa-nodekit's People

Contributors

sparkyfen avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.