-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample-automation-script.js
55 lines (43 loc) · 1.61 KB
/
sample-automation-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function run(input, params) {
if (!Env.getProperty('nuxeo.slack.token')) {
Console.log("Slack Token is not configured. Skipping Notification");
return input;
}
// get text variables
var assignees = ctx.Event.getContext().getProperty('recipients');
var task = ctx.Event.getContext().getProperty('taskInstance');
var taskName = task.getName()? SlackUtils.getTranslation(task.getName(),"en-US") : '';
var directive = task.getDirective() ? SlackUtils.getTranslation(task.getDirective(),"en-US") : '';
var process = Repository.GetDocument(input, {
'value': task.getProcessId()
});
var processName = SlackUtils.getTranslation(process['dc:title'],"en-US");
//get action urls
var taskUrl = Env.getProperty('nuxeo.url')+"/ui/#!/tasks/"+task.getId();
var assetUrl = Env.getProperty('nuxeo.url')+"/ui/#!/doc/"+input.id;
var blockMessage = [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "You have a new task!"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<"+taskUrl+ "|" + processName + " - " + taskName + ">*\n<" + assetUrl + "|" + input['dc:title'] + ">\n" + directive
}
}
];
try {
Notification.SendSlackNotification(input, {
'message':'Hello, you have a new task! '+taskUrl,
'blocks': JSON.stringify(blockMessage),
'nuxeoUsernames': assignees
});
} catch (error) {
Console.log(error);
}
}