Google Action中ListSelect二次点击无法获取optionInfo的咨询
这个问题我之前也碰到过,核心原因是你在用户首次选择后返回的响应里,把actions.intent.OPTION从possibleIntents中移除了。Google Assistant会根据当前响应的possibleIntents来判断如何处理用户的下一次交互——当没有OPTION意图时,点击列表项会被当作普通文本输入,只返回标题内容,而不会传递optionInfo。
要让用户每次点击列表项都能获取到对应的optionInfo,你需要做到以下几点:
每次展示ListSelect时,必须保留OPTION意图:不管用户是首次选择还是滚动后再次选择,只要当前界面还展示着ListSelect组件,就需要在
possibleIntents中同时包含actions.intent.OPTION和actions.intent.TEXT。用户选择后,回复需重新包含ListSelect组件:如果希望用户继续和列表交互(比如滚动后选择其他项),不要只返回
SimpleResponse,应该在响应的richResponse里重新添加ListSelect组件,同时确保possibleIntents配置正确。
举个具体的响应示例,用户选择某一项后,你的webhook应该返回类似这样的结构:
{ "fulfillmentText": "You selected Item #1", "payload": { "google": { "expectUserResponse": true, "richResponse": { "items": [ { "simpleResponse": { "textToSpeech": "You selected Item #1" } }, { "listSelect": { "title": "Select an item", "items": [ { "optionInfo": { "key": "item_1" }, "title": "Item #1", "description": "Description 1" }, { "optionInfo": { "key": "item_2" }, "title": "Item #2", "description": "Description 2" }, { "optionInfo": { "key": "item_3" }, "title": "Item #3", "description": "Description 3" } ] } } ] }, "possibleIntents": [ { "intent": "actions.intent.OPTION", "inputValueData": { "listSelect": { "title": "Select an item", "items": [ { "optionInfo": { "key": "item_1" }, "title": "Item #1", "description": "Description 1" }, { "optionInfo": { "key": "item_2" }, "title": "Item #2", "description": "Description 2" }, { "optionInfo": { "key": "item_3" }, "title": "Item #3", "description": "Description 3" } ] }, "@type": "type.googleapis.com/google.actions.v2.OptionValueSpec" } }, { "intent": "actions.intent.TEXT" } ] } } }
- 确保
expectUserResponse设为true:这个参数告诉Google Assistant要等待用户的下一次交互,而不是直接结束对话,这样用户才能继续操作列表。
总结一下:只要ListSelect组件还在界面上,就必须让actions.intent.OPTION存在于possibleIntents中,这样Assistant才会把列表点击事件解析为OPTION意图,正确传递optionInfo给你的webhook。
内容的提问来源于stack exchange,提问作者oschwarzpdm

