2016-07-22 11 views
1

私はウィキペディアのサービスを呼び出すためにヒストリカルの例を試していました。私は開始時のメッセージにコールを入れます。私はそれが呼び出しstmtをヒットするポイントまで私のメッセージを印刷しているのを見ることができます。コンソールには何も表示されません。以下のコードは次のようになります。alexaのスキルwebserviceコールが発生しません

var https = require('https'); 
var urlPrefix = 'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&explaintext=&exsectionformat=plain&redirects=&titles='; 

HowTo.prototype.eventHandlers.onLaunch = function (launchRequest, session, response) { 
    console.log("vik::::::::::::: before service call "); 


    var speechText = "Welcome to the your assistant? ... what can I help you with."; 
    var repromptText = "For instructions on what you can say, say help me."; 
    response.ask(speechText, repromptText); 
    getJsonEventsFromWikipedia("day", "date", function (events) { 
     console.log("vik::::::::::::: wikipedia response received"); 
     console.log("values are:" + events); 
    }); 
}; 


function getJsonEventsFromWikipedia(day, date, eventCallback) { 
    var url = urlPrefix+'Jan_21'; 
    console.log("url to invoke is:" + url); 

    https.get(url, function(res) { 
     console.log("vik:::::::::::::::::::::inside data fetch"); 
     var body = ''; 

     res.on('data', function (chunk) { 
      body += chunk; 
     }); 

     res.on('end', function() { 
      var stringResult = body; 
      eventCallback(stringResult); 
     }); 
    }).on('error', function (e) { 
     console.log("Got error: ", e); 
    }); 
} 

START RequestId: 0c6d7a9b-4fcd-11e6-84e8-6b679452fe6e Version: $LATEST 
2016-07-22T05:27:58.039Z 0c6d7a9b-4fcd-11e6-84e8-6b679452fe6e session applicationId: amzn1.echo-sdk-ams.app.ef1f54cb-cabe-429b-b8a1-5a4090e5f937 
2016-07-22T05:27:58.040Z 0c6d7a9b-4fcd-11e6-84e8-6b679452fe6e vik::::::::::::: before service call 
2016-07-22T05:27:58.078Z 0c6d7a9b-4fcd-11e6-84e8-6b679452fe6e url to invoke is:https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&explaintext=&exsectionformat=plain&redirects=&titles=Jan_21 
END RequestId: 0c6d7a9b-4fcd-11e6-84e8-6b679452fe6e 
REPORT RequestId: 0c6d7a9b-4fcd-11e6-84e8-6b679452fe6e Duration: 398.63 ms Billed Duration: 400 ms Memory Size: 128 MB Max Memory Used: 17 MB 

のようなコンソールプリントは、私が間違っているのかわからないですし、どのようにそれを

+1

呼び出しは非同期で、データを返す前にラムダ関数が解決する可能性があります。私がやってみようとしていることの1つは、コールバック関数を使ってデータを返すことによって、どこかでラムダ関数を実際に終了させることです。さもなければ、ラムダがそれ自身で終了することが許されている場合、ラムダがどのように振る舞うかはわかりません。 http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html。 – master565

+0

ここに誰かがあなたがしようとしていることが成功しているhttp://stackoverflow.com/questions/28449363/why-is-this-http-request-not-working-on-aws-lambda – master565

+0

私は全くコンテキストを使用していない何をするにも。関係があるかどうかは分かりません。 – Vik

答えて

1

をデバッグすることが機能するようになりました。問題は、それを打ち上げの意図と応答カードの直後に置くことをテストすることでした。これはcontext.succeedを呼び出して、完了する前にそれを強制終了していました。

+0

あなたはそのコードをアップロードしてもよろしいですか? – probbins222

関連する問題