我正在 Build 一个Alexa技能,告诉用户最近的Kaiser Permanente医院,诊所或药房 . 当我使用三个关键字之一进行测试时,出现错误: The response is invalid.
给出无效(不使用三个关键字)响应会给出错误: The remote endpoint could not be called, or the response it returned was invalid.
我不知道如何弄清问题是什么或在哪里,因为我没有得到关于这个问题的任何细节 .
function getWelcomeResponse(callback) {
var speechOutput = "Welcome to the Kaiser Permanente Alexa Skill. Allow me to help you find the nearest Kaiser hospital, pharmacy, or clinic.";
var reprompt = "Would you like me to help you find the nearest Kaiser hospital, pharmacy, or clinic?";
var header = "Kaiser Permanente Skill";
var shouldEndSession = false;
var sessionAttributes = {
"speechOutput" : speechOutput,
"repromptText" : reprompt,
};
callback(sessionAttributes, buildSpeechletResponse(header, speechOutput, reprompt, shouldEndSession));
}
function handleGetKaiserBuildingIntent(intent, session, callback) {
var buildingType = intent.slots.Building.value.toLowerCase();
var speechOutput = "We have an error fam.";
if (buildingType != BLDG_TYPE.PHARMACY ||
buildingType != BLDG_TYPE.CLINIC ||
buildingType != BLDG_TYPE.HOSPITAL) {
speechOutput = "Please try again. I can help you find the nearest Kaiser hospital, clinic, or pharmacy.";
var repromptText = "Please try again. I can help you find the nearest Kaiser hospital, clinic, or pharmacy.";
var header = "Error fam.";
} else {
getJSON(function(data) {
if (data != "ERROR") {
speechOutput = data;
}
callback(session.attributes, buildSpeechletResponseWithoutCard(speechOutput, "", true));
}, buildingType);
}
}
function getJSON(callback, building) {
request.get(url(building), function(error, response, body) {
var d = JSON.parse(body);
var result = d.list[0].contents.title;
if (result != null) {
callback(result);
} else {
callback("ERROR");
}
});
}
function url(building) {
switch (building) {
case BLDG_TYPE.HOSPITAL:
return "http://xjzxdss0040x.dta.kp.org/search/cgi-bin/query-meta?v%3Aproject=kp-mg-facdir-project&v:sources=kp-mg-facdir-proximity&query=hospital&user_lat=37.928243&user_lon=-121.9700594&render.function=json-feed-display-brief&content-type=application-json";
break;
case BLDG_TYPE.PHARMACY:
return "http://xjzxdss0040x.dta.kp.org/search/cgi-bin/query-meta?v%3Aproject=kp-mg-facdir-project&v:sources=kp-mg-facdir-proximity&query=pharmacy&user_lat=37.928243&user_lon=-121.9700594&render.function=json-feed-display-brief&content-type=application-json";
break;
case BLDG_TYPE.CLINIC:
return "http://xjzxdss0040x.dta.kp.org/search/cgi-bin/query-meta?v%3Aproject=kp-mg-facdir-project&v:sources=kp-mg-facdir-proximity&query=clinic&user_lat=37.928243&user_lon=-121.9700594&render.function=json-feed-display-brief&content-type=application-json";
break;
default:
break;
}
}
2 回答
你很难说你的问题是什么 . 它可能是一个不正确上传的Lambda函数,或者您的JSON响应可能太大,因此达到了响应大小限制 . 解决此问题的最佳方法是查看Cloudwatch中的错误日志,看看它的内容 .
您还可以尝试在GET请求返回时返回一个简单的硬编码字符串,以确保到目前为止的所有内容都能正常工作 . 然后用响应中的数据替换硬编码字符串 .