【发布时间】:2017-08-28 19:16:20
【问题描述】:
已经走了 2 天不同的路线,无法弄清楚。也许有人可以阐明我的问题。我正在尝试运行一个连接到多个平台并且已经有大约 5 个工作的机器人服务器。
我现在也在尝试集成 Alexa。我看到 Alexa 请求进入我的服务器(因此 Alexa 技能和端点配置是正确的),但这也花了我相当长的时间,因为亚马逊显然只将流量发送到端口 443,因此允许在亚马逊开发中心定义另一个端口号,但什么都不做……很好!通过添加带有端口转发的负载均衡器来解决。
关于真正的问题。我正在尝试使用以下示例中的 alexa-app 作为我的框架:
var express = require("express");
var alexa = require("alexa-app");
var express_app = express();
var app = new alexa.app("sample");
app.intent("number", {
"slots": { "number": "AMAZON.NUMBER" },
"utterances": ["say the number {-|number}"]
},
function(request, response) {
var number = request.slot("number");
response.say("You asked for the number " + number);
}
);
// setup the alexa app and attach it to express before anything else
app.express({ expressApp: express_app });
// now POST calls to /sample in express will be handled by the app.request() function
// GET calls will not be handled
// from here on, you can setup any other express routes or middleware as normal
我不知道的部分是当我在一个文件中设置我的快速服务器然后想使用中间件函数在第二个文件中设置我的侦听器时如何使用它......类似于:
app.js:
var express = require("express");
var express_app = express();
https.createServer({
key: fs.readFileSync(key),
cert: fs.readFileSync(cert),
ca: fs.readFileSync(ca)
}, app).listen(port, function () {
console.log("http: api server listening on port " + port);
});
app.use('/alexa', controller.Bot.Messenger.Listener.botMiddleWare());
listener.js:
var alexa = require("alexa-app");
var app = new alexa.app("sample");
bot.botMiddleWare = function botMiddleWare () {
return <return function to connect to express in app.js>;
}
感谢任何帮助或指点!
【问题讨论】:
-
我没有绑定到 alexa-app,所以如果人们有其他库可以用来实现这一点,我非常愿意接受建议。
-
最后我设法让这个基于 Express 和 Alexa-app 工作。
-
您能否发布您的解决方案作为此问题的答案?
-
尝试使用 alexa-sdk。它的定义非常明确。
标签: node.js express alexa alexa-app