我正在尝试在本地托管技能。我正在使用alexa-skills npm模块和提供的示例代码:https://www.npmjs.com/package/alexa-skills。我在console.logs中添加了以检查并查看代码是否正在运行,当我运行它侦听的脚本时,但是当我连接它时我没有得到控制台日志。
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);
我使用curl命令来模拟回声会发送的内容(我的回声尚未出现):
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"
}
}'
我收到了这个回复:
* 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
对我来说,这看起来不行。我没有看到任何尝试从代码做出响应(当我测试它时,我确保ID匹配)。为什么这个脚本不生成输出而没有日志输出?
Node = v5.4.1
npm = 3.3.12
express = 4.13.3
alexa-skills = 0.1.0
谢谢!
答案 0 :(得分:3)
这有点晚,但这可能会让你的生活更轻松。
有一种工具是为本地技能开发而构建的。
Alexa的请求和响应将直接发送到您的本地服务器,这样您就可以快速编写代码并进行调试,而无需进行任何部署。我发现这对我们自己的发展非常有用。
答案 1 :(得分:2)
您正在向http://localhost:8000/hello发出curl请求,但我认为它应该是http://localhost:8000/。
当您尝试使用Alexa时,请不要忘记:
答案 2 :(得分:0)
您还可以按照本教程在本地测试您的技能: How to test Alexa locally