Last active
December 11, 2017 01:40
-
-
Save johnotu/9d4a87f700fd2c12de6da8ae641fbe33 to your computer and use it in GitHub Desktop.
Repeatedly generate different sets of quick replies from a products array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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