必须设置格式错误的响应 'final_response'

Malformed Response 'final_response' must be set

我正在使用 DialogFlow 的 webhook 东西,当我发送 JSON 响应时,如下所示:

{
  "fulfillmentText": "This is a text response",
  "source": "example.com",
  "payload": {
    "google": {
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "this is a simple response"
            }
          }
        ]
      }
    }
  }
}

但我在网络服务器响应后收到错误 MalformedResponse 'final_response' must be set.

如果您为意图启用了 Webhook,请确保添加行 'WebhookClient.add('This is a sample response') 因为当为意图启用 Webhook 时,它期望用户已设置webhook 意图中的一些响应 handler.Also 确保 add() 不在任何条件语句中,如 ifwhile

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
    const agent = new WebhookClient({request, response});
function webhookIntent(agent)
{
    //All your custom logics.
    //Ensure the below line is not inside any conditional statements 
    agent.add(`You should hear this response without any error!`);
}
}

如果您没有在 intent 中使用 webhook,请确保在 intent 中设置了默认响应。

希望对您有所帮助!

JSON 响应对 Dialogflow webhook 实现协议的 V2 有效。确保您已完成以下操作:

  1. 确保您已打开 V2 API。点击左上角的设置齿轮,点击V2API按钮。

  2. 确保已为 Webhook 的 URL 设置 Fulfillment,并且已针对要测试的 Intent 打开它。