【发布时间】:2018-05-15 18:30:45
【问题描述】:
我正在尝试构建一种调用 REST API 来获取数据的技能。我正在使用 HelloWorld 示例并对其进行修改以满足我的需要。我正在使用请求节点 (node.js) 来发出请求。
但是,对于我来说,我无法让它工作。我在日志中看到调用了该函数并且返回了正确的结果,但是发送给 Alexa 的响应是空的!!知道我缺少什么吗?
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
console.log("HelloWorldIntentHandler 1: ");
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
},
handle(handlerInput) {
console.log("HelloWorldIntentHandler 2");
var speechText = 'Hello World';
Request.get(url, function(error, response, body) {
console.log("I'm here")
var data = JSON.parse(body)
var result = data.records.totalNum
if (result > 0) {
speechText = "There are " + result + " matches";
} else {
speechText = "ERROR";
}
return handlerInput.responseBuilder
.speak(speechText)
.withSimpleCard('Hello World', speechText)
.getResponse();
});
},
};
日志中的错误是
Error handled: speechOutput.trim is not a function
【问题讨论】:
标签: alexa alexa-skills-kit alexa-skill