我正在尝试实现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\"."
发布于 2020-10-02 19:37:20
当处理一个意图时,DialogFlow调用你的WebHook,你需要确保你的代码发回一个DialogFlow能够理解和处理的JSON对象。看起来您只是返回了一条文本消息(Show Calendar),或者至少是一个以“Show..”开头的JSON。
您正在使用JSON v1 (已弃用,最好转移到V2),因此您的DialogFlow should look like this。通常有SDK (Java,NodeJS,我猜也有Ruby?)它提供了要使用的模型和对象,因此您不需要手动创建JSON,只需使用API即可。
https://stackoverflow.com/questions/64066585
复制