Skip to content

Commit c076545

Browse files
authored
Elastic Email - new components (#18943)
* wip * new components * pnpm-lock.yaml * versions * improve description and validate from & replyTo props
1 parent 97853a1 commit c076545

File tree

18 files changed

+730
-16
lines changed

18 files changed

+730
-16
lines changed

components/elastic_email/actions/add-contact/add-contact.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default {
1010
key: "elastic_email-add-contact",
1111
name: "Add Contact to Mailing List",
1212
description: "Adds a new contact to a mailing list. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#operation/contactsPost)",
13-
version: "0.0.2",
13+
version: "0.0.3",
1414
annotations: {
1515
destructiveHint: false,
1616
openWorldHint: true,
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import app from "../../elastic_email.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
import { isValidEmailFormat } from "../../common/utils.mjs";
4+
5+
export default {
6+
key: "elastic_email-create-campaign",
7+
name: "Create Campaign",
8+
description: "Create a campaign in an Elastic Email account. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#operation/campaignsPost)",
9+
version: "0.0.1",
10+
type: "action",
11+
annotations: {
12+
destructiveHint: false,
13+
openWorldHint: true,
14+
readOnlyHint: false,
15+
},
16+
props: {
17+
app,
18+
name: {
19+
type: "string",
20+
label: "Campaign Name",
21+
description: "The name of the campaign",
22+
},
23+
from: {
24+
type: "string",
25+
label: "From",
26+
description: "Your e-mail with an optional name (e.g.: `email@domain.com` or `John Doe <email@domain.com>`)",
27+
},
28+
recipientListNames: {
29+
propDefinition: [
30+
app,
31+
"listNames",
32+
],
33+
label: "Recipient List Names",
34+
description: "Names of lists from your Account to read recipients from",
35+
},
36+
recipientSegmentNames: {
37+
propDefinition: [
38+
app,
39+
"segmentNames",
40+
],
41+
label: "Recipient Segment Names",
42+
description: "Names of segments from your Account to read recipients from",
43+
optional: true,
44+
},
45+
replyTo: {
46+
type: "string",
47+
label: "Reply To",
48+
description: "To what address should the recipients reply to (e.g. `email@domain.com` or `John Doe <email@domain.com>`)",
49+
},
50+
status: {
51+
propDefinition: [
52+
app,
53+
"campaignStatus",
54+
],
55+
},
56+
subject: {
57+
type: "string",
58+
label: "Subject",
59+
description: "Default subject of email",
60+
optional: true,
61+
},
62+
templateName: {
63+
propDefinition: [
64+
app,
65+
"templateName",
66+
],
67+
optional: true,
68+
},
69+
excludeRecipientListNames: {
70+
propDefinition: [
71+
app,
72+
"listNames",
73+
],
74+
label: "Exclude Recipient List Names",
75+
description: "Names of lists from your Account to exclude from the campaign",
76+
},
77+
excludeRecipientSegmentNames: {
78+
propDefinition: [
79+
app,
80+
"segmentNames",
81+
],
82+
label: "Exclude Recipient Segment Names",
83+
description: "Names of segments from your Account to exclude from the campaign",
84+
optional: true,
85+
},
86+
},
87+
async run({ $ }) {
88+
if (this.from && !isValidEmailFormat(this.from)) {
89+
throw new ConfigurationError("Invalid email format for 'From'");
90+
}
91+
if (this.replyTo && !isValidEmailFormat(this.replyTo)) {
92+
throw new ConfigurationError("Invalid email format for 'Reply To'");
93+
}
94+
95+
if (!this.recipientListNames && !this.recipientSegmentNames) {
96+
throw new ConfigurationError("You must provide at least one list or segment to read recipients from");
97+
}
98+
99+
const response = await this.app.createCampaign({
100+
$,
101+
data: {
102+
Name: this.name,
103+
Recipients: {
104+
ListNames: this.recipientListNames,
105+
SegmentNames: this.recipientSegmentNames,
106+
},
107+
Content: [
108+
{
109+
From: this.from,
110+
ReplyTo: this.replyTo,
111+
Subject: this.subject,
112+
TemplateName: this.templateName,
113+
},
114+
],
115+
Status: this.status,
116+
ExcludeRecipients: this.excludeRecipientListNames || this.excludeRecipientSegmentNames
117+
? {
118+
ListNames: this.excludeRecipientListNames,
119+
SegmentNames: this.excludeRecipientSegmentNames,
120+
}
121+
: undefined,
122+
},
123+
});
124+
$.export("$summary", "Campaign created successfully");
125+
return response;
126+
},
127+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import app from "../../elastic_email.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "elastic_email-create-contact",
6+
name: "Create Contact",
7+
description: "Create a contact in an Elastic Email account. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#operation/contactsPost)",
8+
version: "0.0.1",
9+
type: "action",
10+
annotations: {
11+
destructiveHint: false,
12+
openWorldHint: true,
13+
readOnlyHint: false,
14+
},
15+
props: {
16+
app,
17+
email: {
18+
type: "string",
19+
label: "Email",
20+
description: "The email of the contact",
21+
},
22+
status: {
23+
propDefinition: [
24+
app,
25+
"contactStatus",
26+
],
27+
},
28+
firstName: {
29+
type: "string",
30+
label: "First Name",
31+
description: "The first name of the contact",
32+
optional: true,
33+
},
34+
lastName: {
35+
type: "string",
36+
label: "Last Name",
37+
description: "The last name of the contact",
38+
optional: true,
39+
},
40+
customFields: {
41+
type: "object",
42+
label: "Custom Fields",
43+
description: "A key-value collection of custom contact fields which can be used in the system. Only already existing custom fields will be saved.",
44+
optional: true,
45+
},
46+
},
47+
async run({ $ }) {
48+
const response = await this.app.createContact({
49+
$,
50+
data: [
51+
{
52+
Email: this.email,
53+
Status: this.status,
54+
FirstName: this.firstName,
55+
LastName: this.lastName,
56+
CustomFields: parseObject(this.customFields),
57+
},
58+
],
59+
});
60+
$.export("$summary", "Contact created successfully");
61+
return response;
62+
},
63+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import app from "../../elastic_email.app.mjs";
2+
3+
export default {
4+
key: "elastic_email-create-segment",
5+
name: "Create Segment",
6+
description: "Create a segment in an Elastic Email account. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#tag/Segments)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
props: {
15+
app,
16+
name: {
17+
type: "string",
18+
label: "Segment Name",
19+
description: "The name of the segment",
20+
},
21+
rule: {
22+
type: "string",
23+
label: "Rule",
24+
description: "SQL-like rule to determine which Contacts belong to this Segment. Help for building a segment rule can be found [here](https://help.elasticemail.com/en/articles/5162182-segment-rules)",
25+
},
26+
},
27+
async run({ $ }) {
28+
const response = await this.app.createSegment({
29+
$,
30+
data: {
31+
Name: this.name,
32+
Rule: this.rule,
33+
},
34+
});
35+
$.export("$summary", "Segment created successfully");
36+
return response;
37+
},
38+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import app from "../../elastic_email.app.mjs";
2+
3+
export default {
4+
key: "elastic_email-list-campaigns",
5+
name: "List Campaigns",
6+
description: "List campaigns in an Elastic Email account. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#operation/campaignsGet)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
app,
16+
search: {
17+
type: "string",
18+
label: "Search",
19+
description: "The search query to filter campaigns",
20+
optional: true,
21+
},
22+
limit: {
23+
type: "integer",
24+
label: "Limit",
25+
description: "The maximum number of campaigns to return",
26+
default: 100,
27+
optional: true,
28+
},
29+
offset: {
30+
type: "integer",
31+
label: "Offset",
32+
description: "The offset to start from",
33+
default: 0,
34+
optional: true,
35+
},
36+
},
37+
async run({ $ }) {
38+
const response = await this.app.listCampaigns({
39+
$,
40+
params: {
41+
search: this.search,
42+
limit: this.limit,
43+
offset: this.offset,
44+
},
45+
});
46+
$.export("$summary", `Successfully listed ${response?.length} campaigns.`);
47+
return response;
48+
},
49+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import app from "../../elastic_email.app.mjs";
2+
3+
export default {
4+
key: "elastic_email-list-contacts",
5+
name: "List Contacts",
6+
description: "List contacts in an Elastic Email account. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#operation/contactsGet)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
app,
16+
limit: {
17+
type: "integer",
18+
label: "Limit",
19+
description: "The maximum number of contacts to return",
20+
default: 100,
21+
optional: true,
22+
},
23+
offset: {
24+
type: "integer",
25+
label: "Offset",
26+
description: "The offset to start from",
27+
default: 0,
28+
optional: true,
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.app.listContacts({
33+
$,
34+
params: {
35+
limit: this.limit,
36+
offset: this.offset,
37+
},
38+
});
39+
$.export("$summary", `Successfully listed ${response?.length} contacts.`);
40+
return response;
41+
},
42+
};

components/elastic_email/actions/send-email/send-email.mjs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ import {
22
BODY_CONTENT_TYPE_OPTIONS,
33
ENCODING_OPTIONS,
44
} from "../../common/constants.mjs";
5-
import { parseObject } from "../../common/utils.mjs";
5+
import {
6+
parseObject, isValidEmailFormat,
7+
} from "../../common/utils.mjs";
8+
import { ConfigurationError } from "@pipedream/platform";
69
import app from "../../elastic_email.app.mjs";
710

811
export default {
912
key: "elastic_email-send-email",
1013
name: "Send Email",
1114
description: "Sends an email to one or more recipients. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#operation/emailsPost)",
12-
version: "0.0.2",
15+
version: "0.0.3",
1316
annotations: {
1417
destructiveHint: false,
1518
openWorldHint: true,
@@ -26,7 +29,7 @@ export default {
2629
from: {
2730
type: "string",
2831
label: "From",
29-
description: "Your e-mail with an optional name (e.g.: email@domain.com)",
32+
description: "Your e-mail with an optional name (e.g.: `email@domain.com` or `John Doe <email@domain.com>`)",
3033
},
3134
bodyContentType: {
3235
type: "string",
@@ -50,7 +53,7 @@ export default {
5053
replyTo: {
5154
type: "string",
5255
label: "Reply To",
53-
description: "To what address should the recipients reply to (e.g. email@domain.com)",
56+
description: "To what address should the recipients reply to (e.g. `email@domain.com` or `John Doe <email@domain.com>`)",
5457
optional: true,
5558
},
5659
subject: {
@@ -105,6 +108,13 @@ export default {
105108
},
106109
},
107110
async run({ $ }) {
111+
if (this.from && !isValidEmailFormat(this.from)) {
112+
throw new ConfigurationError("Invalid email format for 'From'");
113+
}
114+
if (this.replyTo && !isValidEmailFormat(this.replyTo)) {
115+
throw new ConfigurationError("Invalid email format for 'Reply To'");
116+
}
117+
108118
const response = await this.app.sendBulkEmails({
109119
$,
110120
data: {

components/elastic_email/actions/unsubscribe-contact/unsubscribe-contact.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "elastic_email-unsubscribe-contact",
66
name: "Unsubscribe Contact",
77
description: "Unsubscribes a contact from future emails. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#operation/suppressionsUnsubscribesPost)",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
annotations: {
1010
destructiveHint: true,
1111
openWorldHint: true,

0 commit comments

Comments
 (0)