show some examples of use of loop statements in collectionbrowse assistant?

I found the answer myself!

You can create the array using a loop, and then create a new CollectionBrowse object using this array.

const {
  conversation,
  Simple,
  Card,
  Image,
  Button,
  List,
  Link,
  Table,
  CollectionBrowse,
  Suggestion,
  Schema
}  = require('@assistant/conversation');
const functions = require('firebase-functions');
const app = conversation({debug:true});

app.handle('callApi', (conv) => {
  
  var titleArr = ['Item #1','Item #2','Item #3'];
  var descriptionArr = ['Description #1','Description #2','Description #3'];
  var footerArr = ['footer #1','footer #2','footer #3'];
  var imageArr = [{url: 'https://developers.google.com/assistant/assistant_96.png'},{url: 'https://developers.google.com/assistant/assistant_96.png'},{url: 'https://developers.google.com/assistant/assistant_96.png'}];
  var openUriActionArr = [{url: 'https://www.example.com'},{url: 'https://www.example.com'},{url: 'https://www.example.com'}];
  var itemsArr = [];
  
  for(var i = 0; i<3; i++){
    itemsArr.push({
      title : titleArr[i],
      description : descriptionArr[i],
      footer : footerArr[i],
      image : imageArr[i],
      openUriAction : openUriActionArr[i]
    });
  }
    
  conv.add(new CollectionBrowse({
   items: itemsArr
  }));
});

exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top