Reputation: 124
I am trying to host a skill locally. I am using the alexa-skills npm module and the provided example code: https://www.npmjs.com/package/alexa-skills. I added in console.logs to check and see if code is being ran, when I run the script it listens but I get no console logs when I connect to it.
var express = require('express'),
AlexaSkills = require('alexa-skills'),
app = express(),
port = process.env.PORT || 8000,
alexa = new AlexaSkills({
express: app, // required
route: "/", // optional, defaults to "/"
applicationId: "amzn1.echo-sdk-ams.app.XXXXXXX" // optional, but recommended
});
alexa.launch(function(req, res) {
console.log('launch \n');
var phrase = "Welcome to my app!";
var options = {
shouldEndSession: false,
outputSpeech: phrase,
reprompt: "What was that?"
};
alexa.send(req, res, options);
});
alexa.intent('Hello', function(req, res, slots) {
console.log('intent \n');
console.log(slots);
var phrase = 'Hello World!';
var options = {
shouldEndSession: true,
outputSpeech: phrase,
card: alexa.buildCard("Card Title", phrase)
};
alexa.send(req, res, options);
});
alexa.ended(function(req, res, reason) {
console.log(reason);
});
console.log('starting server \n');
app.listen(port);
I use a curl command, to simulate what the echo would send (my echo isn't here yet):
curl -v -k http://localhost:8000/hello --data-binary '{
"session": {
"sessionId": "SessionId.XXXXXXXXXX",
"application": {
"applicationId": "amzn1.echo-sdk-ams.app.XXXXXXXXX"
},
"user": {
"userId": "amzn1.echo-sdk-account.XXXXXXXXXX"
},
"new": true
},
"request": {
"type": "LaunchRequest",
"requestId": "EdwRequestId.XXXXXXXXX",
"timestamp": "2016-01-18T05:36:27Z"
}
}'
I get this response:
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> POST /hello HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Length: 493
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 493 out of 493 bytes
< HTTP/1.1 404 Not Found
< X-Powered-By: Express
< X-Content-Type-Options: nosniff
< Content-Type: text/html; charset=utf-8
< Content-Length: 19
< Date: Mon, 18 Jan 2016 05:47:44 GMT
< Connection: keep-alive
<
Cannot POST /hello
* Connection #0 to host localhost left intact
To me it looks like this is not working. I don't see any attempt at a response being made from the code (when I test it I do make sure IDs match). Why is this script not generating output and no log output?
Node = v5.4.1
npm = 3.3.12
express = 4.13.3
alexa-skills = 0.1.0
Thank you!
Upvotes: 3
Views: 1457
Reputation: 119
You can also test your skill locally by following this tutorial: How to test Alexa locally
Upvotes: 0
Reputation: 1164
It's a bit late to chime in, but this may make your life easier.
There is a tool that was built for local skill development.
Requests and responses from Alexa will be sent directly to your local server, so that you can quickly code and debug without having to do any deployments. I have found this to be very useful for our own development.
It's open source: https://github.com/bespoken/bst
Upvotes: 3
Reputation: 4163
You are making the curl request to http://localhost:8000/hello, but I believe it should be http://localhost:8000/.
When you attempt to use from Alexa, don't forget:
Upvotes: 2