问题
I'm doing a project where the Google Assistant generates a list of cards about information on research articles. Each card on the list would have the title and URL to the research article. The Google Assistant would ask what subject you wants to research about and the user would reply with the subject matter in one or two words. I have the following questions
I understand that the
app.buildList()
command requires analias
andkey
variable. Could I level them as blank ornull
in my code because I don't think I need themIf the user clicks on the URL in a card, will the browser automatically open the link? I remember reading that Google must filter and approve URLs in Google assistant apps
Any help would be appreciated
回答1:
You should probably populate the relevant fields for each API call in order to handle various types of user inputs. The key
is used to identify the item that is being said. If a list is shown, you will need to use the key
to identify which is clicked. The user may click on the list item to select it. However, they could also say the thing they want. That is where the aliases are useful.
Let's say you were grabbing a list of scholarly articles. While long articles may not lend themselves well to voice, it could be designed like:
function list () {
const app = new DialogflowApp({request, response});
app.askWithList('Alright! Here are some articles about memristors! Which do you want?',
// Build a list
app.buildList('Memristor Research')
// Add the first item to the list
.addItems(app.buildOptionItem('TITLE_OF_FIRST_PAPER',
['title of first paper', 'first'])
.setTitle('Title of First Paper')
.setDescription('S. Smith, Ph. D')
// Add the second item to the list
.addItems(app.buildOptionItem('TITLE_OF_SECOND_PAPER',
['title of second paper', 'second'])
.setTitle('Title of Second Paper')
.setDescription('H. Paul, Ph. D')
)
);
}
In this snippet, if I say I want the first article, it will give me that one without me having to give the full title while still keeping the interaction hands-free. The key
will let me identify the article that should be read.
You can use the title of the paper or perhaps the link URL in order to handle it and present a card with more information including the URL.
You do not need to have each URL manually approved. The documentation states:
- Links to sites outside the developer's domain are allowed.
- Link text cannot be misleading. This is checked in the approval process.
As long as you are being straightforward about it, users will be able to directly open the paper in a browser by clicking on the link in the card.
More information is available in the documentation
回答2:
You can create list in action on google should have minimum of two values and maximum of 30 values.
For sample code here : https://developers.google.com/actions/assistant/responses#sample_code_2
来源:https://stackoverflow.com/questions/48402373/building-a-list-in-actions-on-google