Google Assistant SDK中的多个命令

时间:2018-05-15 13:02:00

标签: json google-assistant-sdk

我计划使用Google智能助理SDK实现2个自定义命令,并且我已在actions.json文件中进行了相应的更改(附件如下)。但是,某种程度上只有一个命令被触发,即随机启动或选择命令。如何让它触发两个命令?

{
 "manifest": {
    "displayName": "Start Test",
    "invocationName": "Start Test",
    "category": "PRODUCTIVITY"
},
"actions": [
    {
        "name": "com.example.actions.StartTest",
        "availability": {
            "deviceClasses": [
                {
                    "assistantSdkDevice": {}
                }
            ]
        },
        "intent": {
            "name": "com.example.intents.StartTest",
            "parameters": [
                {
                    "name": "testname",
                    "type" : "SchemaOrg_Number"
                }
            ],
            "trigger": {
                "queryPatterns": [
                    "prepare test ($SchemaOrg_Number:testname)"
                ]
            }
        },
        "fulfillment": {
            "staticFulfillment": {
                "templatedResponse": {
                    "items": [
                        {
                            "simpleResponse": {
                                "textToSpeech": "Preparing to start test $testname"
                            }
                        },
                        {
                            "deviceExecution": {
                                "command": "com.example.commands.StartTest",
                                "params": {
                                    "testname": "$testname"
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
],
"types": [
    {
        "name": "$testname",
        "entities": [
            {
                "key": "5",
                "synonyms": [
                    "Test5"
                ]
            }
        ]
    }
],

"manifest": {
    "displayName": "Select Lane",
    "invocationName": "Select Lane",
    "category": "PRODUCTIVITY"
},
"actions": [
    {
        "name": "com.example.actions.SelectLane",
        "availability": {
            "deviceClasses": [
                {
                    "assistantSdkDevice": {}
                }
            ]
        },
        "intent": {
            "name": "com.example.intents.SelectLane",
            "parameters": [
                {
                    "name": "lanename",
                    "type" : "SchemaOrg_Number"
                }
            ],
            "trigger": {
                "queryPatterns": [
                    "select lane ($SchemaOrg_Number:lanename)"
                ]
            }
        },
        "fulfillment": {
            "staticFulfillment": {
                "templatedResponse": {
                    "items": [
                        {
                            "simpleResponse": {
                                "textToSpeech": "Selected lane $lanename"
                            }
                        },
                        {
                            "deviceExecution": {
                                "command": "com.example.commands.SelectLane",
                                "params": {
                                    "lanename": "$lanename"
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
],
"types": [
    {
        "name": "$lanename",
        "entities": [
            {
                "key": "5",
                "synonyms": [
                    "Lane5"
                ]
            }
        ]
    }
]

}

1 个答案:

答案 0 :(得分:0)

您应该整合两个actions数组。该文件是一组键值,因此重复键意味着该值将替换前一个键:

"actions": [
  {
     "name": "com.example.action",
     // ...
  },
  {
     "name": "com.example.bction",
     // ...
  }
]

你应该对类型做同样的事情:

"types": [
  {
    "name": "$type",
    // ...
  },
  {
    "name": "$bype"
  }
]