Google操作 - 从轮播中打开链接

时间:2017-07-29 19:20:22

标签: carousel dialogflow actions-on-google google-home

我正在使用google actions node.js SDK进行Google操作。

在某些时候,我向用户展示了一个带有项目列表的轮播:

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');

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

4 个答案:

答案 0 :(得分:2)

目前,AoG不支持Carousel或List的外部链接,  你只能为每个项目保留一个密钥。

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

  • 向意图生成添加输出上下文(例如,const formatters = { 'string': input => input, 'number': input => input.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'), 'currency': input => input.toFixed(3), 'url': input => (`<a href="${input.url}">${input.title}</a>`) } const format = (type, value) => formatters[type](value) const formatted = format('string', 'hello') console.log(formatted)) 转盘。
  • 使用事件 const formatters = { 'string': input => input, 'number': input => input.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'), 'currency': input => input.toFixed(3), 'url': input => (`<a href="${input.url}">${input.title}</a>`) } const format = formatters => type => value => formatters[type](value) // You can use it in one call format(formatters)('string')('hello') // Create a function with predefined formatters const myFormatter = format(formatters) myFormatter('string')('hello') // Create a function with predefined formatters and for a specific type const urlFormatter = format(formatters)('url') urlFormatter('https://www.google.com')输入上下文 caro_link
  • 制作后备意图
  • 现在,使用后备意图,检查从轮播传递的密钥,并使用card或suggestionLink或其他任何内容返回产品的链接。

答案 1 :(得分:1)

如果我理解你想要做什么,我做了类似的事情:

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

答案 2 :(得分:1)

谷歌最近为此功能推出了“浏览转盘”。

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

答案 3 :(得分:0)

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

但是,您首先需要确定表面是什么(您在JSON obj中获得此信息)并仅在有屏幕的情况下返回它。