Skip to content

Commit 6d87ca6

Browse files
committed
[Components] elasticemail #15687
Sources - New Email Open - New Email Click - New Contact Added Actions - Send Email - Add Contact - Unsubscribe Contact
1 parent 57cd483 commit 6d87ca6

File tree

16 files changed

+511
-491
lines changed

16 files changed

+511
-491
lines changed

components/elastic_email/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,84 @@
1-
import elastic_email from "../../elastic_email.app.mjs";
2-
import { axios } from "@pipedream/platform";
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { STATUS_OPTIONS } from "../../common/constants.mjs";
3+
import { parseObject } from "../../common/utils.mjs";
4+
import app from "../../elastic_email.app.mjs";
35

46
export default {
57
key: "elastic_email-add-contact",
68
name: "Add Contact to Mailing List",
79
description: "Adds a new contact to a mailing list. [See the documentation]()",
8-
version: "0.0.{{ts}}",
10+
version: "0.0.1",
911
type: "action",
1012
props: {
11-
elastic_email: {
12-
type: "app",
13-
app: "elastic_email",
14-
},
15-
addContactEmail: {
13+
app,
14+
email: {
1615
propDefinition: [
17-
elastic_email,
18-
"addContactEmail",
16+
app,
17+
"email",
1918
],
2019
},
21-
addContactListName: {
20+
listNames: {
2221
propDefinition: [
23-
elastic_email,
24-
"addContactListName",
22+
app,
23+
"listNames",
2524
],
2625
optional: true,
2726
},
27+
status: {
28+
type: "string",
29+
label: "Status",
30+
description: "The initial status of the contact.",
31+
options: STATUS_OPTIONS,
32+
optional: true,
33+
},
34+
firstName: {
35+
type: "string",
36+
label: "First Name",
37+
description: "The contact's first name.",
38+
optional: true,
39+
},
40+
lastName: {
41+
type: "string",
42+
label: "Last Name",
43+
description: "The contact's last name.",
44+
optional: true,
45+
},
46+
customFields: {
47+
type: "object",
48+
label: "Custom Fields",
49+
description: "A key-value collection of custom contact fields which can be used in the system. Only already existing custom fields will be saved.",
50+
optional: true,
51+
},
52+
consent: {
53+
type: "object",
54+
label: "Consent",
55+
description: "An object with consent settings. **Example: \"ConsentIP\": \"192.168.0.1\", \"ConsentDate\": \"1/1/2015 0:00:00 AM\", \"ConsentTracking\": \"Unknown\"}**",
56+
optional: true,
57+
},
2858
},
2959
async run({ $ }) {
30-
const response = await this.elastic_email.addContact();
31-
if (this.addContactListName) {
32-
$.export(
33-
"$summary",
34-
`Successfully added contact ${this.addContactEmail} to the mailing list ${this.addContactListName}`,
35-
);
36-
} else {
37-
$.export(
38-
"$summary",
39-
`Successfully added contact ${this.addContactEmail} to the mailing list`,
40-
);
60+
const response = await this.app.addContact({
61+
$,
62+
params: {
63+
listnames: parseObject(this.listNames),
64+
},
65+
data: [
66+
{
67+
Email: this.email,
68+
Status: this.status,
69+
FirstName: this.firstName,
70+
LastName: this.lastName,
71+
CustomFields: parseObject(this.customFields),
72+
Consent: parseObject(this.consent),
73+
},
74+
],
75+
});
76+
77+
if (("success" in response) && response.success === "false") {
78+
throw new ConfigurationError(response.error);
4179
}
80+
81+
$.export("$summary", `Successfully added contact ${this.email} to the mailing list`);
4282
return response;
4383
},
4484
};
Lines changed: 111 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,127 @@
1-
import elasticEmail from "../../elastic_email.app.mjs";
2-
import { axios } from "@pipedream/platform";
1+
import { ENCODING_OPTIONS } from "../../common/constants.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import app from "../../elastic_email.app.mjs";
34

5+
/**FALTA TESTAR */
6+
/**FALTA TESTAR */
7+
/**FALTA TESTAR */
8+
/**FALTA TESTAR */
9+
/**FALTA TESTAR */
10+
/**FALTA TESTAR */
11+
/**FALTA TESTAR */
412
export default {
513
key: "elastic_email-send-email",
614
name: "Send Email",
7-
description: "Sends an email to one or more recipients. [See the documentation]()",
8-
version: "0.0.{{ts}}",
15+
description: "Sends an email to one or more recipients. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#operation/emailsPost)",
16+
version: "0.0.1",
917
type: "action",
1018
props: {
11-
elastic_email,
12-
sendEmailRecipients: {
13-
propDefinition: [
14-
"elastic_email",
15-
"sendEmailRecipients",
16-
],
19+
app,
20+
recipients: {
21+
type: "string[]",
22+
label: "Recipients",
23+
description: "List of recipients",
1724
},
18-
sendEmailSubject: {
19-
propDefinition: [
20-
"elastic_email",
21-
"sendEmailSubject",
22-
],
25+
from: {
26+
type: "string",
27+
label: "From",
28+
description: "Your e-mail with an optional name (e.g.: [email protected])",
29+
},
30+
body: {
31+
type: "string[]",
32+
label: "Body",
33+
description: "List of e-mail body parts, with user-provided MIME types (text/html, text/plain etc). **Format: {\"ContentType\": \"HTML\", \"Content\": \"email content\", \"\": \"\"}**",
34+
optional: true,
35+
},
36+
merge: {
37+
type: "object",
38+
label: "Merge",
39+
description: "A key-value collection of custom merge fields, shared between recipients. Should be used in e-mail body like so: {firstname}, {lastname} etc.",
40+
optional: true,
41+
},
42+
replyTo: {
43+
type: "string",
44+
label: "Reply To",
45+
description: "To what address should the recipients reply to (e.g. [email protected])",
46+
optional: true,
2347
},
24-
sendEmailBody: {
48+
subject: {
49+
type: "string",
50+
label: "Subject",
51+
description: "Default subject of email.",
52+
optional: true,
53+
},
54+
templateName: {
2555
propDefinition: [
26-
"elastic_email",
27-
"sendEmailBody",
56+
app,
57+
"templateName",
2858
],
59+
optional: true,
60+
},
61+
timeOffset: {
62+
type: "integer",
63+
label: "Time Offset",
64+
description: "By how long should an e-mail be delayed (in minutes). Maximum is 35 days.",
65+
optional: true,
66+
},
67+
poolName: {
68+
type: "string",
69+
label: "Pool Name",
70+
description: "Name of your custom IP Pool to be used in the sending process",
71+
optional: true,
72+
},
73+
channelName: {
74+
type: "string",
75+
label: "Channel Name",
76+
description: "Name of selected channel.",
77+
optional: true,
78+
},
79+
encoding: {
80+
type: "string",
81+
label: "Encoding",
82+
description: "Encoding type for the email headers",
83+
options: ENCODING_OPTIONS,
84+
optional: true,
85+
},
86+
trackOpens: {
87+
type: "boolean",
88+
label: "Track Opens",
89+
description: "Should the opens be tracked? If no value has been provided, Account's default setting will be used.",
90+
optional: true,
91+
},
92+
trackClicks: {
93+
type: "boolean",
94+
label: "Track Clicks",
95+
description: "Should the clicks be tracked? If no value has been provided, Account's default setting will be used.",
96+
optional: true,
2997
},
3098
},
3199
async run({ $ }) {
32-
const response = await this.elastic_email.sendBulkEmails();
33-
$.export("$summary", `Emails sent successfully to ${this.sendEmailRecipients.join(", ")}`);
100+
const response = await this.app.sendBulkEmails({
101+
$,
102+
data: {
103+
Recipients: parseObject(this.recipients)?.map((item) => ({
104+
Email: item,
105+
})),
106+
Content: {
107+
From: this.from,
108+
Body: this.body,
109+
Merge: this.merge,
110+
ReplyTo: this.replyTo,
111+
Subject: this.subject,
112+
TemplateName: this.templateName,
113+
},
114+
Options: {
115+
TimeOffset: this.timeOffset,
116+
PoolName: this.poolName,
117+
ChannelName: this.channelName,
118+
Encoding: this.encoding,
119+
TrackOpens: this.trackOpens,
120+
TrackClicks: this.trackClicks,
121+
},
122+
},
123+
});
124+
$.export("$summary", `Emails sent successfully to ${this.recipients.join(", ")}`);
34125
return response;
35126
},
36127
};
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
import elastic_email from "../../elastic_email.app.mjs";
2-
import { axios } from "@pipedream/platform";
1+
import { parseObject } from "../../common/utils.mjs";
2+
import app from "../../elastic_email.app.mjs";
33

44
export default {
55
key: "elastic_email-unsubscribe-contact",
66
name: "Unsubscribe Contact",
77
description: "Unsubscribes a contact from future emails. [See the documentation]()",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
11-
elastic_email,
12-
unsubscribeEmail: {
11+
app,
12+
unsubscribeEmails: {
1313
propDefinition: [
14-
"elastic_email",
15-
"unsubscribeEmail",
14+
app,
15+
"unsubscribeEmails",
1616
],
1717
},
1818
},
1919
async run({ $ }) {
20-
const response = await this.elastic_email.unsubscribeContact();
21-
$.export("$summary", `Unsubscribed contact ${this.unsubscribeEmail} successfully`);
20+
const parsedEmails = parseObject(this.unsubscribeEmails);
21+
const response = await this.app.unsubscribeContact({
22+
$,
23+
data: parsedEmails,
24+
});
25+
$.export("$summary", `Unsubscribed ${this.parsedEmails.length} contact(s) successfully`);
2226
return response;
2327
},
2428
};

components/elastic_email/app/elastic_email.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const LIMIT = 100;
2+
3+
export const STATUS_OPTIONS = [
4+
"Transactional",
5+
"Engaged",
6+
"Active",
7+
"Bounced",
8+
"Unsubscribed",
9+
"Abuse",
10+
"Inactive",
11+
"Stale",
12+
"NotConfirmed",
13+
];
14+
15+
export const ENCODING_OPTIONS = [
16+
"UserProvided",
17+
"None",
18+
"Raw7bit",
19+
"Raw8bit",
20+
"QuotedPrintable",
21+
"Base64",
22+
"Uue",
23+
];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

0 commit comments

Comments
 (0)