Vous êtes sur la page 1sur 9

Slash Command - Add 2 Numbers

message = Map();
info arguments;
argumentsSplit = arguments.toList(",");
info argumentsSplit;
sum = abs(argumentsSplit.get(0)) +
abs(argumentsSplit.get(1));
message.put("text","Sum is " + sum);
return message;

Message Action- Upload to Zoho Docs

info message;
// Upload your file to Zoho Docs
output = Map();
docsparams = Map();
att = attachments.get(0);
docsparams.put("stringPart","true");
docsparams.put("paramName","filename");
docsparams.put("content","" + att);
fileslist = List();
fileslist.add(docsparams);
att.setParamName("content");
fileslist.add(att);
response1 = invokeurl
[
url :"https://apidocs.zoho.com/files/v1/upload"
type :POST
files:fileslist
connection:"ENTER THE CONNECTION NAME"
];
info response1;
result =
response1.get("response").toList().get(2).toList();
info result;
docid =
result.toMap().get("result").toList().get(1).toMap()
.get("uploaddocid");
output.put("text","Uploaded to your ZOHO Docs! (y)
[View in Docs](https://docs.zoho.com/file/" + docid
+ ")");
return output;

Bots

Asana Bot - Message Handler

response = Map();
if(message.containsIgnoreCase("Add a task"))
{
workspaces = invokeurl
[
url :"https://app.asana.com/api/1.0/workspaces"
type :GET
connection:"ENTER THE CONNECTION NAME"
];
workspaceId =
workspaces.get("data").get(0).get("id");
workspaces = workspaces.get("data");
workspaceName = workspaces.get(0).get("name");
context =
{"id":"addTask","timeout":"300","params":{{"name":"t
askName","question":"Alright let's get started! Give
me the task name.
:smile:"},{"name":"users","question":"Okay. Who
shall I assign this task to? \nYou could also assign
it to yourself or leave it
unassigned","suggestions":{"list":{{"text":"Assign
to myself"},{"text":"Leave it
unassigned"}}}},{"name":"workspace","question":"Awes
ome. You have only one workspace. i will go ahead
and pick that
directly.","value":{"text":workspaceName}}}};
response.put("context",context);
}
else
{
response = {"text":"Hi, I'm Asana bot, You can use
me to create a task in a specific workspace of your
choice, Click this to create
one","suggestions":{"list":{{"text":"Add a
task"}}}};
}
return response;

Asana Bot - Context Handler

response = Map();
info answers;
workspaceName =
answers.get("workspace").get("text");
if(context_id.equals("addTask"))
{
if(answers.size() == 3)
{
workspaceName =
answers.get("workspace").get("text");
workspaces = invokeurl
[
url :"https://app.asana.com/api/1.0/workspaces"
type :GET
connection:"ENTER THE CONNECTION NAME"
];
workspaces = workspaces.get("data");
for each workspace in workspaces
{
if(workspaceName == workspace.get("name"))
{
workspaceId = workspace.get("id");
}
}
taskName = answers.get("taskName").get("text");
if(answers.get("users").get("text") == "Assign to
myself")
{
assignee = user.get("email");
parameters =
{"data":{"assignee":assignee,"workspace":workspaceId
,"name":taskName}};
}
else
{
parameters =
{"data":{"workspace":workspaceId,"name":taskName}};
}
parameters = parameters.toString();
createTaskResponse = invokeurl
[
url :"https://app.asana.com/api/1.0/tasks"
type :POST
parameters:parameters
connection:"ENTER THE CONNECTION NAME"
];
info createTaskResponse;
createdTask = createTaskResponse.get("data");
info createdTask;
if(createdTask.get("assignee") == null)
{
response = {"text":"\nTask Name: " +
createdTask.get("name") + "\nAssigned to : No
one","card":{"title":"The task has been created
(y)","theme":"modern-inline"}};
}
else
{
response = {"text":"\nTask Name: " +
createdTask.get("name") + "\nAssigned to : " +
createdTask.get("assignee").get("name"),"card":{"tit
le":"The task has been created
(y)","theme":"modern-inline"}};
}
}
}
return response;

Asana Bot - Incoming Webhook Handler

info body;
response = Map();
webhookBody = body.toMap();
events = webhookBody.get("events");
isChangeNotified = false;
for each event in events
{
resourceId = event.get("resource");
}
if(event.get("type") == "task" &&
event.get("action") == "added" || event.get("type")
== "task" && event.get("action") == "changed" &&
isChangeNotified != true)
{
assigneeId = "";
taskInfo = invokeurl
[
url :"https://app.asana.com/api/1.0/tasks/" +
resourceId
type :GET
connection:"ENTER THE CONNECTION NAME"
];
task = taskInfo.get("data");
assignedTo = "None";
taskName = task.get("name");
created = task.get("created_at").toDate();
due = "-";
if(task.get("due_on") != null)
{
due = task.get("due_on").toDate();
}
modified = task.get("modified_at").toDate();
status = task.get("assignee_status");
notes = task.get("notes");
if(task.get("assignee") != null)
{
assignedTo = task.get("assignee").get("name");
assigneeId = task.get("assignee").get("id");
}
else
{
assignedTo = "no one";
}
person = invokeurl
[
url :"https://app.asana.com/api/1.0/users/" +
assigneeId
type :GET
connection:"ENTER THE CONNECTION NAME"
];
//info person;
emailIds = List();
emailIds.add(person.get("data").get("email"));
emailIds = emailIds.toString();
info resourceId;
response = {"text":"Task assigned to " +
assignedTo,"card":{"theme":"modern-inline","title":"
### " +
taskName},"slides":{{"type":"label","title":"Details
","data":{{"Created At":created},{"Due
by":due},{"Last Modified on":modified},{"Assignee
Status":status},{"Notes":notes}}}},"userids":emailId
s};
zoho.cliq.postToBot("BOTNAME",response);
}
return Map();

Slash Command - To create a webhook in


Asana

response = Map();
url =
"https://cliq.zoho.com/api/v2/bots/BOTNAME/incoming?
authtoken=AUTHTOKEN";
projects = invokeurl
[
url :"https://app.asana.com/api/1.0/projects"
type :GET
connection:"ENTER THE CONNECTION NAME"
];
projects = projects.get("data");
for each project in projects
{
projectId = project.get("id");
params =
{"data":{"target":url,"resource":projectId}};
webhooksCreate = invokeurl
[
url :"https://app.asana.com/api/1.0/webhooks"
type :POST
parameters:params.toString()
connection:"ENTER THE CONNECTION NAME"
];
info webhooksCreate;
}
if(webhooksCreate.containsKey("data"))
{
response = {"text":"Webhooks created
successfully","card":{"theme":"modern-inline"}};
}
else
{
response = {"text":"Error in creating
webhooks.","card":{"theme":"modern-inline"}};
}
return response;

Vous aimerez peut-être aussi