我正在尝试将实现消息作为Dialogflow v2 API WebhookResponse的一部分发回。
这有效:
仅发送FulfillmentText
作为响应的一部分就可以正常工作(在Google Simulator上的“ Actions”中测试应用程序,并使用正确的FulfillmentText
值):
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
的一部分,则测试失败:
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是错误的,因为它作为响应的一部分返回... Cannot find field: Message ...
。
我虽然使用了适用于Dialogflow的Golang SDK(https://godoc.org/google.golang.org/genproto/googleapis/cloud/dialogflow/v2#WebhookResponse)
这已在Google模拟器上的“动作”中进行了测试,并在Pixel 2上运行了实际的Google助手。
有人能指出正确的方向吗?
答案 0 :(得分:0)
正如您所说,问题在于响应的json结构。以下是有效的webhook响应
{
"fulfillmentMessages": [
{
"text": {
"text": [
"foo",
"bar"
]
}
}
],
"fulfillmentText": "foobar",
"source": "Test"
}