Google 操作 - 从轮播中打开 Link

Google Actions - Open Link from carousel

我正在为我的 Google 操作使用 google 操作 node.js SDK。

有时,我会向用户展示一个带有项目列表的旋转木马:

var responseText = utils.getResponseText(Response.BUY_PRODUCTS);
var items = self._getProductSuggestItems(); //each item has am item key
self.assistant.askWithCarousel(responseText, self.assistant.getIncomingCarousel().addItems(items));

我收到了回复,并且我设法通过

获得了商品代码
var itemKey = assistant.getContextArgument('actions_intent_option', 'OPTION');

现在我想打开浏览器并将用户重定向到匹配的产品页面。 我如何实现这一目标?

您可以向用户提供您的 URL:https://developers.google.com/actions/reference/nodejs/RichResponse 您应该使用:addSuggestionLink

但是,您首先要确定表面是什么(您在 JSON obj 中获得此信息)并且 return 它仅适用于有屏幕的情况。

目前,AoG 不支持轮播或列表的外部 link, 你只能为每个项目保留一个密钥。

虽然有一种方法可以解决这个问题:

  • 向意图生成添加输出上下文(例如,caro_link) 轮播。
  • 使用事件 actions_intent_OPTION输入上下文 回退意图 caro_link
  • 现在,使用后备意图,使用卡片或建议链接或其他方式检查从轮播传递的 key 和 return 您产品的 link。

如果我明白你想做什么,我做了类似的事情:

  1. 有意生成轮播
  2. 创建一个包含事件的意图:actions_intent_OPTION
  3. 此意图通过以下方式访问轮播: const param = app.getSelectedOption()
  4. 您创建了一张带有链接到该产品页面的按钮的卡片。

Google 最近为此功能引入了浏览轮播卡片。

Link

下面是浏览轮播卡片的消息对象格式。

"fulfillment": {
  "speech": " Here is what we got for you.",
  "messages": [
    {
      "type": "simple_response",
      "platform": "google",
      "textToSpeech": " Here is what we got for you."
    },
    {
      "items": [
        {
          "description": "at price of Rs. 57,999",
          "title": "Apple MacBook Air Core i5 5th Gen - (8 GB/128 GB SSD/Mac OS Sierra) MQD32HN/A A1466",
          "footer": "Apple MacBook Air Core i5 5th Gen - (8 GB/128 GB SSD/Mac OS Sierra) MQD32HN/A A1466",
          "image": {
            "url": "https://rukminim1.flixcart.com/image/200/200/j4irlow0/computer/j/8/c/apple-na-notebook-original-imaevdrcvuksg2zv.jpeg?q=90",
            "accessibilityText": "Apple MacBook Air Core i5 5th Gen - (8 GB/128 GB SSD/Mac OS Sierra) MQD32HN/A A1466"
          },
          "openUrlAction": {
            "url": "https://dl.flipkart.com/dl/apple-macbook-air-core-i5-5th-gen-8-gb-128-gb-ssd-mac-os-sierra-mqd32hn-a/p/itmevcpqqhf6azn3?pid=COMEVCPQBXBDFJ8C&affid=HotDeals20&affExtParam2=pricee-desktop-search-21"
          }
        },
        {
          "description": "at price of Rs. 89,990",
          "title": "Apple Macbook PRO MPXQ2/R2 Core i5 (6th Gen)/8 GB/128 GB/33.78 cm (13.3)/Mac OS)",
          "footer": "Apple Macbook PRO MPXQ2/R2 Core i5 (6th Gen)/8 GB/128 GB/33.78 cm (13.3)/Mac OS)",
          "image": {
            "url": "https://assetscdn.paytm.com/images/catalog/product/L/LA/LAPAPPLE-MACBOOROSE73954D5B64792/1.jpg",
            "accessibilityText": "Apple Macbook PRO MPXQ2/R2 Core i5 (6th Gen)/8 GB/128 GB/33.78 cm (13.3)/Mac OS)"
          },
          "openUrlAction": {
            "url": "https://paytmmall.com/apple-macbook-pro-mpxq2-r2-core-i5-6th-gen-8-gb-128-gb-33-78-cm-13-3-mac-os-CMPLXLAPAPPLE-MACBOODUMM202563C836CCA-pdp?product_id=145129487&discoverability=online&src=grid&utm_source=NDTV&utm_medium=affiliate&utm_campaign=NDTV-recharge&utm_term=Gadget360"
          }
        },
        {
          "description": "at price of Rs. 105,185",
          "title": "Apple MPXT2HN/A Core i5 (6th Gen)/8 GB/256 GB/33.78 cm (13.3)/Mac OS)",
          "footer": "Apple MPXT2HN/A Core i5 (6th Gen)/8 GB/256 GB/33.78 cm (13.3)/Mac OS)",
          "image": {
            "url": "https://assetscdn.paytm.com/images/catalog/product/L/LA/LAPAPPLE-MPXT2HNAVK49295F2A396E0/1.jpg",
            "accessibilityText": "Apple MPXT2HN/A Core i5 (6th Gen)/8 GB/256 GB/33.78 cm (13.3)/Mac OS)"
          },
          "openUrlAction": {
            "url": "https://paytmmall.com/apple-mpxt2hn-a-core-i5-6th-gen-8-gb-256-gb-33-78-cm-13-3-mac-os-CMPLXLAPAPPLE-MPXT2HE-HU224691C3146BBC-pdp?product_id=145650181&discoverability=online&src=grid&utm_source=NDTV&utm_medium=affiliate&utm_campaign=NDTV-recharge&utm_term=Gadget360"
          }
        }
      ],
      "platform": "google",
      "type": "browse_carousel_card"
    }
  ]
}

请注意,simple_response 消息对于此功能是强制性的,项目数量应大于 2 且小于 10.