【问题标题】:Send response to Dialogflow webhook向 Dialogflow webhook 发送响应
【发布时间】:2020-09-25 14:56:32
【问题描述】:

我正在尝试实现 Dialogflow 机器人。我已经设置了所有意图、为意图和 webhook 接收器控制器定义的响应。它运行良好,但基于 Fulfillment docs 在 Dialogflow 向我的 webhook 服务发出请求后,我需要向 Dialogflow 发送响应。该怎么做?

这是我的 webhook 服务:

class Api::V1::WebhooksController < ActionController::API
  include ActionController::HttpAuthentication::Basic::ControllerMethods
  include ActionController::HttpAuthentication::Token::ControllerMethods

  http_basic_authenticate_with name: Rails.application.credentials.webhook_auth_name, password: Rails.application.credentials.webhook_auth_password

  def create
    action_name = params[:webhook][:queryResult][:intent][:displayName]

    case action_name
    when 'get-calendar'
      render json: 'Show calendar', status: :ok
    when 'get-room'
      render json: 'Show available rooms', status: :ok
    end
  end
end

这给了我Raw interaction log 里面的信息:

{
  "queryText": "Calendar",
  "parameters": {},
  "fulfillmentText": "<happy>This is your calendar</happy>",
  "fulfillmentMessages": [
    {
      "text": {
        "text": [
          "<happy>This is your calendar</happy>"
        ]
      },
      "lang": "en"
    }
  ],
  "intent": {
    "id": "1234",
    "displayName": "get-calendar",
    "priority": 500000,
    "webhookState": "WEBHOOK_STATE_ENABLED",
    "messages": [
      {
        "text": {
          "text": [
            "<happy>This is your calendar</happy>"
          ]
        },
        "lang": "en"
      }
    ]
  },
  "intentDetectionConfidence": 1234,
  "diagnosticInfo": {
    "webhook_latency_ms": 1234
  },
  "languageCode": "en",
  "slotfillingMetadata": {
    "allRequiredParamsPresent": true
  },
  "id": "1234",
  "sessionId": "1234",
  "timestamp": "2020-09-25T14:38:31.92Z",
  "source": "agent",
  "webhookStatus": {
    "webhookEnabledForAgent": true,
    "webhookStatus": {
      "code": 3,
      "message": "Webhook call failed. Error: Failed to parse webhook JSON response: Expect message object but got: \"Show\"."
    }
  },
  "agentEnvironmentId": {
    "agentId": "1324",
    "cloudProjectId": "test-project"
  }
}

我不认为这部分是我所期望的:

  "message": "Webhook call failed. Error: Failed to parse webhook JSON response: Expect message object but got: \"Show\"."

【问题讨论】:

    标签: ruby-on-rails ruby dialogflow-es dialogflow-es-fulfillment


    【解决方案1】:

    DialogFlow 在处理 Intent 时调用您的 WebHook,您需要确保您的代码返回一个 DialogFlow 可以理解并可以处理的 JSON 对象。看起来您只是发回一条短信(显示日历),或者至少是一个以“显示..”开头的 JSON

    您正在使用 DialogFlow API v1(已弃用,最好移至 V2),因此您的 JSON should look like this。通常有 SDK(Java、NodeJS,我猜也是 Ruby?)提供模型和对象来使用,所以你不需要手动创建 JSON,只需使用 API。

    【讨论】:

      猜你喜欢
      • 2017-11-03
      • 1970-01-01
      • 1970-01-01
      • 2022-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      相关资源
      最近更新 更多