2017-07-25 165 views
0

我正在构建一项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; 
 
    } 
 
}

+0

您可以检查cloudwatch日志以获取有关lambda执行中出错的更多详细信息。 –

回答

0

这很难说是你给了什么什么你的问题。它可能是一个不正确的上传Lambda函数,或者您的JSON响应可能太大,从而达到响应大小限制。解决此问题的最佳方法是查看Cloudwatch中的错误日志,然后查看结果。

+0

嗨,安,什么是Cloudwatch,我该如何使用它来帮助我调试?我希望我能提供更多信息,但这是我通过亚马逊开发者控制台中的服务模拟器提供的所有信息。我希望他们能够提供更多的信息,而不仅仅是模糊的错误回应。还有什么我可以提供的,可能有帮助吗? – Mike

+0

JSON响应非常大,但是,我不知道限制是什么。另外,在我的'getJSON()'函数中,我只抓取了一个字符串'title',如'var result = d.list [0] .contents.title;' – Mike

+0

'这行所示:cloudwatch是aws特定的监控仪表板:aws.amazon.com/cloudwatch。一旦您登录并转到左侧导航栏中的“日志”,您应该会看到您的技能日志。通常在这里有更多关于你为什么会出错的信息。就响应大小而言(这是您的技能响应,不像来自API调用的JSON响应),限制为24576个字节。 –

0

当GET请求返回时,您也可以尝试返回一个简单的硬编码字符串,以确保到达该点的所有内容都能正常工作。然后用响应中的数据替换硬编码的字符串。

+0

我明白你的意思了。我会尝试的。我的其他理论是,它是一个内部网站,Alexa试图从外部访问或返回的JSON对象太大。 – Mike