通过Dialogflow webhook履行发回对Google上的操作的丰富回复

时间:2018-02-06 03:35:29

标签: webhooks actions-on-google dialogflow fulfillment

要让Google智能助理向用户显示丰富的回复,必须为其提供example on the Actions on Google docs之类的回复。但是,由于我使用Dialogflow作为我的服务器和Google之间的中间方,我需要在我的webhook中提供some kind of response to Dialogflow来表明应该有丰富的响应。正如您从该链接中看到的那样,文档提到了如何向FB Messenger,Kik,LINE等发送丰富的响应,而不是Google智能助理。

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

enter image description here

2 个答案:

答案 0 :(得分:4)

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

{
    "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您还可以使用提供的Dialogflow集成方法来构建rich response

答案 1 :(得分:2)

如果你正在使用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

查看如何添加轮播,列表和建议芯片
相关问题