通过 Dialogflow webhook fulfillment 发回对 Google 上的操作的丰富响应

Send back rich responses to Actions on Google through Dialogflow webhook fulfillment

要让 Google 助手向用户显示丰富的响应,必须在我的 webhook 中为其提供类似于 example on the Actions on Google docs. However, since I'm using Dialogflow as the intermediary party between my server and Google's, I need to provide some kind of response to Dialogflow 的响应,以指示应该有丰富的响应。正如您从 link 中看到的那样,文档提到了如何向 FB Messenger、Kik、LINE 等发送丰富的回复,但没有提到 Google Assistant。

我在这里错过了什么?我在 Dialogflow Web 控制台中看到了丰富响应的选项,但我似乎只能输入没有来自服务器的动态数据的硬编码响应。正确的做法是什么?

使用 Dialogflow 集成,JSON 您的 webhook 应该 return 获得丰富响应的响应如下所示:

{
    "data":{
        "google":{
            "expectUserResponse":true,
            "noInputPrompts":[

            ],
            "richResponse":{
                "items":[
                    {
                        "simpleResponse":{
                            "textToSpeech":"Welcome to this Basic Card",
                            "displayText":"Welcome to this Basic Card"
                        }
                    },
                    {
                        "basicCard":{
                            "buttons":[
                                {
                                    "title":"Button Title",
                                    "openUrlAction":{
                                        "url":"https://some.url"
                                    }
                                }
                            ],
                            "formattedText":"Some text",
                            "image":{
                                "url":"http://some_image.jpg",
                                "accessibilityText":"Accessibility text describing the image"
                            },
                            "title":"Card Title"
                        }
                    }
                ],
                "suggestions":[
                    {
                        "title":"Aléatoire"
                    },
                    {
                        "title":"Top"
                    }
                ]
            }
        }
    }
}

如果您使用的是Node.js library You can also use the provided methods for Dialogflow integration to build your rich response

如果您使用 Node.js,您应该调用方法 buildRichResponse(),然后将项目添加为该对象的子对象,如下所示:

app.ask(app.buildRichResponse()
.addSimpleResponse('A text to be spoken')
.addBasicCard(app.buildBasicCard('Some text to be displayed')
  .setTitle('A title')
  .addButton('Read more', 'https://example.google.com/something')
  .setImage('https://example.google.com/image.png', 'Image alternate text')
  .setImageDisplay('CROPPED')
  )
);

这是一个添加 BasicCard 的示例,您可以在 https://developers.google.com/actions/assistant/responses#rich-responses

查看如何添加 Carousels、Lists 和 Suggestions Chips