dongruidian3064 2018-10-22 09:27
浏览 63

如何在Dialogflow v2 WebhookResponse中发送FulfillmentMessages?

I'm trying to send back fulfillment messages as part of Dialogflow's v2 API WebhookResponse.

This works:

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)
}

The JSON being sent back:

{"fulfillment_text":"foobar"}

The response in the Simulator:

{
    "conversationToken": "[]",
    "finalResponse": {
    "richResponse": {
        "items": [
            {
                "simpleResponse": {
                    "textToSpeech": "foobar"
                }
            }
        ]
    }
},
    "responseMetadata": {
    "status": {
        "message": "Success (200)"
    },
    "queryMatchInfo": {
        "queryMatched": true,
            "intent": "24db2044-f2fb-4607-9897-1de757990622"
    }
}
}

This doesn't:

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)
}

The JSON being sent back:

{
    "fulfillment_text":"foobar",
    "fulfillment_messages":[
        {
            "Message":{
                "Text":{
                    "text":[
                        "foo",
                        "bar"
                    ]
                }
            }
        }
    ]
}

The response in the Simulator:

{
    "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\"}"
            }
        ]
    }
}
}

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)

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?

  • 写回答

1条回答 默认 最新

  • dqhgjay5753 2018-10-22 09:44
    关注

    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"
    }
    
    1. Messages is not present in the actual structure.
    2. fullfillment_text should be fulfillmentText
    3. Outer Text should be text
    4. fullfillment_messages should be fulfillmentMessages
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制