Bot Sub Actions

Bot sub actions

A bot's sub actions are like a subset of the bot's menu action handler. Sub actions execute the function from within the parent menu action they're associated with. When a user interacts with a bot sub action, sub_action attribute will be passed to the parent menu action for execution. You can add upto a maximum of 5 unique sub actions for each parent menu action. 

For example, consider a menu action called Issues.  This parent menu action will open up a list of all sub actions that can be performed on Issues. You can add in sub actions that will create, view or delete issues. 

How can you create a bot sub action?

1. Once you create the bot menu handler, click on the Edit Menu option and give your bot sub action a name and click save.  

2. Click on Edit Code for the parent menu action and define your sub action's functionality. 

Note:

To add more sub actions click on the Add Sub Menu option. You can also drag and drop to reorder the sub actions as per your preference. 

Where can you find a bot's sub action?

You can click on the dropdown icon right next to a bot's menu action to show the list of all sub actions associated with it. 

Using a bot's sub action

Let's say you want to manage your tasks in Zoho Projects from Cliq. To do so, create a menu action called Tasks. This will act as the parent menu action and will have a list of related sub actions that'll let you create, view and delete tasks. We've considered two sub actions as an example in the below code, one that lets you view your open tasks and one that'll pull up tasks that are completed. 



response = Map();
portals = invokeurl
[
url :"https://projectsapi.zoho.com/restapi/portals/"
type : GET
connection:"<Give your connection name>"
];
portalID = portals.get("portals").get(0).get("id");
project = invokeurl
[
url :"https://projectsapi.zoho.com/restapi/portal/"+portalID+"/projects/"
type : GET
connection:"<Give your connection name>"
];
projectID = project.get("projects").toList().get(0).get("id");
info projectID;
if(sub_action.containsIgnoreCase("View"))
{
tasks = invokeurl
[
url :"https://projectsapi.zoho.com/restapi/portal/"+portalID+"/projects/"+projectID+"/tasks/"
type : GET
parameters:{"owner": user.get("id"),"status":"notcompleted"}
connection:"<Give your connection name>"
];
info tasks;
rows = List();
tasks = tasks.get("tasks");
for each task in tasks
{
row = Map();
row.put("ID",task.get("key"));
row.put("Name", task.get("name"));
row.put("Due By", task.get("end_date_long").toTime("yyyy-MM-dd"));
row.put("Priority",task.get("priority"));
rows.add(row);
}
response = {"text":"Hey "+user.get("first_name")+"! Here're your task details: ","bot":{"name":"Projects Bot"},"card":{"theme":"modern-inline"},"slides":[{"type":"table","title":"","data":{"headers":["ID","Name","Due By","Priority"],"rows":rows}}]}; 
}
else if (sub_action.containsIgnoreCase("Delete")) 
{
tasks = invokeurl
[
url :"https://projectsapi.zoho.com/restapi/portal/"+portalID+"/projects/"+projectID+"/tasks/"
type : GET
parameters:{"created_by": user.get("id"),"status":"completed"}
connection:"<Give your connection name​>"
];
info tasks;
rows = List();
tasks = tasks.get("tasks");
for each task in tasks
{
row = Map();
row.put("ID",task.get("key"));
row.put("Name", task.get("name"));
row.put("Priority",task.get("priority"));
row.put("Status", task.get("status").get("name"));
row.put("Delete","[Delete](invoke.function|deletetask)");
rows.add(row);
}
	response = {"text": "Hey "+user.get("first_name")+"! Here's the list of tasks you've completed: ","bot":{"name":"Projects Bot"},"card":{"theme":"modern-inline"},"slides":[{"type":"table","title":"","data":{"headers":["ID","Name","Priority","Status","Delete"],"rows":rows}}]}; 
}
return response;

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: support@zohocliq.com