【问题标题】:HTTP / HTTPS GET Request Alexa Skill - "The Response is Invalid" Lambda ResponseHTTP / HTTPS GET 请求 Alexa 技能 - “响应无效” Lambda 响应
【发布时间】:2017-07-27 20:05:01
【问题描述】:

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

【问题讨论】:

  • 您可以查看 cloudwatch 日志以获取有关 lambda 执行中出现问题的更多详细信息。

标签: node.js amazon-web-services aws-lambda alexa-skills-kit


【解决方案1】:

很难说你的问题是你所给予的。可能是上传的 Lambda 函数不正确,或者您的 JSON 响应可能太大,从而达到响应大小限制。解决此问题的最佳方法是查看 Cloudwatch 中的错误日志并查看其内容。

【讨论】:

  • 嗨,Ann,什么是 Cloudwatch,如何使用它来帮助我调试?我希望我能提供更多信息,但这是我通过 Amazon Dev Console 的服务模拟器提供的所有信息。我希望他们能提供更多信息,而不仅仅是模糊的错误响应。还有什么我可以提供的可以帮助的吗?
  • JSON 响应很大,但是不知道限制是多少。另外,在我的getJSON()函数中,我只抓取了一个字符串,title,var result = d.list[0].contents.title;一行所示
  • cloudwatch 是一个特定于 aws 的监控仪表板:aws.amazon.com/cloudwatch‎。登录并转到左侧导航中的“日志”后,您应该会看到您的技能日志。通常这里有更多关于你为什么出错的信息。就响应大小而言(这是您的技能响应,不像来自 API 调用的 JSON 响应),限制为 24576 字节。
【解决方案2】:

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

【讨论】:

  • 我明白你在说什么。我会试试的。我的其他理论是它是 Alexa 试图从外部访问的内部网站,或者 JSON 返回的对象太大。
猜你喜欢
  • 1970-01-01
  • 2020-07-23
  • 2018-09-24
  • 2021-08-28
  • 1970-01-01
  • 2019-01-23
  • 2018-06-09
  • 2019-11-12
  • 1970-01-01
相关资源
最近更新 更多