我正在尝试将实现消息发送回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模拟器上的Actions上进行了测试,并在Pixel 2上运行了实际的Google Assistant。

有人能指出我正确的方向吗?

最佳答案

如您所说,问题在于响应的json结构。以下是有效的webhook响应

{
"fulfillmentMessages": [
    {
        "text": {
            "text": [
                "foo",
                "bar"
            ]
        }
    }
],
"fulfillmentText": "foobar",
"source": "Test"
}
  • 实际结构中不存在消息。
  • fullfillment_text应该为fillmentText
  • 外文字应为文字
  • fullfillment_messages应该被履行消息
  • 关于go - 如何在Dialogflow v2 Webhook响应中发送FulfillmentMessages?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52926138/

    10-12 07:38
    查看更多