简体   繁体   中英

HTTP / HTTPS GET Request Alexa Skill - “The Response is Invalid” Lambda Response

I am building an Alexa skill that tells a user the closest Kaiser Permanente hospital, clinic, or pharmacy. When I test using one of the three keywords, I get the error: The response is invalid.

Giving an invalid (using none of the three keywords) response gives me the error: The remote endpoint could not be called, or the response it returned was invalid.

I am at a loss as to how to figure out what or where the issue is, as I am not given any details about the issue.

 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; } } 

It's difficult to say what your problems is with what you've given. It could be an improperly uploaded Lambda function or your JSON response could be too big and thus hitting the response size limit. The best start to trouble shooting this problem is to look at your error logs in Cloudwatch and see what that says.

You can also try returning a simple, hardcoded string when the GET request returns to make sure everything up to that point is working correctly. Then replace the hardcoded string with data from the response.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM