Reading through the documentation for Actions on Google, I've built a browse carousel by using a rich response class and supplying it with a simple response, the carousel and some suggestion chips.
const carouselItems = [];
items.forEach(item => {
const carouselItem = new BrowseCarouselItem({
description: item.description.text,
image: new Image({
alt: item.title,
url: item.image,
}),
url: item.link,
title: item.title,
})
carouselItems.push(carouselItem)
});
conv.ask(new RichResponse({
items: [{
simpleResponse: new SimpleResponse("the simple response message"),
carouselBrowse: new BrowseCarousel({
items: [ browseCarouselItem1, browseCarouselItem2 ],
}),
}],
suggestions: ["suggestion1", "suggestion2"]
});
After spending time doing this, I discovered that the rich response class appears to be unnecessary. In fact, I can get the same result by using conv.ask()
three times in a row instead.
conv.ask("the simple response message");
conv.ask(new BrowseCarousel({
items: [ browseCarouselItem1, browseCarouselItem2 ]
}));
conv.ask(new Suggestions([ "suggestion1", "suggestion2" ]);
With this discovery, I find myself uncertain of the correct approach. Does one of these methods replace the other? What is the best practice? I've used RichResponse
a few times throughout my webhook and I'm now unsure if I am working with an obsolete class.