2017-07-25 97 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