Bot Message Handler

Messages handlers can be triggered when a bot receives a message. They can also be used by the bot creator to post messages through the bot. The creator can either choose to post the message to all the users subscribed to the bot or only to a few selected users. The attributes passed when a message handler is triggered are listed below:

Attribute NameDescription
messageDetails of the message sent to the bot, upon which the message handler is triggered.
attachmentsAttachments passed in the message.
mentionsDetails of the user/chat/bot mentioned.
linksList of links, if any that is present in the message.
userDetails of the user sending a message to the bot.
chatDetails of the chat in which the message handler is triggered.
locationDetails of the current location of the user.

Example:

An example here is the Cliq Help Bot, that can assist you with questions you might have. A simple sample syntax for the Cliq Help Bot's message handler is shown below. 



//Sample Syntax for Bot Message Handler

response = Map();
contact = "[Contacts](https://www.zoho.com/cliq/help/contacts/)";
if(message.containsIgnoreCase("contacts"))
{
	response.put("text","That's a really good question. Why don't you take a look at our help guide on " + contact + " !");
}
else if(message.containsIgnoreCase("Hi") || message.containsIgnoreCase("Hey"))
{
	response.put("text","Hey *" + user.get("first_name") + "* ! How can I help you today?");
}
else
{
	response.put("text","I'm sorry, I am not able to help you with this question. :sad: ");
}
return response;

Using suggestions in the bot message handler 

Bot suggestions can be triggered by using the suggestions object in the bot message handler. These suggestions are prompted when a user enters a message corresponding to the text defined in your handler code. The suggestions are displayed as options, and on click from the user, the button option text is returned as a response. 

Note: A bot suggestions list can show a maximum of 10 suggestions.  

Sample structure of the suggestions object in bot message handler :

The entry map can have two parameters :

ParameterDescription
textString. Use this param to give the option text.
icon Image URL. This param can be used to give an icon/image to the option.

list = List();
entry = Map();
entry.put("text","");
entry.put("icon","");
list.add(entry);

Example 

The above-given use case can be simplified using the suggestions object in the bot message handler. 



response = Map();
if(message.containsIgnoreCase("Help"))
{
	suggestions = Map();
	list = List();
	entry = Map();
	entry.put("text","Contacts");
	list.add(entry);
	entry1 = Map();
	entry1.put("text","Channels");
	list.add(entry1);
	response.put("text","Hey " + user.get("first_name") + " ,choose one option from the list! I can help you with these. :smile:");
	suggestions.put("list",list);
	response.put("suggestions",suggestions);
}
else if(message.containsIgnoreCase("Contacts"))
{
	response.put("text","Contacts are users who accept your invites and vice versa. Learn more about contacts [here](https://www.zoho.com/cliq/help/contacts/)");
}
else if(message.containsIgnoreCase("Channels"))
{
	response.put("text","Channels is a platform for groups to share information! See our help page on [Channels](https://www.zoho.com/cliq/help/channels/)");
}
else
{
	response.put("text","I'm sorry. I can't help you with this. Try typing *Help* :upset:");
}
return response;

 

When a user selects an option from the bot suggestions, the selected entity will be return as a message input. 

Articles:

Cliq Bots - How to make a bot respond to your messages?

Read this form post on how to use bot suggestions and configure the bot message handler!