Guest User

Untitled

a guest
Dec 13th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. const productQuickreplies = (products, sliceSet, beginSlice, endSlice) => {
  2.  
  3. // slice the elements of the array to the desired set size
  4. let slicedProducts = products.slice(beginSlice, endSlice);
  5.  
  6. // form an array of quick replies with title and payload
  7. let quickReplies = slicedProducts.map(product => {
  8. return {
  9. "content_type": "text",
  10. "title": product.title,
  11. "payload": product.title
  12. };
  13. });
  14.  
  15. // Check if the current set is not the last one
  16. if (endSlice < products.length) {
  17. // add an extra quick reply that will display the next set
  18. quickReplies.push({
  19. "content_type": "text",
  20. "title": "Next",
  21. "payload": `next_${beginSlice + sliceSet}_${endSlice + sliceSet}`
  22. });
  23. }
  24. return quickReplies;
  25. }
Add Comment
Please, Sign In to add comment