Alexa-skills 本地测试不起作用
Alexa-skills local test not working
我正在尝试在本地托管一项技能。我正在使用 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 命令来模拟 echo 发送的内容(我的 echo 还没有出现):
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
谢谢!
您正在向 http://localhost:8000/hello, but I believe it should be http://localhost:8000/ 发出 curl 请求。
当您尝试使用 Alexa 时,请不要忘记:
- 创建证书(self-signed足以开发)
- 如果节点模块不为您执行 https(如果模块正在执行,这也可能是您的问题的一部分。
- 使用命名端点。您不能在 Alexa 技能定义中使用 IP 地址。为 DNS 条目使用 DuckDNS 或类似服务。
插话有点晚,但这可能会让你的生活更轻松。
有一个专为本地技能开发而构建的工具。
来自 Alexa 的请求和响应将直接发送到您的本地服务器,以便您可以快速编码和调试,而无需进行任何部署。我发现这对我们自己的发展非常有用。
您还可以按照本教程在本地测试您的技能:
How to test Alexa locally
我正在尝试在本地托管一项技能。我正在使用 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 命令来模拟 echo 发送的内容(我的 echo 还没有出现):
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
谢谢!
您正在向 http://localhost:8000/hello, but I believe it should be http://localhost:8000/ 发出 curl 请求。
当您尝试使用 Alexa 时,请不要忘记:
- 创建证书(self-signed足以开发)
- 如果节点模块不为您执行 https(如果模块正在执行,这也可能是您的问题的一部分。
- 使用命名端点。您不能在 Alexa 技能定义中使用 IP 地址。为 DNS 条目使用 DuckDNS 或类似服务。
插话有点晚,但这可能会让你的生活更轻松。
有一个专为本地技能开发而构建的工具。
来自 Alexa 的请求和响应将直接发送到您的本地服务器,以便您可以快速编码和调试,而无需进行任何部署。我发现这对我们自己的发展非常有用。
您还可以按照本教程在本地测试您的技能: How to test Alexa locally