Skip to content

Instantly share code, notes, and snippets.

@johnotu
Created December 11, 2017 00:22
Show Gist options
  • Save johnotu/63b10e4f87ecfa852bbb524dcd592b0f to your computer and use it in GitHub Desktop.
Save johnotu/63b10e4f87ecfa852bbb524dcd592b0f to your computer and use it in GitHub Desktop.
const quickReplyTags = (tags, sliceSet, beginSlice, endSlice) => {
// slice the elements of the array to the desired set size
let slicedTags = tags.slice(beginSlice, endSlice);
// form an array of quick replies with title and payload
let quickReplies = slicedTags.map(tag => {
return {
"content_type": "text",
"title": tag.title,
"payload": tag.title
};
});
// Check if the current set is not the last one
if (endSlice < tags.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