Repository navigation
Expand file tree
/
Copy pathsample_code_integration.js
More file actions
89 lines (79 loc) · 3.67 KB
/
Copy pathsample_code_integration.js
File metadata and controls
89 lines (79 loc) · 3.67 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
({
componentName: "googleMail",
componentVersion: 1,
version: "0.0.1",
description: "A sample code integration built on the Gmail component.",
workflows: [
{
name: "summarizeNewEmail",
label: "Summarize New Email",
description: "Runs for every new email in the connected user's 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",
description: "Builds a one-line summary of the new email.",
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 connected user's most recent emails, optionally only those from one sender.",
triggers: [{name: "request", type: "request/v1/awaitWorkflowAndRespond"}],
outputs: [{name: "emails", task: "fetchEmails"}],
tasks: [
{
name: "fetchEmails",
label: "Fetch Emails",
description: "Searches the inbox with the Gmail Search Email action.",
perform: function (context) {
const request = context.input()["request"] || {};
const body = request.body || {};
const result = context.component.googleMail.searchEmail(
{from: body.from, maxResults: body.maxResults || 10});
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 connected user's 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;
}
}
]
}
]
})