1
我正在嘗試歷史虛張聲勢的示例來調用維基百科服務。我把這個電話放在開始信息上。我可以看到它正在打印我的消息,直到它打到呼叫站點。但隨後它在控制檯中不打印任何東西。代碼如下所示:alexa技能web服務調用不會發生
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
我不知道什麼是錯的,如何調試它
該調用是異步的,並且在返回數據之前可能會解析lambda函數。我會嘗試做的一件事是實際上通過使用回調函數返回數據來結束lambda函數。否則,我不確定如果允許lambda自行結束,lambda表現如何。 http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html。 – master565
這裏有人成功地做你在做什麼http://stackoverflow.com/questions/28449363/why-is-this-http-request-not-working-on-aws-lambda – master565
我根本沒有使用上下文做任何事。所以不知道它是否相關 – Vik