我正在使用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');
现在我想打开浏览器并将用户重定向到匹配的产品页面。 我该如何实现这一目标?
答案 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
答案 1 :(得分:1)
如果我理解你想要做什么,我做了类似的事情:
actions_intent_OPTION
const param = app.getSelectedOption()
答案 2 :(得分:1)
谷歌最近为此功能推出了“浏览转盘”。
以下是浏览轮播卡的消息对象格式。
"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中获得此信息)并仅在有屏幕的情况下返回它。