Skip to content

Instantly share code, notes, and snippets.

@johnotu
Created December 13, 2017 08:01
Show Gist options
  • Save johnotu/760a5ee1e81f5d6cda914fcb81cfa54e to your computer and use it in GitHub Desktop.
Save johnotu/760a5ee1e81f5d6cda914fcb81cfa54e to your computer and use it in GitHub Desktop.
quickReplies.push({
"content_type": "text",
"title": "Next",
"payload": "nextslice_5_10"
});
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;
}
[
{
_id: '59ed1ed9be3ee700123e4e4a',
title: 'shoes',
status: 'Active',
__v: 0,
},
{
_id: '59ed1ee7be3ee700123e4e4b',
title: 'casual',
status: 'Active',
__v: 0,
},
{
_id: '59ed1f41be3ee700123e4e4c',
title: 'biscuits',
status: 'Active',
__v: 0,
},
{
_id: '59ed1f47be3ee700123e4e4d',
title: 'snacks',
status: 'Active',
__v: 0,
},
{
_id: '59ed1f67be3ee700123e4e50',
title: 'lowsugar',
status: 'Active',
__v: 0,
},
{
_id: '59ed1f73be3ee700123e4e51',
title: 'weavon',
status: 'Active',
__v: 0,
},
{
_id: '59ed1f7dbe3ee700123e4e52',
title: 'computers',
status: 'Active',
__v: 0,
},
{
_id: '59ed1f86be3ee700123e4e53',
title: 'electronics',
status: 'Active',
__v: 0,
},
{
_id: '59ed1f94be3ee700123e4e54',
title: 'drinks',
status: 'Active',
__v: 0,
},
{
_id: '59ed1faabe3ee700123e4e55',
title: 'beer',
status: 'Inactive',
__v: 0,
},
{
_id: '5a280e4e767f3a00145ed7ce',
title: 'Sockets',
status: 'Active',
__v: 0,
},
{
_id: '5a280e4f767f3a00145ed7cf',
title: 'Sockets',
status: 'Active',
__v: 0,
},
{
_id: '5a280e77767f3a00145ed7d1',
title: 'tea',
status: 'Active',
__v: 0,
},
{
_id: '5a280e85767f3a00145ed7d2',
title: 'flowers',
status: 'Active',
__v: 0,
},
{
_id: '5a280e92767f3a00145ed7d3',
title: 'butter',
status: 'Active',
__v: 0,
},
];
let quickReplies = slicedProducts.map(product => {
return {
"content_type": "text",
"title": product.title,
"payload": product.title
};
});
const slicedProducts = products.slice(0,5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment