【问题标题】:How to send FulfillmentMessages as part of Dialogflow v2 WebhookResponse?如何将 FulfillmentMessages 作为 Dialogflow v2 WebhookResponse 的一部分发送?
【发布时间】:2018-10-22 09:27:58
【问题描述】:

我正在尝试将履行消息作为 Dialogflow 的 v2 API WebhookResponse 的一部分发回。

这行得通:

在我的回复中仅发送 FulfillmentText 可以正常工作(在 Google 模拟器上的操作中测试应用程序会回复正确的 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。

谁能指出我做错了什么的正确方向?

【问题讨论】:

    标签: go webhooks dialogflow-es actions-on-google google-assistant-sdk


    【解决方案1】:

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

    {
    "fulfillmentMessages": [
        {
            "text": {
                "text": [
                    "foo",
                    "bar"
                ]
            }
        }
    ],
    "fulfillmentText": "foobar",
    "source": "Test"
    }
    
    1. 消息在实际结构中不存在。
    2. fullfillment_text 应该是 fulfillmentText
    3. 外部文本应该是文本
    4. fullfillment_messages 应该是 fulfillmentMessages

    【讨论】:

      猜你喜欢
      • 2018-05-27
      • 2018-09-22
      • 1970-01-01
      • 2018-11-15
      • 2018-05-15
      • 2016-06-26
      • 1970-01-01
      • 2020-02-05
      • 2019-01-27
      相关资源
      最近更新 更多