如何解决如何呈现从Webhook返回的列表
我正在使用Google Actions。我从Webhook返回JSON,并在模拟器中测试动作时收到以下错误:
“由于缺少插槽的类型覆盖而无法呈现列表或集合提示。请注意,列表和集合仅应在插槽填充中使用。应该有一个相应的类型替代,用于描述如何呈现列表或集合。这种类型。”
JSON是从https://developers.google.com/assistant/conversational/prompts-selection的文档中获取的经过稍微修改的示例。
typeOverrides名称“ items”与场景的插槽名称匹配。
这是webhook请求和响应JSON。
***请求***
{
"handler": {
"name": "aa"
},"intent": {
"name": "searchIntent","params": {
"searchParm": {
"original": "milk","resolved": "milk"
}
},"query": "milk"
},"scene": {
"name": "Start","slotFillingStatus": "UNSPECIFIED","slots": {},"next": {
"name": "SearchScene"
}
},"session": {
"id": "ABwppHGln0UTzfUPqJ1SMr1Cuw2TyPjJQoGUkULazcObus3vUwJCJCpba--5PSRwjqMQelRqMAUnwPvl","params": {},"typeOverrides": [],"languageCode": ""
},"user": {
"locale": "en-AU","accountLinkingStatus": "ACCOUNT_LINKING_STATUS_UNSPECIFIED","verificationStatus": "VERIFIED","packageEntitlements": [],"lastSeenTime": "2020-11-05T21:24:16Z"
},"home": {
"params": {}
},"device": {
"capabilities": [
"SPEECH","RICH_RESPONSE","LONG_FORM_AUdio"
]
}
}
***响应***
{
"session": {
"id": "ABwppHGln0UTzfUPqJ1SMr1Cuw2TyPjJQoGUkULazcObus3vUwJCJCpba--5PSRwjqMQelRqMAUnwPvl","typeOverrides": [
{
"name": "items","synonym": {
"entries": [
{
"name": "ITEM_1","synonyms": [
"Item 1","First item"
],"display": {
"title": "Item #1","description": "Description of Item #1","image": {
"alt": "Google Assistant logo","height": 0,"url": "https://developers.google.com/assistant/assistant_96.png","width": 0
}
}
},{
"name": "ITEM_2","synonyms": [
"Item 2","Second item"
],"display": {
"title": "Item #2","description": "Description of Item #2",{
"name": "ITEM_3","synonyms": [
"Item 3","Third item"
],"display": {
"title": "Item #3","description": "Description of Item #3",{
"name": "ITEM_4","synonyms": [
"Item 4","Fourth item"
],"display": {
"title": "Item #4","description": "Description of Item #4","width": 0
}
}
}
]
},"typeOverrideMode": "TYPE_REPLACE"
}
]
},"prompt": {
"override": false,"content": {
"list": {
"items": [
{
"key": "ITEM_1"
},{
"key": "ITEM_2"
},{
"key": "ITEM_3"
},{
"key": "ITEM_4"
}
],"subtitle": "List subtitle","title": "List title"
}
},"firstSimple": {
"speech": "This is a list.","text": "This is a list."
}
}
}
解决方法
TypeOverride 名称应该与插槽的 Type 相匹配,而不是插槽的 name 。
,我与大家分享解决方案。
的确,文档省略了某些部分来完成这项工作,但是如果我们注意阅读并紧随其后,它确实起作用。
一旦有了Actions Builder项目,我们要做的第一件事就是在类型部分中创建一个实体。就是这样,我们不需要添加输入或值,只需创建类型。
下一步是准备展示收藏的场景。在这种情况下,我创建了一个名为INTRO的文件。
这是您出现错误的地方。您试图在进入场景时在Webhook中显示触发的集合。不必在此放置任何东西,它必须是空的。
下一步是添加插槽类型和名称。我们还必须配置2件事,一是使该插槽成为必需项,二是激活该复选框,以便它调用负责绘制集合的处理程序。
如果您注意到,我将插槽命名为: type_option ,它的类型为 prompt_type ,即我在第一步中声明的类型。然后,我根据需要标记了该插槽,最后激活了它,以调用Webhook中名为 LaunchRequest 的处理程序。
现在让我们看一下代码。
const LaunchRequestHandler = app => {
app.handle('LaunchRequest',conv => {
conv.session.typeOverrides = [
{
name: 'prompt_option',// We reference the type of slot,not the name
mode: 'TYPE_REPLACE',synonym: {
entries: [
{
name: 'ITEM_1',synonyms: ['Item 1','First item'],display: {
title: 'Element 1',description: 'This is the element 1',image: new Image({
url: '<YOUR URL>',alt: 'example'
})
}
},{
name: 'ITEM_2',synonyms: ['Item 2','Second item'],display: {
title: 'Element 2',description: 'This is the element 2',alt: 'example 2'
})
}
}
]
}
}
];
const items = [{ key: 'ITEM_1' },{ key: 'ITEM_2' }]
conv.add(new Collection({ title: '<YOUR TITLE>',subtitle: '<YOUR SUBTITLE>',items }))
})
}
这是我们要呈现集合时被配置为调用的代码段。如果仔细观察,我们将引用类型而不是插槽名称。
如果我们从模拟器进行测试,那么一切都应该正常工作。一切都很完美。
希望我的帮助对您有帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。