내가 만든 API와 내가 만든 API를 읽는 알렉사 스킬. API는 잘 작동하고 그대로 람다를 사용하여 Alexa 스킬에서 null 응답 받기
{
"_id": "5a4523104494060cf097c1ad",
"description": "Sprinting",
"date": "2017-12-29"
}
내가 다음 코드
'getNext': function() {
var url = '***API ADDRESS*** ';
var text = "The session will be";
https.get(url, function(response) {
var body = '';
response.on('data', function(x) {
body += x;
});
console.log("a" + text);
response.on('end', function() {
var json = JSON.parse(body);
text += json.description;
console.log("b" + text);
this.emit(":tell", text);
});
console.log("c " + text);
});
console.log("d" + text);
// this.emit(":tell", text);
}
콘솔 출력
2017-12-29T09:33:47.493Z dThe session will be
2017-12-29T09:33:47.951Z aThe session will be
2017-12-29T09:33:47.952Z c The session will be
2017-12-29T09:33:48.011Z bThe session will beSprinting
그러나 이것은 this.emit 기능에 대한 null을 반환 한 반환 .
다른 사람의 주석을 제거하고 주석을 제거하면 <speak> The session will be</speak>
이 반환됩니다.
나는 스코프와 관련이 있다고 생각하지만, 왜 텍스트가 로그 b에서는 정확하지만 d에서는 그렇지 않은지에 대해 생각할 수 없다. 내가이 울퉁불퉁 한 곳에서 this.emit을 사용할 수 없다면, 끝에서 사용할 정보를 거기에서 얻는 방법이 필요하다.