0
[Node.js ASK] (https://developer.amazon.com/public/community/post/Tx213D2XQIYH864/Announcing-the-Alexa-Skills-Kit-for-Node-js)를 사용하여 API에서 데이터를 반환하는 간단한 Alexa 스킬을 작성하려고합니다. http를 처리기 내에 넣으려고했지만 콜백이 비동기 적으로 API 데이터를 반환하기 전에 Alexa가 처리기를 완료합니다.Alexa Node.js 스킬 키트 - 처리기가 완료되기 전에 콜백 데이터를 반환해야합니다.
내가 답을 찾고되었고, 내 생각이 현재 :
- 사용하지
- 알아낼 동 기적으로 데이터를 내가 을 잃었 간단한
- 뭔가를 얻을 수있는 방법 Node.js를 코드의
코어 :
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.registerHandlers(handler);
alexa.execute();
};
var handler = Alexa.CreateStateHandler(states.x, {
'intent': function() {
var options = {
host: baseURL,
path: pathURL
};
callback = function(response) {
var str = "";
response.on('data', function(piece) {
str += piece;
});
response.on('end', function() {
//does not get executed
this.emit(':tell', str, "test");
});
}
http.request(options, callback).end();
//this does get executed if I leave this here
this.emit(':tell'...);
};