如何呈现从 webhook 返回的列表 [英] How to render a list returned from a webhook

查看:13
本文介绍了如何呈现从 webhook 返回的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Google Actions.当我在模拟器中测试我的操作时,我从我的 webhook 返回 JSON 并收到以下错误:

<块引用>

"由于缺少插槽的类型覆盖,无法呈现列表或集合提示.注意,List 和 Collection 只能用于槽填充.应该有一个相应的类型覆盖来描述如何为这个类型呈现列表或集合."

JSON 是取自

解决方案

我和大家分享这个解决方案.

文档确实省略了某些部分来完成这项工作,但如果我们注意阅读并严格遵守它,它确实有效.

一旦我们有了 Actions Builder 项目,我们要做的第一件事就是在类型部分创建一个实体.就是这样,我们不需要添加输入或值,只需创建类型即可.

下一步是准备展示我们收藏的场景.在本例中,我创建了一个名为 INTRO.

这是您出错的地方.您正在尝试在进入场景时触发的 webhook 中显示集合.什么都不必放在那里,它必须是空的.

下一步是添加插槽类型和名称.我们还必须配置另外两件事情,一是使所述插槽成为强制性的,二是激活复选框,以便它调用我们负责绘制集合的处理程序.

如果您注意到,我将槽命名为:type_option,它的类型为 prompt_type,即我在第一步中声明的类型.然后我将那个插槽标记为需要,最后我激活它以调用我的 webhook 中名为 LaunchRequest 的处理程序.

现在让我们看看代码.

const LaunchRequestHandler = app =>{app.handle('LaunchRequest', conv => {conv.session.typeOverrides = [{name: 'prompt_option',//我们引用的是槽的类型,而不是名称模式:'TYPE_REPLACE',同义词:{条目: [{名称:'ITEM_1',同义词:['Item 1', 'First item'],展示: {title: '元素 1',description: '这是元素 1',图像:新图像({url: '<你的网址>',alt:'示例'})}},{名称:'ITEM_2',同义词:['Item 2', 'Second item'],展示: {title: '元素 2',description: '这是元素 2',图像:新图像({url: '<你的网址>',alt: '示例 2'})}}]}}];const items = [{ key: 'ITEM_1' }, { key: 'ITEM_2' }]conv.add(new Collection({ title: '<YOUR TITLE>', subtitle: '<YOUR SUBTITLE>', items }))})}

这是我们配置为在想要展示集合时调用的代码段.如果我们仔细观察,我们指的是类型而不是插槽的名称.

有了这个,如果我们从模拟器进行测试,一切都应该有效.一切都很完美.

希望我的帮助对您有所帮助.

I am using Google Actions. I am returning JSON from my webhook and receiving the following error when I test my action in the simulator:

"Failed to render List or Collection prompt because of missing Type Override for a slot. Note, List and Collection should only be used in slot filling. There should be a corresponding Type Override that describes how to render the List or Collection for this Type."

The JSON is a slightly modified sample taken from docs at https://developers.google.com/assistant/conversational/prompts-selection.

The typeOverrides name 'items' matches a slot name for the scene.

Here is the webhook request and the response JSON.

*** REQUEST ***

 {
  "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",
    "params": {},
    "accountLinkingStatus": "ACCOUNT_LINKING_STATUS_UNSPECIFIED",
    "verificationStatus": "VERIFIED",
    "packageEntitlements": [],
    "lastSeenTime": "2020-11-05T21:24:16Z"
  },
  "home": {
    "params": {}
  },
  "device": {
    "capabilities": [
      "SPEECH",
      "RICH_RESPONSE",
      "LONG_FORM_AUDIO"
    ]
  }
}

*** RESPONSE ***

{
  "session": {
    "id": "ABwppHGln0UTzfUPqJ1SMr1Cuw2TyPjJQoGUkULazcObus3vUwJCJCpba--5PSRwjqMQelRqMAUnwPvl",
    "params": {},
    "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",
                "image": {
                  "alt": "Google Assistant logo",
                  "height": 0,
                  "url": "https://developers.google.com/assistant/assistant_96.png",
                  "width": 0
                }
              }
            },
            {
              "name": "ITEM_3",
              "synonyms": [
                "Item 3",
                "Third item"
              ],
              "display": {
                "title": "Item #3",
                "description": "Description of Item #3",
                "image": {
                  "alt": "Google Assistant logo",
                  "height": 0,
                  "url": "https://developers.google.com/assistant/assistant_96.png",
                  "width": 0
                }
              }
            },
            {
              "name": "ITEM_4",
              "synonyms": [
                "Item 4",
                "Fourth item"
              ],
              "display": {
                "title": "Item #4",
                "description": "Description of Item #4",
                "image": {
                  "alt": "Google Assistant logo",
                  "height": 0,
                  "url": "https://developers.google.com/assistant/assistant_96.png",
                  "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."
    }
  }
}

解决方案

I share with all of you the solution for this.

It is true that the documentation omits certain parts to make this work, but if we pay attention to reading and following it to the letter it really works.

Once we have our Actions Builder project, the first thing we do is create an entity in the types section. Just that, we don't need to add inputs or values, just create the type.

The next step is to prepare the scene where we will show our collection. In this case I created one called INTRO.

This is where you have the error. You are trying to display the collection in the webhook that fires when you enter the scene. Nothing has to be placed there, it must be empty.

The next step is to add the slot type and a name. We must also configure 2 more things, one is to make said slot mandatory and the other is to activate the checkbox so that it calls our handler who is in charge of painting the collection.

If you notice, I named the slot: type_option and it is of type prompt_type, that is, the type I declared in the first step. Then I marked that slot as required and finally I activated it to call the handler named LaunchRequest that is in my webhook.

Now let's see the code.

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',
                image: new Image({
                  url: '<YOUR URL>',
                  alt: 'example 2'
                })
              }
            }
          ]
        }
      }
    ];

    const items = [{ key: 'ITEM_1' }, { key: 'ITEM_2' }]

    conv.add(new Collection({ title: '<YOUR TITLE>', subtitle: '<YOUR SUBTITLE>', items }))
  })
}

This is the piece of code that we configure to be called when we want to present the collection. If we look closely, we refer to the type not to the name of the slot.

With this, everything should work, if we do the test from the simulator. Everything is perfect.

I hope my help has served you well.

这篇关于如何呈现从 webhook 返回的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆