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'...);
};