Git Product home page Git Product logo

alexa-app-server's Introduction

alexa-app-server

An Alexa App (Skill) Server module using Node.js and the alexa-app module.

NPM Build Status Coverage Status

Stable Release

You're reading the documentation for the next release of alexa-app-server, which should be 3.0.3. Please see CHANGELOG and make sure to read UPGRADING when upgrading from a previous version. The current stable release is 3.0.2.

Installation

npm install alexa-app-server --save

Usage

var AlexaAppServer = require('alexa-app-server');

var instance = AlexaAppServer.start({
  server_root: __dirname,     // Path to root
  public_html: "public_html", // Static content
  app_dir: "apps",            // Location of alexa-app modules
  app_root: "/alexa/",        // Service root
  port: 8080                  // Port to use
});

instance.stop();              // Stop the server

Summary

The alexa-app-server module offers a stand-alone web server to host Alexa Apps (Skills). Think of it as a simple "container" that allows you to easily publish multiple Alexa Apps with one server. This module does not help you write the Alexa Apps (Skills) themselves, as apps are independent modules, written using the alexa-app framework.

The server can also serve static website content, and offers a built-in Alexa App debugger/simulator. This allows you to test your skill using a web browser and view the responses, without actually using an Amazon Echo.

Key Features

  • Multiple apps can be hosted on a single server
    • Apps are stored in the /apps directory by default
    • Each app is a stand-alone Node module, built using the alexa-app framework
    • Each app must export its alexa-app instance to be loaded into the server
    • package.json contains information about the app, including (optionally) the appId
    • The hotswap module reloads code changes to apps, if they set module.change_code = 1
  • Built-in Echo Simulator
    • Debug apps by issuing a GET request to the app endpoints
    • Send simulated requests to your app, view the JSON response
    • Session variables are automatically maintained between requests
    • Send intent requests and set slot values
    • View generated schema and utterances
  • Supports HTTPs

Starting The Server

You can either get a reference to an AlexaAppServer instance, or you can use the start() method shortcut. Getting a reference allows you to inspect or change the server object later.

var AlexaAppServer = require('alexa-app-server');
var server = new AlexaAppServer({ port: 80, debug: false });
server.start();
server.express.use('/test', function(req, res) { res.send("OK"); });
var AlexaAppServer = require('alexa-app-server');
AlexaAppServer.start({ port: 8080 });

Configuration Options

The start() method accepts a configuration object. The defaults are shown below.

require('alexa-app-server').start({

  // In order to start the server from a working directory other than
  // where your server.js file, you need to provide Node the full path
  // to your server's root directory.
  // Default is __dirname.
  server_root: __dirname,

  // A directory containing static content to serve as the document root.
  // This directory is relative to the script using alexa-app-server, not
  // relative to the module directory.
  // Default is 'public_html'.
  public_html: 'public_html',

  // A directory containing Alexa Apps. This directory should contain one
  // or more subdirectories. Each subdirectory is a stand-alone Alexa App
  // built with the alexa-app framework. These directories are each
  // processed during server startup and hooked into the server.
  // Default is 'apps'.
  app_dir: 'apps',

  // The prefix to use for all Alexa Apps. For example, you may want all
  // your Alexa endpoints to be accessed under the "/api/" path off the
  // root of your web server.
  // Default is 'alexa'.
  app_root: 'alexa',

  // The directory containing server-side processing modules.
  // Default is 'server'.
  server_dir: 'server',

  // Enable http support.
  // Default is true.
  httpEnabled: true,

  // The port the server should bind to.
  // Default is 8080.
  port: 8080,

  // The host address in which the server should bind to.
  // By default, the host is omitted and the server will accept connections on
  // any IPv6 address (::) when IPv6 is available, or any IPv4 address (0.0.0.0) otherwise.
  host: '127.0.0.1',

  // Show debugger UI with GET requests to Alexa App endpoints.
  // Note that the 'verify' and 'debug' options cannot be used together.
  // Default is true.
  debug: true,

  // Log useful information with console.log().
  // Default is true.
  log: true,

  // Insert alexa-verifier-middleware and add verification for Alexa requests
  // as required by the Alexa certification process.
  // Default is false.
  verify: false,

  // The pre() method is called after the express server has been instantiated, but
  // before any Alexa Apps have been loaded. It is passed the AlexaAppServer object itself.
  pre: function(appServer) { },

  // The post() method is called after the server has started and the start() method
  // is ready to exit. It's passed the AlexaAppServer object itself.
  post: function(appServer) { },

  // Like pre(), but this function is fired on every request, but before the
  // application itself gets called. You can use this to load up user details before
  // every request, for example, and insert it into the json request itself for
  // the application to use.
  // If it returns a falsy value, the request json is not changed.
  // If it returns a non-falsy value, the request json is replaced with what was returned.
  // If it returns a Promise, request processing pauses until the Promise resolves.
  // The value passed on by the promise (if any) replaces the request json.
  preRequest: function(json, request, response) { },

  // Like post(), but this function is fired after every request. It has a final
  // opportunity to modify the JSON response before it is returned back to the
  // Alexa service.
  // If it returns a falsy value, the response json is not changed.
  // If it returns a non-falsy value, the response json is replaced with what was returned.
  // If it returns a Promise, response processing pauses until the Promise resolves.
  // The value passed on by the promise (if any) replaces the response json.
  postRequest : function(json, request, response) { },

  // Enable https support. Note httpsPort, privateKey, and certificate are required.
  // Default is false.
  httpsEnabled: false,

  // The https port the server will bind to. Required for httpsEnabled support.
  // Default is undefined.
  httpsPort: 443,

  // The private key filename. This file must reside in the sslcert folder under the
  // root of the project.
  // Default is undefined.
  privateKey: 'private-key.pem',

  // The certificate filename. This file must reside in the sslcert folder under the root of the
  // project.
  // Default is undefined.
  certificate: 'cert.cer',

  // The certificate chain bundle filename. This is an optional file that must reside in the
  // sslcert folder under the root of the project.
  // Default is undefined.
  chain: 'cert.ca_bundle',

  // An optional passphrase used to validate certificate and key files. For best practice, don't
  // put the password directly in your source code, especially if it's going to be on GitHub, and
  // instead, load it from process.env or a file included in the .gitignore list.
  // Default is undefined.
  passphrase: 'passphrase'

});

Enabling HTTPs

You can use a PaaS, such as Heroku, which comes with SSL enabled out-of-the-box.

Alternatively, you can enable HTTPs support using the instructions below.

Generate a x509 SSL Certificate using the following:

openssl genrsa -out private-key.pem 1024
openssl req -new -x509 -key private-key.pem -out cert.cer -days 365

To make sure the certificate is verified, use the following:

openssl x509 -noout -text -in cert.cer

Place the two generated files in the sslcert directory.

Add the following properties the to config that creates the server.

AlexaAppServer.start({
  httpsPort: 443,
  httpsEnabled: true,
  privateKey: 'private-key.pem',
  certificate: 'cert.cer'
});

Debugging With The Echo Simulator

Each app (skill) is available at a url endpoint on the server, and responds to POST requests from the Echo. If you load an app's endpoint in your browser with a GET request, it will display an echo simulator that can be used to debug your application. With it, you can send different request types to your app, load slots with values you specify, etc and see the actual generated JSON output from your application.

Show Application ID

To show the application ID in the session correctly, set applicationId in package.json.

{
  "alexa": {
    "applicationId": "amzn1.echo-sdk-ams.app.999999-d0ed-9999-ad00-999999d00ebe"
  }
}

Assign the value in your alexa-app.

var app = new alexa.app('hello_world');
app.id = require('./package.json').alexa.applicationId;

View Generated Schema And Utterances

In the Echo Simulator, your application's schema definition and example utterances are displayed. These can be directly pasted into the Amazon Developer interface when defining your skill.

You can also get the schema and utterances directly from your endpoint url using url parameters:

GET /your/app/endpoint?schema
GET /your/app/endpoint?utterances

Dynamic Server-Side Functionality

Most servers will need some server-side processing logic, such as handling logins, or processing forms. You can specify a directory containing files that define server-side functionality by hooking into Express. These files are stand-alone modules that export a single function that the framework calls. An example is below and in the "examples/server" directory.

The default directory used to hold these modules is "server" but you can change this by using the "server_dir" configuration parameter, as shown above.

For example, examples/server/login.js:

module.exports = function(express, alexaAppServerObject) {
  express.use('/login', function(req, res) {
    res.send("imagine this is a dynamic server-side login action");
  });
};

Sample App Structure

This is a sample directory structure of what a complete app server might look like.

.
+--- server.js
+--- sslcert
+--- apps
     +--- alexa-app-1
          +--- package.json
          +--- index.js
          +--- node_modules
     +--- alexa-app-2
          +--- package.json
          +--- index.js
          +--- node_modules
+--- public_html
     +--- index.html

Running in Production

While individual alexa-app functions can be deployed to AWS Lambda, the alexa-app-server module can be used in both development and production for multiple applications. It will work with the Alexa Service Simulator on developer.amazon.com, a real Echo device, etc.

Choose HTTPs in Service Endpoint Type in the Alexa app configuration on developer.amazon.com and point to one of your apps. For example, alexa-app-server-hello-world is available at https://alexa-app-server-hello-world.herokuapp.com/alexa/hello_world.

Make sure to set verify: true and debug: false in production environments.

Examples

See the example application in the "examples" directory.

History

See CHANGELOG for details.

License

Copyright (c) 2016-2017 Matt Kruse

MIT License, see LICENSE for details.

alexa-app-server's People

Contributors

benedekh avatar dblock avatar martincostello avatar matt-kruse avatar mreinstein avatar rickwargo avatar seattleacademy avatar siedi avatar tejashah88 avatar tommettam avatar zqylur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alexa-app-server's Issues

Errors with no line numbers

I'm getting this in the console:

Error loading app [/Users/tlovett1/projects/alexa-app-server/examples/apps/airportinfo/index.js]: SyntaxError: Invalid or unexpected token

How can I find the line number?

Invalid schema for guessinggame example.

When attempting to add intents and utterances to the Amazon app portal for the example app guessing game, an error message is displayed:

Error: There was a problem with your request: 'guess' is an intent name as well as a slot name. Slot names and intent names must not overlap._

Consider adding a license

Hi there! This is awesome stuff. I was hoping to incorporate some of this into something I'm working on, but I noticed there wasn't a license. I was wondering if you wouldn't mind adding one to the project so that I could do that and contribute any improvements back upstream.

The same is true for @matt-kruse/alexa-app, but I figured I'd only bug you once. ;)

Thanks!

Missing license

Would it be possible to add a license declaration, similar to alexa-app?

How can i make a http request?

Can you please add an example skill with a http request?
I want to query an API but i think my way is not so perfect.

`var alexa = require('alexa-app');
var async = require('async');
var request = require('request');

// Allow this module to be reloaded by hotswap when changed
module.change_code = 1;

// Define an alexa-app
var app = new alexa.app('hello_world');

async.parallel([
function(callback) {
var options = {
url: 'https://xxxxxxxxxx.de/ddd',
timeout: 3000
}
request(options, function(err, response, body) {
// JSON body
if(err) { console.log(err); callback(true); return; }
obj = JSON.parse(body);
callback(false, obj);
});
}],
function(err, results) {
app.launch(function(req, res) {
sayToday(results[0], req, res);
});

  app.intent('DayIntent', {
    "slots": { "DAY": "DAY_OF_WEEK"},
    "utterances": ["xxxxx"]
  }, function(req, res) {
      if(err) { 
        res.say("sdfsdfsdfsdf"); 
        return; 
      }
      
      //parse JSON
  });
  
}

);`

Custom Slot Types don't appear in Alexa Tester

I originally logged this against alexa-app (here)and was told to try moving it here.

Trying to use a custom slot type, which basically looks like this in my intent:

    {
        "slots":{"COMMAND":"COMMAND_SLOT"},
        "utterances":[ "send {the|} {command|} {commands|COMMAND}" ]
    }

(where commands is an app.dictionary)

I've also tried:

    {
        "slots":{"COMMAND":"COMMAND_SLOT"},
        "utterances":[ "send {the|} {command|} {-|COMMAND}" ]
    }

In both cases, the Utterances properly appear in the Alexa Tester (using alexa-app-server 2.3.1), but the Custom Slot Type section of the tester is always empty. I was under the impression the custom slot type info should appear there to facilitate copy/pasting into the interaction model.

I started on alexa-app 2.3.4 and upgraded to 2.4.0 ... same problem.

Thanks!

Re-organize tests

The current tests are not organized properly. If anyone is willing to re-write the tests, please send a PR.

Deal with multiple slashes in normalizedRoot

From #64

One (simple) formatting suggestion is to remove trailing slashes from the normalizedRoot in self.loadapps(). The comments have an example where the server root ends with a slash and if included, the message says, "loaded app [hello_world] at endpoint: /alexa//hello_world."

Play an Audio Stream?

Is it possible to play an online audio stream/file with this server on Alexa? I haven't found anything in the examples or package to use it with. It would be nice to have an example or a small documentation for stuff like this.

My PHPStorm gave me res.play(); but that didn't really work out either.

alexa-verifier set the "verify" flag to true and calling from a non echo throws an error

I used the example code here:

var AlexaAppServer = require("alexa-app-server");
var server = new AlexaAppServer( {
	port:3000
    ,verify: true
    ,public_html: "public"
	// Use preRequest to load user data on each request and add it to the request json.
	// In reality, this data would come from a db or files, etc.
	,preRequest: function(json,req,res) {
		//console.log("preRequest fired");
		//json.userDetails = { "name":"Bob Smith" };
	}
	// Add a dummy attribute to the response
	,postRequest: function(json,req,res) {
		//json.dummy = "text";
	}
} );
server.start();

and added the verify flag so that I can pass the skills certification. When I try to make a request through postman it does fail (which is good) but It's not throwing a 500, instead it throws the following error:

ReferenceError: er is not defined
    at Object.handle (/my/path/node_modules/alexa-app-server/index.js:97:57)
    at next_layer (/my/path/node_modules/alexa-app-server/node_modules/express/lib/router/route.js:103:13)
    at Route.dispatch (/my/path/node_modules/alexa-app-server/node_modules/express/lib/router/route.js:107:5)
    at /my/path/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:195:24
    at Function.proto.process_params (/my/path/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:251:12)
    at next (/my/path/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:189:19)
    at Layer.handle (/my/path/node_modules/alexa-app-server/index.js:79:15)
    at trim_prefix (/my/path/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:226:17)
    at /my/path/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:198:9
    at Function.proto.process_params (/my/path/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:251:12)
    at next (/my/path/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:189:19)
    at next (/my/path/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:166:38)
    at Layer.staticMiddleware [as handle] (/my/path/node_modules/alexa-app-server/node_modules/serve-static/index.js:55:61)
    at trim_prefix (/my/path/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:226:17)
    at /my/path/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:198:9
    at Function.proto.process_params (/my/path/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:251:12)
    at next (/my/path/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:189:19)
    at IncomingMessage.<anonymous> (/my/path/node_modules/alexa-app-server/index.js:184:5)
    at emitNone (events.js:86:13)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Add I18n support

The request templates don't have the locale attribute need for i18n

Application ID not getting set when testing(debug)

I have added the application id to the project.json file. I verified that app.id is getting set by adding a console.log into node_modules/alexa-app-server/index.js(line 112).

But when I bring up the POST testing page the application id is not being replaced in the template. I'm don't do much browser javascript programming, and can't figure out why.

Is this a bug, or did I miss a configuration step somewhere?

alexa simulator doesn't end sessions when shouldEndSession is set

It seems that LaunchRequest always sets session.new true, and all other requests always set session.new false. This doesn't seem to be the way that real AVS works, though. I'm not real sure how possible it would be to change this, given that I haven't looked into how the tester works at all, but figure it's worth noting, and if someone does have the time and inclination to dig into it, it'd be real helpful for some people. :-)

That said, as soon as I get some time (if ever), I'm going to look into it as well as other things.

verify & debug in production

Hi,

I just updated to the latest version, and now I have verify: true and debug: false in my code. I tested it out in production, and it doesn't work.

I get the following
{ status: "failure", reason: "missing certificate url" }

I have a feeling that it has to do with debug: false. I think turning off the debugger page deactivates the url's ability to be active.

Is anyone else seeing this too? Thanks!

Request hangs during POST with body content

I have a script in the server directory that requires POST method, and it hangs now that I've updated alexa-app-server. I was able to get around this by wrapping the raw body function with:

if (config.verify) {
  ...raw body parser for request verification...
}

It seems like req.on('data', function(data) { does not get called if the POST method is used.

Release 3.0.0

Considering how many changes we've all contributed to this library, wouldn't it make sense to bump the version to 2.4.0 from 2.3.1, instead of 2.3.2?

Templates in test.ejs do not include context property. userId is extracted from this...

I am learning the Alexa ecosystem and in running the persistence tutorial, the execution failed due to userId being null. It appears the alexa-app is pulling the userId from the context property, but the request template does not have said property. I modified my copy of test.ejs and it now works. Is there another configuration parameter that I should have set so that his would happen "automagically"?

`TypeError: undefined is not a function` on express.post

Ok, so I have alexa-app-server server.js like so:

var AlexaAppServer = require('alexa-app-server');

var instance = AlexaAppServer.start({
  server_root: __dirname,     // Path to root
  public_html: "public_html", // Static content
  app_dir: "apps",            // Location of alexa-app modules
  app_root: "/alexa/",        // Service root
  port: 8080,                  // Port to use

  httpsPort: 8081,
  httpsEnabled: true,
  privateKey: 'private-key.pem',
  certificate: 'cert.cer',

  debug: true,
  verify: false
});

And then in ./apps/hello_world/index.js, I have:

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

// Allow this module to be reloaded by hotswap when changed
module.change_code = 1;

// Define an alexa-app
var app = new alexa.app('hello_world');
app.launch(function(req, res) {
  res.say("Hello World!!");
});

app.intent('NameIntent', {
  "slots": { "NAME": "LITERAL", "AGE": "NUMBER" },
  "utterances": ["{My name is|my name's} {matt|bob|bill|jake|nancy|mary|jane|NAME} and I am {1-100|AGE}{ years old|}"]
}, function(req, res) {
  res.say('Your name is ' + req.slot('NAME') + ' and you are ' + req.slot('AGE') + ' years old');
});

app.intent('AgeIntent', {
  "slots": { "AGE": "NUMBER" },
  "utterances": ["My age is {1-100|AGE}"]
}, function(req, res) {
  res.say('Your age is ' + req.slot('AGE'));
});

module.exports = app;

But when I start the server I get this stack trace complaining about express.post:

serving static content from: /home/ec2-user/Tinkering/xAlexa/public_html
loading server-side modules from: /home/ec2-user/Tinkering/xAlexa/server
   loaded /home/ec2-user/Tinkering/xAlexa/server/login.js
loading apps from: /home/ec2-user/Tinkering/xAlexa/apps
/home/ec2-user/Tinkering/xAlexa/apps/hello_world/node_modules/alexa-app/index.js:491
    express.post(endpoint, function(req, res) {
            ^
TypeError: undefined is not a function
    at Object.express (/home/ec2-user/Tinkering/xAlexa/apps/hello_world/node_modules/alexa-app/index.js:491:13)
    at /home/ec2-user/Tinkering/xAlexa/node_modules/alexa-app-server/index.js:122:11
    at Array.forEach (native)
    at Object.self.load_apps (/home/ec2-user/Tinkering/xAlexa/node_modules/alexa-app-server/index.js:82:30)
    at Object.self.start (/home/ec2-user/Tinkering/xAlexa/node_modules/alexa-app-server/index.js:188:12)
    at Function.appServer.start (/home/ec2-user/Tinkering/xAlexa/node_modules/alexa-app-server/index.js:295:21)
    at Object.<anonymous> (/home/ec2-user/Tinkering/xAlexa/server.js:3:31)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

I tried installing express then updating ./apps/hello_world/index.js to be:

var express = require( 'express' );
var alexa = require('alexa-app');
var express_app = express();

// Allow this module to be reloaded by hotswap when changed
module.change_code = 1;

// Define an alexa-app
var app = new alexa.app('hello_world');
app.launch(function(req, res) {
  res.say("Hello World!!");
});

app.intent('NameIntent', {
  "slots": { "NAME": "LITERAL", "AGE": "NUMBER" },
  "utterances": ["{My name is|my name's} {matt|bob|bill|jake|nancy|mary|jane|NAME} and I am {1-100|AGE}{ years old|}"]
}, function(req, res) {
  res.say('Your name is ' + req.slot('NAME') + ' and you are ' + req.slot('AGE') + ' years old');
});

app.intent('AgeIntent', {
  "slots": { "AGE": "NUMBER" },
  "utterances": ["My age is {1-100|AGE}"]
}, function(req, res) {
  res.say('Your age is ' + req.slot('AGE'));
});

app.express({ expressApp: express_app });
module.exports = app;

And this starts the server, but the app does not load:

serving static content from: /home/ec2-user/Tinkering/xAlexa/public_html
loading server-side modules from: /home/ec2-user/Tinkering/xAlexa/server
   loaded /home/ec2-user/Tinkering/xAlexa/server/login.js
loading apps from: /home/ec2-user/Tinkering/xAlexa/apps
   error loading app [/home/ec2-user/Tinkering/xAlexa/apps/hello_world/index.js]: TypeError: undefined is not a function
enabling https
listening on https port 8081
listening on http port 8080

Any ideas?

Add support for more node versions for Travis-CI

Currently, the only tested node versions are v6 and v7 (according to travis-ci). It's not very easy to add other versions without some errors encountered, mainly with danger-js (see #48 for attempts by me to solve this issue).

If future releases of alexa-app-server are to intentionally drop support for older versions of node, it's best to add a section in the README stating which versions are supported.

Multi Language Support?

Is there any way to check which language my request is in so i can forward it to my intent?

Utterance generation bug

I am filing this here but also cross-filed against the alexa-app. Please feel free to close out one of them.

@matt-kruse There seems to be a bug in the server generation of utterance permutations. For example the following:

"utterances": ['{to|} set temperature to {64-80|number}']

generates utterances as follows:

setTempsIntent	to set temperature to {sixty four|number}
setTempsIntent	set temperature to {sixty five|number}
setTempsIntent	to set temperature to {sixty six|number}
setTempsIntent	set temperature to {sixty seven|number}
...

but what I believe should be generated is:

setTempsIntent	to set temperature to {sixty four|number}
setTempsIntent	set temperature to {sixty four|number}
setTempsIntent	to set temperature to {sixty five|number}
setTempsIntent	set temperature to {sixty five|number}
setTempsIntent	to set temperature to {sixty six|number}
setTempsIntent	set temperature to {sixty six|number}
setTempsIntent	to set temperature to {sixty seven|number}
setTempsIntent	set temperature to {sixty seven|number}
...

Add support for node Alexa-sdk

When I tried to test the node alexa-sdk (https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs) locally, I got a response from alexa-app-server of...

App [app-name] is not an instance of alexa-app

which means that any user using alexa-sdk instead of alexa-app (https://github.com/matt-kruse/alexa-app) cannot proceed with local testing. Is there support for this and I simply haven't configured alex-sdk or my app correctly, or does the support for alexa-sdk not exist? If the latter, ought there be support for alexa-sdk?

Add Listen IP config option

Hi,

Would you please add a 'listen' IP configuration option to AlexaAppServer.start()? For example, in index.js, line 218, add a config.listen variable...

self.express.listen(config.port, config.listen);

This way, users can control the listen IP address for the service. For now we are 'hacking' it by modifying this line to:

self.express.listen(config.port, '149.2.28.245');

Thanks!

missing certificate url

Hi,

every i time i start my server i get the following error:
{"status":"failure","reason":"missing certificate url"}

I tried it with a self signed certificat and altough with an existing wildcard certificat from my domain.
Whats wrong there ?

I've tried altough the old version 2.3.1 (as mentioned in another issue) , but i get the same error.

Here are my settings:

var AlexaAppServer = require("alexa-app-server");

AlexaAppServer.start({
  server_root: __dirname,
  port: 83,
  debug:false,
  verify:true,
  log : true,
  // Use preRequest to load user data on each request and add it to the request json.
  // In reality, this data would come from a db or files, etc.
  preRequest: function(json, req, res) {
    console.log("preRequest fired");
    json.userDetails = { "name": "Bob Smith" };
  },
  // Add a dummy attribute to the response
  postRequest: function(json, req, res) {
    console.log("JKO");
    json.dummy = "text";
  },

    httpsEnabled: true,

    // The https port the server will bind to. Required for httpsEnabled support.
    // Default is undefined.
    httpsPort: 8181,

    // The private key filename. This file must reside in the sslcert folder under the
    // root of the project. Default is undefined.
    privateKey: 'key.key',

    // The certificate filename. This file must reside in the sslcert folder under the root of the
    // project. Default is undefined.
    certificate: 'crt.crt',

    bundle: 'ca.crt'
});

How to test Alexa Skills with Mocha or other Framework and alexa-app/-server

Hello,

I really like the alexa-app and alexa-app-server environment and tools. They enable me to create Alexa-Skills easily. But what I am not sure of (didn't find something on the Internet so far or must have missed it) how I can test the Skill-Intents with eg. Mocha and Chai? It easy to open the Skill in the Browser, see the response and everything there, but it is not scalable. Is it?

Or how can I test multiple slot-values (eg wrong, valid or empty) against multiple Intents?

I am thinking about something like this example: Alexa Skill Test Framework from BrianMacIntosh. Or how do you test your skills within this setup? Am I looking in the wrong direction?

Thank you for your help guys.

req.slot should not log console error when default value is passed

req.slot('abc', null)
If abc isn't passed with intent request, it'll report error like

missing intent in request: abc [TypeError: Cannot read property 'value' of undefined]

IMO, passing default value means it can be empty and consumer of this method will handle it. In this case we shouldn't log as error. At most, we can set as warning.

I can send a PR if you agree.

Error on app.customSlotTypes()

The merge that was done under commit 4be7899 seems to have introduced a call to app.customSlotTypes(). However, this seems to have caused a regression. When I now start my (alexa-app-server and alexa-app-based skill), I get an error like this:

TypeError: app.customSlotTypes is not a function
    at Object.handle (/Users/xyz/Documents/Projects/xyz123/myprojects/Alexa/node_modules/alexa-app-server/index.js:131:81)

It's not clear to me what should be implementing the customSlotTypes() method, but I don't see it elsewhere in the whole source code tree for alexa-app-server or alexa-app.

I see this problem with alexa-app-server 2.3.0. If I regress to 2.2.4, it goes away. I am using alexa-app 2.3.4.

Testing interface

Amazon certification rules dictate that the end point must verify that the request has come from Alexa. However, when verification is ON, this breaks the local testing tool.

The testing tool probably needs to be automatically disabled when config.verify is on. In fact, the testing tool should probably be disabled in any production environment.

Test hangs with certCheck: true

When you checkCert: true the following test hangs.

/*jshint expr: true*/
"use strict";
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
var sinonChai = require("sinon-chai");
chai.use(sinonChai);
var chaiString = require('chai-string');
chai.use(chaiString);
var expect = chai.expect;
chai.config.includeStack = true;
var mockHelper = require("./helpers/mock_helper");
var sinon = require("sinon");
var express = require('express');
var request = require("supertest-as-promised");
var bodyParser = require('body-parser');
var path = require('path');

describe("Alexa", function() {
  var Alexa = require("../index");
  var mockRequest = mockHelper.load("intent_request_airport_info.json");

  describe("app", function() {
    var app;
    var testServer;
    var testApp;

    beforeEach(function() {
      app = express();
      app.use(bodyParser.json());
      app.set('views', path.join(__dirname, 'views'));
      app.set('view engine', 'ejs');
      testApp = new Alexa.app("testApp");
      testServer = app.listen(3000);
    });

    afterEach(function() {
      testServer.close();
    });

    context("#express with checkCert=true", function() {
      beforeEach(function() {
        testApp.express({
          expressApp: app,
          router: express.Router(),
          checkCert: true,
          debug: false
        });
      });

      it("checks cert header", function() {
        return request(testServer)
          .post('/testApp')
          .set('signaturecertchainurl', 'dummy')
          .set('signature', 'dummy')
          .send(mockRequest)
          .expect(401).then(function(res) {
            expect(res.body.status).to.equal("failure");
            expect(res.body.reason).to.equal("signature is not base64 encoded");
          });
      });
    });
  });
});

how to configure on the Amazon side?

question:

I've put together an alexa-app-server, with https support as described in the README, but no amount of fooling with the settings on developer.amazon.com seems to get it to work. I just get "The SSL handshake failed". I also tried following the Amazon directions for generating a certificate, and put it in the same place in the alexa-app-server and get the same response.

Any ideas or suggestions? I know it's not directly related to the app-server, but I'm hoping someone might have some experience they can lend.

Hotswap broken

I have subfolders in some of my apps. Hotswap will reload for index.js but not for my other js files in the subfolders. How can I get hotswap to listen to all files in my app's hierarchy?

setting "verify: true" is causing alexa app to timeout from echo devices

When I set the flag for verify to be true it works when I try to check my endpoint from a non-echo device. It properly returns a 401 error message:

{
  "status": "failure",
  "reason": "The signaturecertchainurl HTTP request header is invalid!"
}

However, when I try to test the app from the Amazon Alexa dev website or any echo devices, it throws an error that the requested skill has taken too long to respond.

Switching the flag back to false or removing completely and it goes back to working from echo devices but obviously it is going to fail certification.

Simplify request verification code

I noticed that this portion of the code could be replaced with some from the alexa-verifier-middleware module.

// starts at line 73 in index.js
if (config.verify) {
    // could be replaced with something like: self.express.use(endpoint, avm());
    self.express.use(endpoint, function(req, res, next) {
        req.verified = false;
        if (!req.headers.signaturecertchainurl) {
            return next();
        }

        var cert_url = req.headers.signaturecertchainurl;
        var signature = req.headers.signature;
        var requestBody = req.rawBody;
        verifier(cert_url, signature, requestBody, function(er) {
            if (er) {
                res.status(401).json({ status: 'failure', reason: er });
            } else {
                req.verified = true;
                next();
            }
        });
    });
}

Thoughts?

Implement feature-based testing system

What is really needed for this library (and possible other alexa-js libraries) is a feature-based testing system, that focuses more on what features are being tested and how well will they work against various scenarios. For example, if I have two alexa-app-servers, one on an AWS Lambda instance and one on an express instance, I should have some reassurance that both instances will work identically feature-wise. This would also ideally help us isolate any bugs so that if a certain group of tests of one feature fail, the feature itself would be deemed buggy.

Support for ca chain certificates

Hello,

Alexa would not connect to the server with the SSL cert that I had without also including the ca bundle (spent several hours of it working on my local machine and not on Alexa dev network to figure this one out)

I have forked and have added the code here and have made the ca cert optional as to keep the original functionality and to allow the inclusion of the cert if available.

The start method returns a single instance

Start returns a single instance, but that one may not be started since there're 2 instances, one for HTTP and one for HTTPS. In the case both are enabled it's even less clear what happens there.

isPortTaken tests don't work

I put garbage instead of port numbers in the tests that call isPortTaken and they still pass. Something looks not right, this should return a promise and reject it?

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.