building a list in “actions on google”

我的未来我决定 提交于 2020-01-05 02:33:25

问题


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

  1. I understand that the app.buildList() command requires an alias and key variable. Could I level them as blank or null in my code because I don't think I need them

  2. If 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!