Skip to content

Instantly share code, notes, and snippets.

@johnotu
Last active December 11, 2017 01:40
Show Gist options
  • Save johnotu/9d4a87f700fd2c12de6da8ae641fbe33 to your computer and use it in GitHub Desktop.
Save johnotu/9d4a87f700fd2c12de6da8ae641fbe33 to your computer and use it in GitHub Desktop.
Repeatedly generate different sets of quick replies from a products array
const productQuickreplies = (products, sliceSet, beginSlice, endSlice) => {
// slice the elements of the array to the desired set size
let slicedProducts = products.slice(beginSlice, endSlice);
// form an array of quick replies with title and payload
let quickReplies = slicedProducts.map(product => {
return {
"content_type": "text",
"title": product.title,
"payload": product.title
};
});
// Check if the current set is not the last one
if (endSlice < products.length) {
// add an extra quick reply that will display the next set
quickReplies.push({
"content_type": "text",
"title": "Next",
"payload": `next_${beginSlice + sliceSet}_${endSlice + sliceSet}`
});
}
return quickReplies;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment