Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

alexa-utils

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alexa-utils

A simple library for making the development of Alexa skills easier.

Source
npmnpm
Version
0.0.5
Version published
Weekly downloads
5
-82.14%
Maintainers
1
Weekly downloads
 
Created
Source

alexa-utils

A simple library for making the development of Alexa (Amazon Echo) apps (Skills) easier with Node.js.

Disclaimer

This library is very minimalistic as far as what features it supports. For example, this library will NOT handle cards, reprompts, session infomation, or account linking. Also, it doesn't support async functions at the moment, although it may be implemented in a later version. If you have any suggestions or bug fixes, please contact me or make a pull request.

Installation

npm install alexa-utils --save

Features

  • Simplified handling of requests and generating responses
  • Automatic generation of express objects for handling interactions between the user and the Echo device
  • Request verification (via the 'alexa-verifier' module)
  • Simplified handling of session data
  • Apps can be tested without running a server

Code Example

This code will automatically create an express object pre-initialized with a specified route, enabled verification, and sample code to handle the three most common intents.

var alexaUtils = require('alexa-utils');
const PORT = 3000;

var app = alexaUtils.createServer('/alexa', false,
	function(res, input) {
		switch (input.type) {
			case 'LaunchRequest':
				alexaUtils.sendResponse(res, "Hello there!");
				break;
			case 'SessionEndedRequest':
				alexaUtils.sendResponse(res, "Goodbye!");
				break;
			case 'IntentRequest':
				alexaUtils.sendResponse(res, "I see that your favorite color is " + input.slots.color);
				break;
		}
	}
);

app.listen(PORT, function() {
  console.log('Alexa server listening on port ' + PORT);
});

API Reference

Dictionary:

  • ExpressObject - an object created via express()
  • RequestObject - an object created as part of the function(request, response); used for parsing data from a web client
  • ResponseObject - an object created as part of the function(request, response); used for sending data to a web client

prepareExpress(ExpressObject express, boolean debug = true)

Given the express object, it will add middleware for handling JSON and URL-Encoded requests. If debug is set to false, the express object will also be able to authenticate the said requests by checking if they come from the Amazon servers only. Note that this is REQUIRED if you are submitting your Alexa Skill app for publification.

bindRoute(ExpressObject express, String route, function callback(ResponseObject response, JsonObject requestInfo))

Given the express object, it will bind all Amazon Alexa requests to the specified route, and all requests will be piped to the specified function, which has a ResponseObject (necessary for sending back a response to the Alexa device), and a simplified JSON Object. Refer to the parseRequest function for information about the JSON Schema.

createServer(String route, boolean debug, function callback(ResponseObject response, JsonObject requestInfo))

Essentially combines the prepareExpress and bindRoute, and returns a new ExpressObject all at once.

parseRequest(RequestObject request)

Constructs and returns a simplified JSON Object with the following JSON Schema:

{
	"$schema": "http://json-schema.org/draft-04/schema#",
	"type": "object",
	"properties": {
		"type": {
			"type": "string"
		},
		"name": {
			"type": "string"
		},
		"slots": {
			"type": "object",
			"properties": {
				"slot1": {
					"type": "any"
				},
				"slot2": {
					"type": "any"
				},
				"slot3": {
					"type": "any"
				}
			}
		}
	}
}

Note that you can have as many slots as you need for your Alexa Skill app.

sendResponse(ResponseObject res, String text, boolean shouldEnd = true)

Sends a response to the Echo device with the specified text to say. The shouldEnd variable specifies if the session between the user and the Echo device should end after sending that response.

Keywords

alexa-skill

FAQs

Package last updated on 28 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts