我在节点js中编写了一个hello world alexa技能并将其部署在heroku中。 我必须使用websockets将响应发送到web ui(比如我本地机器中的html页面)。这可能吗?
我的服务器代码-server.js
'use strict';
var AlexaAppServer = require( 'alexa-app-server' );
var server = new AlexaAppServer( {
httpsEnabled: false,
port: 8080
} );
server.start();
下面是index.js
module.change_code = 1;
'use strict';
var alexa = require( 'alexa-app' );
var app = new alexa.app('Helloworld');
app.launch( function( request, response ) {
console.log(app);
//console.log(request);
response.say( 'Welcome to Welcome to helloworld.' );
});
app.error = function( exception, request, response ) {
console.log(exception)
console.log(request);
console.log(response);
response.say( 'Sorry an error occured ' + error.message);
};
app.intent('Helloworld',
{
"slots":[]
,"utterances":[
"hello alexa",
"hi alexa",
"how are you?"]
},
function(request,response) {
response.say("welcome user");
//send this same response to a webpage using socket
}
);
module.exports = app;
答案 0 :(得分:0)
你是否正在尝试与alexa交互的html页面。如果你是对的,你必须使用websocket,但是你可以尝试在AWS本身提供的API网关,在API网关中你可以调用它到你的html页面,这个链接可能对你有所帮助。 https://blog.prototypr.io/using-voice-commands-to-control-a-website-with-amazon-echo-alexa-part-1-6-a35edbfef405