alexa-utils

This package is no longer supported and has been deprecated. To avoid malicious use, npm is hanging on to the package name.


License
ISC
Install
npm install alexa-utils@0.2.8

Documentation

NPM Stats

NPM DavidDM NPM Version

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, although more support will be added soon. For example, 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.

Additionally, ths library does not aim to compete with the official Alexa library for node, or the alexa-app library. Rather, it's simply my version of a library capable of interacting with the Amazon Echo.

Installation

npm install alexa-utils --save

Features

  • Simplified handling of requests and generating responses
  • Full support for Echo cards
  • Automatic generation of express objects for handling interactions between the user and the Echo device
  • Automatic request verification (via the alexa-verifier-middleware module)
  • Modular system of creating alexa skills
  • Easily host multiple skills without any conflict
  • Apps can be tested without running a server

Mentions

Code Example

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

var app = alexa.app("HelloWorld")
    .onLaunch(function(req, res) {
        res.prompt("Hello there!").send();
    })
    .onIntent("GetFavoriteColor", function(req, res) {
        res.prompt("I see that your favorite color is " + req.intent.slots("color")).send();
    })
    .onSessionEnd(function(req, res) {
        res.prompt("Goodbye!").send();
    })
    .host("/hello", PORT, false, false);

console.log("Server started on port " + PORT);

API Reference

Dictionary:

  • reqObj - an object created as part of the function(request, response); used for parsing data from a web client
  • resObj - an object created as part of the function(request, response); used for sending data to a web client
  • alexa - the object holding the reference to the alexa-utils library
  • optional - the argument doesn't need to be specified when calling the function

Request Object JSON Format

This format is used when alexa-utils receives the requests from the Echo and feeds it to your skill. Note that if the type has a function signature, that means that the field specified is a function with that signature.

{
    "intent": {
        "type": "string",
        "name": "string",
        "reason": "string",
        "slot": function(name)
    },
    "session": {
        "new": boolean,
        "id": "string",
        "appId": "string",
        "getAttribute": function(name),
        "user": {
            "id": "string",
            "accessToken": "string"
        }
    }
}

Methods in alexa.app

app(string name) [Constructor]

Creates an app object to process the intent requests

app.onLaunch(function action(reqObj, resObj))

Sets the action to occur when the user tries to use the skill but deosn't specify a specific action to do.

app.onIntent(string intentName, function action(reqObj, resObj))

Assigns the action to the particular intent specified.

app.onSessionEnd(function action(reqObj, resObj))

Sets the action to occur when the session with the user has ended.

app.host(string route, integer port, boolean debug, boolean overrideTECheck)

Deploys the skill onto the web with the specified route and port. If you want to enable request verification, set the third argument and to true. The fourth argument allows you to bypass the time expiry check on the SSL certificate of the web service in which the skill is being hosted, if for some reason the expiry check falsely fails. You can check out more details in the alexa-verifier-middleware module

Methods in alexa.response

For full documentation on constructing responses for the Echo, refer to this link

response(reqObj) [Constructor]

Generates a base response with the minimum required info to send sucessfully to the Echo device.

response.prompt(string prompt)

Creates a prompt field with the specified text. Features auto-detection of type of prompt text (SSML or regular text).

response.reprompt(string prompt)

Same as the prompt function, except for the reprompt field.

response.regularCard(string title, string textContent, optional string smallImageUrl, optional string largeImageUrl)

Creates a home card with the given arguments. If you only give two arguments, a 'Simple' card will be created with just the title and textContent (plain text). However, if you want to include an image, add the respective URLs and a 'Standard' card will be created, including everything that a simple card will have plus the wanted images.

response.linkAccountCard()

Creates a card set up for account linking.

response.setAttribute(string name, object value)

Creates/Modifies a session variable with the given name and value.

response.endSession(boolean value)

Sets the flag if the session between the Echo device and the user should end after sending the response. Note that by default, this flag is set to true

response.send()

Sends the constructed response to the Echo device.