【问题标题】:Send back rich responses to Actions on Google through Dialogflow webhook fulfillment通过 Dialogflow webhook 实现向 Actions on Google 发回丰富的响应
【发布时间】:2018-02-06 03:35:28
【问题描述】:

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

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

【问题讨论】:

    标签: webhooks actions-on-google dialogflow-es fulfillment


    【解决方案1】:

    使用 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

    【讨论】:

    • 注意,这仅适用于 V1 API。我是否可以假设 V2 还没有类似的功能?文档很少。
    • 您说的是 Dialogflow V1/V2 还是 Actions on Google V1/V2?
    • 我指的是Dialogflow V2
    • 你是对的!您应该坚持使用 Dialogflow V1,因为没有关于 Google 集成操作的 Dialogflow V2 响应的文档。
    【解决方案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 了解如何添加轮播、列表和建议筹码

    【讨论】:

      猜你喜欢
      • 2018-06-07
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 1970-01-01
      • 1970-01-01
      • 2018-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多