我正在構建一項Alexa技能,告訴用戶最接近的Kaiser Permanente醫院,診所或藥房。當我測試使用三個關鍵字之一,我得到的錯誤:The response is invalid.
HTTP/HTTPS GET請求Alexa技巧 - 「響應無效」Lambda響應
給予無效(使用沒有這三個關鍵字)的反應給我的錯誤: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;
}
}
您可以檢查cloudwatch日誌以獲取有關lambda執行中出錯的更多詳細信息。 –