Repository navigation
Expand file tree
/
Copy pathsample_code_project.js
More file actions
105 lines (94 loc) · 4.12 KB
/
Copy pathsample_code_project.js
File metadata and controls
105 lines (94 loc) · 4.12 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
({
name: "Sample Code Project JavaScript",
version: "1",
description: "Sample code project description.",
workflows: [
{
name: "sampleWorkflow1",
label: "Sample workflow 1",
description: "Greets the name it is given.",
inputs: [{name: "name", label: "Name", type: "STRING", required: true}],
outputs: [{name: "greeting", task: "greet"}],
tasks: [
{
name: "greet",
label: "Greet",
description: "Builds a greeting from the name input.",
perform: function (context) {
const name = context.input("name");
context.log("info", "Greeting " + name);
return "Hello, " + name + "!";
}
}
]
},
{
name: "summarizeNewEmail",
label: "Summarize New Email",
description: "Runs for every new email in the inbox and logs who sent it.",
triggers: [{name: "newEmail", type: "googleMail/v1/newEmailPolling", parameters: {format: "SIMPLE"}}],
outputs: [{name: "summary", task: "summarize"}],
tasks: [
{
name: "summarize",
label: "Summarize",
perform: function (context) {
const email = context.input("newEmail");
const summary = "New email from " + email.from + ": " + email.subject;
context.log("info", summary);
return summary;
}
}
]
},
{
name: "fetchRecentEmails",
label: "Fetch Recent Emails",
description: "Returns the most recent emails, optionally only those from one sender.",
inputs: [{name: "from", label: "From", type: "STRING", required: false}],
outputs: [{name: "emails", task: "fetchEmails"}],
tasks: [
{
name: "fetchEmails",
label: "Fetch Emails",
connections: [{componentName: "googleMail", name: "gmail"}],
perform: function (context) {
const result = context.component.googleMail.searchEmail(
{from: context.input()["from"], maxResults: 10}, "gmail");
context.log("info", "Found " + (result.messages || []).length + " emails");
return result.messages || [];
}
}
]
},
{
name: "notifySlackOnNewEmail",
label: "Notify Slack on New Email",
description: "Posts every new email in the inbox to a Slack channel.",
inputs: [
{
name: "channel", label: "Slack Channel", type: "STRING", required: true,
componentName: "slack", componentVersion: 1, groupName: "channel"
}
],
triggers: [{name: "newEmail", type: "googleMail/v1/newEmailPolling", parameters: {format: "SIMPLE"}}],
outputs: [{name: "message", task: "postToSlack"}],
tasks: [
{
name: "postToSlack",
label: "Post to Slack",
description: "Posts the sender and subject with the Slack Send Channel Message action.",
connections: [{componentName: "slack", name: "slack"}],
perform: function (context) {
const email = context.input("newEmail");
const text = "New email from " + email.from + ": " + email.subject;
const message = context.component.slack.sendChannelMessage(
{channel: context.input("channel"), text: text}, "slack");
context.log("info", "Posted to Slack: " + text);
return message;
}
}
]
}
]
})