Webhook调用失败 - 预计BEGIN_OBJECT但是在第1行第1列路径为STRING $

时间:2018-03-20 14:57:27

标签: java php heroku webhooks dialogflow

我正在使用DIalogflow(api.ai)来创建聊天界面。就目前而言,我只有一个名为“姓名”的简单意图,例如“谁是约翰?”它回应'约翰是'。关于Dialoglow这个问题的json输出如下:

{
  "id": "my_project_id",
  "timestamp": "2018-03-20T14:41:02.561Z",
  "lang": "en",
  "result": {
    "source": "agent",
    "resolvedQuery": "Who is John",
    "action": "",
    "actionIncomplete": false,
    "parameters": {
      "given-name": "John"
    },
    "contexts": [],
    "metadata": {
      "intentId": "0fb73421-0d19-4a09-b7e9-1e767041547f",
      "webhookUsed": "true",
      "webhookForSlotFillingUsed": "false",
      "webhookResponseTime": 2224,
      "intentName": "Identity"
    },
    "fulfillment": {
      "speech": "John is a",
      "messages": [
        {
          "type": 0,
          "speech": "John is a"
        }
      ]
    },
    "score": 1
  },
  "status": {
    "code": 206,
    "errorType": "partial_content",
    "errorDetails": "Webhook call failed. Error: Failed to parse webhook JSON response: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $.",
    "webhookTimedOut": false
  },
  "sessionId": "491d57cb-0af2-45ac-a658-9e47ec6658ce",
  "alternativeResultsFromKnowledgeService": {}
}

我在Dialogflow中创建了一个webhook到一个简单的应用程序,其中包含部署在Heroku上的php脚本,以便更改问题的答案,例如: '谁是约翰'。 我的PHP脚本在Heroku上打印以下答案:

{"speech":"This is a too personal question.","displayText":"This is a too personal question.","source":"webhook"}

但是正如您在Dialogflow上面的json输出中看到的那样,我收到以下错误:

"Webhook call failed. Error: Failed to parse webhook JSON response: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $."

这就是为什么webhook不起作用的原因,我无法从Heroku上的php脚本回到Dialogflow来检索答案('这是一个太个人的问题')。

为什么我收到此错误,因为我的输出是有效的json输出?

1 个答案:

答案 0 :(得分:0)

试试 API 是否真的是 JSON 模式。 要对此进行测试,您可以在 apitester.com 之类的页面上进行设置,然后查看 JSON 的请求或响应。​​