Extension Properties

What are extension properties? 

Extension properties are values associated with the extension. They are quite similar to regular data properties, wherein you map a key of type string with a value string.  The main purpose is to store data configurations for the extension. They can be added, retrieved for use and deleted and even the Organization admin does not have access to view these configurations. These properties should be created and updated during extension installation and used in the extension code. Cliq supports a maximum of 10 properties per extension.

How can extension properties be used?

Let's consider a scenario where you would like to store some details the user gives when installing the extension. Instead of creating a database in Cliq to store only one row of information, you can set a property and call the relevant deluge tasks in any of the extension component! A few examples where extension properties can be used are:

  • Storing the URL of the server that will be connected to the extension
  • The data center's ID the extension should connect

Note:

The extension properties task can be used only in components that are bundled in an extension.

Extension Properties Deluge Tasks

Cliq Platform offers three deluge tasks to create and manage extension properties. They are:

zoho.cliq.extension.setProperties

Use this deluge task to set a property value with a string. Values passed should be of the data type Map.

Syntax


zoho.cliq.extension.setProperties($data_map);

 

Note:

Extension properties' keys can consist only characters from a to z and _

 

Sample Code



dataMap = {"username":"scottfisher"};
zoho.cliq.extension.setProperties(dataMap);

zoho.cliq.extension.getProperties

Use this deluge task to get the value assigned to a property. Pass the string variable assigned to the property along with the task to retrieve the property. 

To get a list of properties, create a list with all the string variables and pass the list in the getProperties deluge task.

Syntax


zoho.cliq.extension.getProperties($property_name);

 

Sample Code



zoho.cliq.extension.getProperties("username");

zoho.cliq.extension.deleteProperty

Use this deluge task to delete a property. Values passed to this deluge task should be of the type map. 

Syntax


zoho.cliq.extension.deleteProperty($data_map);

 

Sample Code



dataMap = {"username":"scottfisher"};
zoho.cliq.extension.deleteProperty(dataMap);

User Scenario - GitHub Extension for Cliq

Take for example, an integration between GitHub and Cliq. The GitHub extension for Cliq provides notifications of event updates such as new issues, issue fixes, branch merges to name a few. The extension's installation handler is configured to create webhooks for all the existing projects in the user's GitHub account. During installation, the extension set properties deluge task is triggered to store the incoming webhook endpoint. The bot's menu action can be used to pull the list of all projects that donot have a webhook configured with Cliq. The project list is shown with a button to create the webhook. On button click, the function to create webhook is called. The extension's incoming webhook endpoint stored using extension property is called in the button function code. The workflow is given below!

Installation Handler Code



response = Map();
success = true;
if(success)
{
	appid = Map();
	appid.put("webhook","https://cliq.zoho.com/api/v2/applications/"APP ID"/incoming?appkey="APPKEY"&zapikey=" + authtoken);
	zoho.cliq.extension.setProperties(appid);
	response.put("status","200");
	response.put("title","Success!");
	response.put("message","We're glad you chose this extension!");
	note = list();
	note.add("1. Use the bot to resolve issues quicker.");
	note.add("2. Use the slash commands and message actions to keep track for activities");
	response.put("note",note);
	response.put("footer","Contact support@yourdomain.com for any related help / support.");
}
else
{
	response.put("status","500");
	response.put("title","Uh-oh!");
	response.put("message","We're sorry! The extension installation failed.");
	note = list();
	note.add("Installation failure might be due to the following reasons:");
	note.add("1. Your account is not in the premium plan.");
	note.add("2. You have not configured the webhook properly.");
	response.put("note",note);
	response.put("footer","Contact support@yourdomain.com for any related help / support.");
}
return response;

 

@GitHub Bot Menu Action - Add Alerts




response = Map();
getUserDetails = invokeurl
[
	url :"https://api.github.com/user"
	type :GET
	connection:"ENTER THE CONNECTION NAME"
];
userName = getUserDetails.get("login");
repoName = invokeurl
[
	url :"https://api.github.com/users/" + userName + "/repos"
	type :GET
	connection:"ENTER THE CONNECTION NAME"
];
if(repoName.toList().size() == 0)
{
	resp = {"text":user.get("first_name") + " I couldn't find any repositories in your GitHub :sad: \nOnce you are part of repos, try again.","card":{"theme":"4"},"bot":{"name":"GitHub","image":"https://image.flaticon.com/icons/svg/25/25231.svg"}};
}
list = List();
for each  result in repoName.toList()
{
	name = result.get("full_name");
	reponame = result.get("name");
	getHooks = invokeurl
	[
		url :"https://api.github.com/repos/" + name + "/hooks"
		type :GET
		connection:"ENTER THE CONNECTION NAME"
	];
	if(getHooks.isEmpty())
	{
		entry = Map();
		entry.put("reponame",reponame);
		list.add(entry);
	}
	else if ( !getHooks.isEmpty() ) 
    	{
		url = getHooks.toMap().get("config").get("url");
		if(!url.contains("https://cliq.zoho.com/api/v2/applications/"APP-ID"/incoming"))
		{
			entry = Map();
			entry.put("reponame",reponame);
			list.add(entry);
		}
    	}
}
if(list.size() == 0)
{
	resp = {"text":"Yowza, all your repos are in my watchlist! I will notify you the moment an action takes place in any of them. ","card":{"theme":"4"},"bot":{"name":"GitHub","image":"https://image.flaticon.com/icons/svg/25/25231.svg"}};
}
else
{
	lists = List();
	for each  repo in list
	{
		name = repo.get("reponame");
		lists.add('[+' + name + '](invoke.function|Createhook|cliq@gmail.com|' + name + ')');
	}
	resp = {"text":"Hi there :bye-bye:\nPlease pick the repositories for which you would like to receive all updates.","bot":{"name":"GitHub","image":"https://image.flaticon.com/icons/svg/25/25231.svg"},"card":{"theme":"10"},"slides":{{"type":"list","data":lists}}};
}
zoho.cliq.postToChat(chat.get("id"),resp);
return Map();

 

Create Webhook Button Function



info arguments;
response = Map();
reponame = arguments.get("key");
getUser = invokeurl
[
	url :"https://api.github.com/user"
	type :GET
	connection:"ENTER THE CONNECTION NAME"
];
userName = getUser.get("login");
params = Map();
config = Map();
events = {"push","issues","create","delete","pull_request","commit_comment","issue_comment"};
params.put("name","web");
params.put("events",events);
webhookUrl = zoho.cliq.extension.getProperties("webhook");
webhookUrl = webhookUrl.toMap().get("webhook");
config.put("url",webhookUrl);
config.put("content_type","json");
param.put("config",config);
createHook = invokeurl
[
	url :"https://api.github.com/repos/" + userName + "/" + reponame + "/hooks"
	type :POST
	parameters:params.toString()
	connection:"ENTER THE CONNECTION NAME"
];
id = createHook.get("id");
if(id != null)
{
	resp = {"text":"Cool! I've added this repo to my watchlist. :cool:","card":{"theme":"4"},"bot":{"name":"GitHub","image":"https://image.flaticon.com/icons/svg/25/25231.svg"}};
}
else
{
	resp = {"text":"Great! This repo has already been added to my watchlist. I can even double watch it for ya, so that nothing will be missed :relaxed:","card":{"theme":"4"},"bot":{"name":"GitHub","image":"https://image.flaticon.com/icons/svg/25/25231.svg"}};
}
return response;