问题描述
我正在尝试将实现消息作为Dialogflow v2 API WebhookResponse的一部分发送回去。
I'm trying to send back fulfillment messages as part of Dialogflow's v2 API WebhookResponse.
这可行:
仅发送 FulfillmentText
作为我的响应的一部分就可以正常工作(在 Google模拟器上的操作中测试应用,并以正确的 FulfillmentText
value):
Sending only a FulfillmentText
as part of my response works fine (Testing the app in the Actions on Google Simulator replies with the proper FulfillmentText
value) :
func random(c *gin.Context, wr dialogflow.WebhookRequest) {
log.Println("Random action detected")
fullfillment := dialogflow.WebhookResponse{
FulfillmentText: "foobar",
}
c.JSON(http.StatusOK, fullfillment)
}
返回的JSON:
{"fulfillment_text":"foobar"}
模拟器中的响应:
{
"conversationToken": "[]",
"finalResponse": {
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "foobar"
}
}
]
}
},
"responseMetadata": {
"status": {
"message": "Success (200)"
},
"queryMatchInfo": {
"queryMatched": true,
"intent": "24db2044-f2fb-4607-9897-1de757990622"
}
}
}
这不是:
但是我尝试发回任何实际消息(文本消息,基本卡,简单响应等)作为 FulfillmentMessages
的一部分,则测试失败:
But as soon as I try to send back any actual messages (Text Message, Basic Card, Simple Response, etc.) as part of FulfillmentMessages
, the test fails:
func random(c *gin.Context, wr dialogflow.WebhookRequest) {
log.Println("Random action detected")
textMessage := dialogflow.Intent_Message_Text{
Text: []string{"foo", "bar"},
}
fullfillment := dialogflow.WebhookResponse{
FulfillmentText: "foobar",
FulfillmentMessages: []*dialogflow.Intent_Message{
{
Message: &dialogflow.Intent_Message_Text_{
Text: &textMessage,
},
},
},
}
c.JSON(http.StatusOK, fullfillment)
}
正在发送回JSON:
{
"fulfillment_text":"foobar",
"fulfillment_messages":[
{
"Message":{
"Text":{
"text":[
"foo",
"bar"
]
}
}
}
]
}
模拟器中的响应:
{
"responseMetadata": {
"status": {
"code": 10,
"message": "Failed to parse Dialogflow response into AppResponse because of empty speech response",
"details": [
{
"@type": "type.googleapis.com/google.protobuf.Value",
"value": "{\"id\":\"917d8ac3-3f0f-4953-b556-4dec27b8bbb8\",\"timestamp\":\"2018-10-22T09:00:45.488Z\",\"lang\":\"en-us\",\"result\":{},\"alternateResult\":{},\"status\":{\"code\":206,\"errorType\":\"partial_content\",\"errorDetails\":\"Webhook call failed. Error: Failed to parse webhook JSON response: Cannot find field: Message in message google.cloud.dialogflow.v2.Intent.Message.\"},\"sessionId\":\"ABwppHHSbrqOCPRp_DAPDLepL6YjSNpbzQ61CIBDTMl99rtRqfaWq-y0HtExb1--k6bcaL4CACQMeiVF3p-x5qk\"}"
}
]
}
}
}
我假设我的Web服务发送回的JSON错误,因为它返回 ...找不到字段:Message ...
作为其响应的一部分。
我正在为Dialogflow使用正确的Golang SDK()
I am assuming that the JSON that my web service sends back is wrong, since it returns ... Cannot find field: Message ...
as part of its response.I am using the proper Golang SDK for Dialogflow though (https://godoc.org/google.golang.org/genproto/googleapis/cloud/dialogflow/v2#WebhookResponse)
这是在Google模拟器上的Actions上进行了测试,以及在Pixel 2上运行了实际的Google Assistant。
This was tested on Actions on Google's Simulator as well as running the actual Google Assistant on a Pixel 2.
有人能指出我正确的方向吗?
Can anybody point me in the right direction what I am doing wrong?
推荐答案
正如您所说,问题出在响应的json结构上。以下是有效的webhook响应
As you said, the issue is with the json structure of the response. Below is a working webhook response
{
"fulfillmentMessages": [
{
"text": {
"text": [
"foo",
"bar"
]
}
}
],
"fulfillmentText": "foobar",
"source": "Test"
}
- 消息在实际结构中不存在。
- fullfillment_text 应该是 fulfillmentText
- 外部 Text 应该是 text
- fullfillment_messages 应该是 fulfillmentMessages
- Messages is not present in the actual structure.
- fullfillment_text should be fulfillmentText
- Outer Text should be text
- fullfillment_messages should be fulfillmentMessages
这篇关于如何在Dialogflow v2 WebhookResponse中发送FulfillmentMessages?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!