函数 ical.fromURL 不工作 AWS Lambda
Function ical.fromURL not working AWS Lambda
我正在处理 Alexa 技能可以使用的 Lambda 函数。我想要的只是一些简单的东西,可以读取事件并将信息发送回用户。为此,我使用 npm 库 ical.js https://www.npmjs.com/package/ical 和函数 ical.fromURL(url, options, function(err, data) {} ) 但问题是该函数永远不会执行。我有以下代码:
var Alexa = require("alexa-sdk");
var ical = require("ical");
var test = "This is a simple test 1";
exports.handler = function(event, context) {
var alexa = Alexa.handler(event, context);
alexa.registerHandlers(handlers);
alexa.execute();
};
var handlers = {
'LaunchRequest':function() {
console.log(test);
ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function(err, data) {
test = "Nothing changes";
});
console.log(test);
test.emit(':tell', 'I am done');
}
};
这是我在 ASK CLI output on cloudwatch as you can see the test text doesn't change, and would work if it was outside of the function(err, data){}. I don't believe there are any problems with reading in the calendar as the link http://lanyrd.com/topics/nodejs/nodejs.ics downloads a working ics file. The function activates if I try it in the https://npm.runkit.com/ical 工具中执行 "ask simulate -l en-US -t 'start calendar read'" 时从 could watch 得到的输出。所以我不确定我做错了什么。在 alexa 技能套件开发中测试时,技能作品也会给出响应。
您打错了 test.emit(':tell', 'I am done');
而不是 this.emit(':tell', 'I am done');
。
您的代码也不会 return 来自 url 的数据,因为 this.emit
将首先 return 而不是您的回调函数。为了return数据,需要把this.emit
放在ical.fromURL
的回调函数里面。
var handlers = {
'LaunchRequest':function() {
console.log(test);
ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, (err, data) => {
test = "Nothing changes";
console.log(test);
// you can edit the response here base on the data you receive.
this.emit(':tell', `I am done: ${test}`);
});
}
};
我正在处理 Alexa 技能可以使用的 Lambda 函数。我想要的只是一些简单的东西,可以读取事件并将信息发送回用户。为此,我使用 npm 库 ical.js https://www.npmjs.com/package/ical 和函数 ical.fromURL(url, options, function(err, data) {} ) 但问题是该函数永远不会执行。我有以下代码:
var Alexa = require("alexa-sdk");
var ical = require("ical");
var test = "This is a simple test 1";
exports.handler = function(event, context) {
var alexa = Alexa.handler(event, context);
alexa.registerHandlers(handlers);
alexa.execute();
};
var handlers = {
'LaunchRequest':function() {
console.log(test);
ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function(err, data) {
test = "Nothing changes";
});
console.log(test);
test.emit(':tell', 'I am done');
}
};
这是我在 ASK CLI output on cloudwatch as you can see the test text doesn't change, and would work if it was outside of the function(err, data){}. I don't believe there are any problems with reading in the calendar as the link http://lanyrd.com/topics/nodejs/nodejs.ics downloads a working ics file. The function activates if I try it in the https://npm.runkit.com/ical 工具中执行 "ask simulate -l en-US -t 'start calendar read'" 时从 could watch 得到的输出。所以我不确定我做错了什么。在 alexa 技能套件开发中测试时,技能作品也会给出响应。
您打错了 test.emit(':tell', 'I am done');
而不是 this.emit(':tell', 'I am done');
。
您的代码也不会 return 来自 url 的数据,因为 this.emit
将首先 return 而不是您的回调函数。为了return数据,需要把this.emit
放在ical.fromURL
的回调函数里面。
var handlers = {
'LaunchRequest':function() {
console.log(test);
ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, (err, data) => {
test = "Nothing changes";
console.log(test);
// you can edit the response here base on the data you receive.
this.emit(':tell', `I am done: ${test}`);
});
}
};