1

i was trying history bluff example to invoke wikipedia service. i put the call in the on start message. i can see it is printing my message up to the point it hits the call stmt. but then it prints nothing in the console. the code looks like below:

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

The console prints like

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  

i am not sure what is wrong and how to debug it

johndoe
  • 4,387
  • 2
  • 25
  • 40
Vik
  • 8,721
  • 27
  • 83
  • 168
  • 1
    The call is asynchronous, and the lambda function is likely resolving before getting data back. One thing I would try doing is actually ending the lambda function somewhere by returning data using the callback function. Otherwise, I'm not sure how lambda will behave if it is allowed to end on its own. http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html. – master565 Jul 22 '16 at 18:34
  • Here is someone successful doing what you're trying http://stackoverflow.com/questions/28449363/why-is-this-http-request-not-working-on-aws-lambda – master565 Jul 22 '16 at 18:38
  • i am not using context at all to do anything. so not sure if it is relevant – Vik Jul 22 '16 at 19:44
  • @master565 looking at the link and the example picked from histroy bluff sample this should wait. but seems it is not. not sure why – Vik Jul 22 '16 at 20:04
  • The history buff sample uses some file AlexaSkill.js. I'm not really sure what that or if it was specific to the samples, and I have no idea how it works. If you're building off their samples, I'm sorry that I won't be able to help you. – master565 Jul 22 '16 at 21:17
  • that file i have it already. to take a look u can see it here https://www.dropbox.com/s/n61wss9td3mkbpp/AlexaSkill.js?dl=0 – Vik Jul 23 '16 at 00:26

1 Answers1

1

it works now. the problem was to test i put it in the launch intent and just after the response card. this was calling the context.succeed and killing it before it completes.

Vik
  • 8,721
  • 27
  • 83
  • 168