actions-on-google / actions-on-google-nodejs

Node.js client library for Actions on Google
https://actions-on-google.github.io/actions-on-google-nodejs
Apache License 2.0
900 stars 193 forks source link

Only One Item in List OF Actions on Google Rich Response #335

Open iamrahulmaru opened 5 years ago

iamrahulmaru commented 5 years ago

What should we do when we have only one item to show in List of actions on google rich response.

Actually, I am printing dynamic items in List. But when there is only one data it gives error.

conv.ask(new List({
  title: 'List Title',
  items: {
    // Add the first item to the list
    'SELECTION_KEY_ONE': {
      title: 'Title of First List Item',
      description: 'This is a description of a list item.',
    },

  },
}));
maaaaaaaax commented 5 years ago

Have you tried adding an if condition that sends a BasicCard instead of a List when the list's length is 1?

iamrahulmaru commented 5 years ago

yes i have tried it but after that i can't get click event of that. like below

app.intent('actions.intent.OPTION', (conv, params, option) => {
  let response = 'You did not select any item';
  if (option && SELECTED_ITEM_RESPONSES.hasOwnProperty(option)) {
    response = SELECTED_ITEM_RESPONSES[option];
  }
  conv.ask(response);
});
Fleker commented 5 years ago

That's an interesting point. If there is only one item, how much do you need to rely on user interaction? Maybe you adapt the flow more like this:

I found one item, Title. Do you want to hear it? User: Yes same fulfillment as selecting item

versus

I found 3 items. Which one do you want? User: Click

iamrahulmaru commented 5 years ago

@Fleker that could be a possible solution. but I think Actions on Google should remove validation of minimum 2 items in the list. Only one item should be allowed. It will be easy & convenient for both users & developers.

iamrahulmaru commented 5 years ago

and there is a maximum limit of 30 items in one list. What should we do when we have more than 30 items to show in one item?

Fleker commented 5 years ago

You should splice the list and ensure that you have a maximum of 30 items.

iamrahulmaru commented 5 years ago

You should splice the list and ensure that you have a maximum of 30 items.

that I know... but what if I have more than 30 items... what should we do in that case?

Fleker commented 5 years ago

If you have more than 30, you should either splice the array so you show 30, or do some sort of pagination system. But if you have more than 30, a carousel is probably not the right UI for your use case.

iamrahulmaru commented 5 years ago

Google should remove that validation of minimum 1 and maximum 30 (or give at least 50). Just a suggestion :)

Fleker commented 5 years ago

If you only have one item, is there a time when you'd want to show that one item instead of just passing through and showing the value of that item?

onigetoc commented 4 years ago

I just did that and it worked. I put it in a function and return all the results.

  var count = obj.resultCount;
  var data = obj.results;

  if (count > 1){
     // your list code here
  } else {   
    conv.ask(new BasicCard({
    text: data[0].description, // Note the two spaces before '\n' required for
                                 // a line break to be rendered in the card.
    subtitle: data[0].releaseDate,
    title: data[0].title,
    buttons: new Button({
      title: 'This is a button',
      url: 'https://assistant.google.com/',
    }),
    image: new Image({
      url: data[0].image,
      alt: data[0].title,
    }),
    display: 'CROPPED',
  }));

  }

But now, how to make it cliquable like a list and get all infos ???