如何通过API.AI发送轮播?

时间:2017-08-09 18:06:29

标签: json webhooks dialogflow actions-on-google

我的机器人希望通过API.AI向Google智能助理发送轮播。我的理解是,我需要将其括在data - >内。 google,例如:

{
    "data": {
        "google": {
            "expectUserResponse": true,
            "isSsml": false,
            "expectedInputs": [
                {
                    "inputPrompt": {
                        "richInitialPrompt": {
                            "items": [
                                {
                                    "simpleResponse": {
                                        "textToSpeech": "Hello World"
                                    }
                                }
                            ]
                        }
                    },
                    "possibleIntents": [
                        {
                            "intent": "actions.intent.OPTION",
                            "inputValueData": {
                                "@type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
                                "carouselSelect": {
                                    "items": [
                                        {
                                          "optionInfo": {"key": "FOO", "synonyms": ["foo"]},
                                          "title": "Foo",
                                          "image": {"url": "http://example.com/", "accessibilityText": "Foo"}
                                        },
                                        {
                                            "optionInfo": {"key": "BAR", "synonyms": ["bar"]},
                                            "title": "Bar",
                                            "image": {"url": "http://example.com/", "accessibilityText": "Bar"}
                                        }
                                    ]
                                }
                            }
                        }
                    ]
                }
            ]
        }
    }
}

但它不起作用。什么是正确的格式?

1 个答案:

答案 0 :(得分:2)

如果您通过模拟器进行测试,则应该出现一个验证错误,该错误会给您至少一些关于缺失的指导。如果你甚至没有得到它,除data.google对象之外的其他部分可能存在问题,因此api.ai有问题。

有许多事情一目了然,可能是问题所在。你不能只是在api.ai响应中坚持一个对话webhook响应。有关文档,请参阅https://developers.google.com/actions/apiai/webhook#response,但这里有一些我认为可能存在问题的内容

  • expectedInputs属性不应该存在。
  • 您的data.google.expectedInputs.possibleIntents媒体资源应为data.google.systemIntent
  • 您仍需要提供api.ai字段,例如基本speech属性
  • data.google.expectedInputs.inputPrompt.richInitialPrompt位于data.google.richResponse

以下是一些适用于我的JSON:


{
    "speech": "Hello",
    "contextOut": [
        {
            "name": "_actions_on_google_",
            "lifespan": 100,
            "parameters": {}
        }
    ],
    "data": {
        "google": {
            "expectUserResponse": true,
            "richResponse": {
                "items": [
                    {
                        "simpleResponse": {
                            "textToSpeech": "Hello"
                        }
                    }
                ],
                "suggestions": []
            },
            "systemIntent": {
                "intent": "actions.intent.OPTION",
                "data": {
                    "@type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
                    "carouselSelect": {
                        "items": [
                            {
                                "title": "Foo",
                                "image": {
                                    "url": "http://example.com/foo.jpg",
                                    "accessibilityText": "Foo title"
                                },
                                "optionInfo": {
                                    "key": "foo-key",
                                    "synonyms": [
                                        "foo-alt-1",
                                        "foo-alt-2"
                                    ]
                                }
                            },
                            {
                                "title": "Bar",
                                "image": {
                                    "url": "http://example.com/bar.jpg",
                                    "accessibilityText": "Bar title"
                                },
                                "optionInfo": {
                                    "key": "bar-key",
                                    "synonyms": [
                                        "bar-alt-1",
                                        "bar-alt-2"
                                    ]
                                }
                            }
                        ]
                    }
                }
            }
        }
    }
}