Zobot to handle single choice menu when dynamic list content is more than 10 items

Zobot to handle single choice menu when dynamic list content is more than 10 items

Whatsapp supports maximum of only 10 items for its single choice menu. When we need to show a dynamic list with content more than 10, this could be challenging. We essentially need to add a next and previous buton here in order to make it functional. I am sharing a plug code that can be used to split and basically paginate the content which is used in our business model to list subscribed products of a contact. 

items = List();
if(session.containsKey("phone"))
{
phone = session.get("phone").get("value");
}
index = session.get("index").get("value");
info phone;
contact = zoho.crm.searchRecords("Contacts","(Mobile:equals:" + phone + ")");
contactid = contact.get(0).get("id");
subscriptions = zoho.crm.getRelatedRecords("Subscription","Contacts",contactid);
pagesize = index + 8;
//info subscriptions;
for each  subscription in subscriptions
{
if(subscription.get("Description") == "Chit Subscription" || subscription.get("Description") == "Public Substitution")
{
subid = subscription.get("id");
chitName = subscription.get("Subscribed_Product").get("name");
chittal = subscription.get("Chittal");
output = chitName + "-" + chittal;
info output;
items.add({"id":subid,"text":output});
}
}
if(pagesize > items.size())
{
pagesize = items.size();
}
itemsPaginated = items.subList(index,pagesize);
if(pagesize < items.size())
{
itemsPaginated.add({"id":"next","text":"Next"});
itemsPaginated.add({"id":"previous","text":"Previous"});
}
response = Map();
response.put("items",itemsPaginated);
return response;
An index with value 0 is initially passed when loading the menu. This can be declared using any plugs used before zobot reached this plug.
After this, we need to add a criteria router to check if user had clicked next or previous button. Then if the click is next, we increment the index and if its previous, we decerement it. The below plug code handles that.
index = session.get("index").get("value");
choice = session.get("choice").get("value");
info choice;
if(choice.contains("next"))
{
newIndex = index + 8;
}
else if(choice.contains("previous") && index > 1)
{
newIndex = index - 8;
}
else
{
newIndex = 0;
}
response = Map();
response.put("newIndex",newIndex);
return response;