【问题标题】:alexa skill webservice call does not happenAlexa技能网络服务调用不会发生
【发布时间】:2016-11-25 22:00:31
【问题描述】:

我正在尝试历史虚张声势的例子来调用维基百科服务。我把电话放在开始消息中。我可以看到它正在打印我的消息,直到它到达呼叫 stmt。但随后它在控制台中不打印任何内容。代码如下:

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 自行结束,它将如何表现。 docs.aws.amazon.com/lambda/latest/dg/….
  • 这里有人成功地做你正在尝试的事情stackoverflow.com/questions/28449363/…
  • 我根本没有使用上下文来做任何事情。所以不确定它是否相关
  • @master565 查看链接和从 histroy bluff 样本中挑选的示例,这应该等待。但似乎不是。不知道为什么
  • 历史爱好者示例使用了一些文件 AlexaSkill.js。我不确定那是什么,或者它是否特定于样本,我也不知道它是如何工作的。如果您正在构建他们的样本,很抱歉我无法为您提供帮助。

标签: node.js aws-lambda alexa alexa-skills-kit


【解决方案1】:

现在可以了。问题是测试我把它放在启动意图中,就在响应卡之后。这是调用 context.succeed 并在它完成之前将其杀死。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-21
    • 2020-07-03
    • 2018-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多