Bot Menu Handler

What are bot menus?

A menu action is a shortcut that a bot can perform for the user or is an interface from which the user gets to select the required action from a list of actions that are lined up. To understand this in a better way, consider the example of the Projects Bot that has a list of menu actions like Stats, Add, My Tasks, My Bugs and Configure. Clicking on any of these options will pull out the required information instantly thereby reducing the time latency.

Note: You can add up to five custom menus for a bot.

Default bot menu actions

A list of default menu actions is available for all bots, such as

  • Print - To print the chat transcript.
  • Pin Bot - Use this menu item to list the bot under the My Pins category.
  • Unsubscribe - Unsubscribe to a bot.
  • Bot Permalink - Select this action item to copy the bot permalink and share instantly.

How can you create a custom bot menu?

  • Once you create a bot by giving the name, description, filling the required fields and clicking that Save Bot button, you will be directed to the Edit Handlers page.
  • Click Add Menu under the Menu option. 
  • Name your menu action and define it's functionality in the Edit Code page.

Where can you find a bot's menu actions?

The custom menu actions are displayed below the message composer in the chat window!

Configuring the bot menu handler

Given below are the list of attributes that are passed when a bot menu handler is triggered.

AttributesDescription
UserDetails of the bot subscriber who executes the menu action.
LocationDetails about the current location of the user.
ChatDetails of the bot's chat.
context_idA unique identifier for each context map. You can use this to invoke the context handler from the menu handler
 
sub_actionA unique identifier for each bot sub action. You can use this to define execution for each sub action.
 

Using bot menu handler

The Projects Bot has a menu option to get details of issues/bugs assigned to you. Take a look at the sample syntax given below. We've used our message cards here to display data. Learn more about message cards 

Note:

This example uses the Get all issues API of Zoho Projects. To learn more about this API, refer Zoho Projects API

 



message = Map();
assigneelist = List();
assigneelist.add(user.get("id"));
paramsMap = {"statustype":"open","assignee":assigneelist};
getUserIssues = invokeurl
[
	url :"https://projectsapi.zoho.com/restapi/portal/Portal ID/projects/Project ID/bugs/"
	type :GET
	parameters:paramsMap
	connection:"Enter your connection name"
];
bugs = getUserIssues.toMap().get("bugs");
rows = List();
for each  bug in bugs
{
	title = bug.get("title");
	bugid = bug.get("bug_number");
	severity = bug.get("severity").toMap().get("type");
	row = Map();
	row.put("Issue Title",title);
	row.put("Issue ID",bugid);
	row.put("Severity",severity);
        row.put("Change Status","[+Change Stauts](invoke.function|projects)");
        row.put("Add Note","[Add Note](invoke.function|projects)");
	rows.add(row);
}
info rows;
message = {"text":"Hey "+user.get("first_name")+" ! List of recent open issues assigned to you!","card":{"title":"Open Issues","theme":"modern-inline"},"slides":{{"type":"table","title":"Issue Details","data":{"headers":{"Issue Title","Issue ID","Severity","Change Status","Add Note"},"rows":rows}}}};
zoho.cliq.postToBot("Enter your bot's unique name",message);
return Map();

Invoking the context handler from the bot menu handler

Let us consider a cab booking bot that helps the customer's in booking cabs. The bot shows a list of options to the users as suggestions and when the user selects an option, the menu handler is triggered to show the initial list of suggestions. Further the responses made by the user are passed to the context handler through the context map, and any further action is performed using the bot context handler. 

Sample code for a bot menu handler


response=Map();
context={"id":"Cab Service","timeout":"300","params":[{"name":"cab service","question":"Great! Let me fetch you the cab details :smile:","suggestions":{"list":[{"text":"Micro"},{"text":"Sedan"},{"text":"Mini"}]}},{"name":"time","question":"Okay cool. When can I send them over?","suggestions":{"list":[{"text":"Now"},{"text":"In half an hour"}]}},{"name":"Confirmation","question":"Please confirm your request once!","suggestions":{"list":[{"text":"Yes"},{"text":"No"}]}}]};
response.put("context",context);
return response;

Sample code for a context handler


response=Map(); 
info answers;
if(context_id.matches("Cab Service"))
{
confirm="Please check other options then!"; 
if(answers.get("Confirmation").containsIgnoreCase("YES"))
{
confirm="Great! I've arranged for a" + answers.get("cab service").get("text") + "to be there" + answers.get("time").get("text") +". :thumbsup:"; 
} 
response.put("text",confirm);
}
return response;

 

Articles:

Cliq Bots - Create preset actions for your bot using the menu handler

Learn how to configure a feedback menu action to receive feedback from your bot subscribers.