Skip to content

Commit 6ed10ea

Browse files
committed
new components
1 parent 2a63a63 commit 6ed10ea

File tree

7 files changed

+301
-20
lines changed

7 files changed

+301
-20
lines changed

components/elastic_email/actions/create-campaign/create-campaign.mjs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "elastic_email-create-campaign",
66
name: "Create Campaign",
77
description: "Create a campaign in an Elastic Email account. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#operation/campaignsPost)",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "action",
1010
annotations: {
1111
destructiveHint: false,
@@ -45,7 +45,12 @@ export default {
4545
type: "string",
4646
label: "Reply To",
4747
description: "To what address should the recipients reply to (e.g. John Doe email@domain.com)",
48-
optional: true,
48+
},
49+
status: {
50+
propDefinition: [
51+
app,
52+
"campaignStatus",
53+
],
4954
},
5055
subject: {
5156
type: "string",
@@ -60,12 +65,6 @@ export default {
6065
],
6166
optional: true,
6267
},
63-
status: {
64-
propDefinition: [
65-
app,
66-
"campaignStatus",
67-
],
68-
},
6968
excludeRecipientListNames: {
7069
propDefinition: [
7170
app,
Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import app from "../../elasticemail.app.mjs";
1+
import app from "../../elastic_email.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
23

34
export default {
45
key: "elastic_email-create-contact",
56
name: "Create Contact",
67
description: "Create a contact in an Elastic Email account. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#operation/contactsPost)",
7-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
89
type: "action",
910
annotations: {
1011
destructiveHint: false,
@@ -13,7 +14,50 @@ export default {
1314
},
1415
props: {
1516
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+
},
1646
},
17-
async run() {
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;
1862
},
1963
};

components/elastic_email/actions/create-segment/create-segment.mjs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "elastic_email-create-segment",
55
name: "Create Segment",
66
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.{{ts}}",
7+
version: "0.0.1",
88
type: "action",
99
annotations: {
1010
destructiveHint: false,
@@ -13,7 +13,26 @@ export default {
1313
},
1414
props: {
1515
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+
},
1626
},
17-
async run() {
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;
1837
},
1938
};

components/elastic_email/actions/update-campaign/update-campaign.mjs

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "elastic_email-update-campaign",
55
name: "Update Campaign",
66
description: "Update a campaign in an Elastic Email account. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#operation/campaignsByNamePut)",
7-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
88
type: "action",
99
annotations: {
1010
destructiveHint: true,
@@ -13,7 +13,122 @@ export default {
1313
},
1414
props: {
1515
app,
16+
campaign: {
17+
propDefinition: [
18+
app,
19+
"campaign",
20+
],
21+
},
22+
name: {
23+
type: "string",
24+
label: "Campaign Name",
25+
description: "The name of the campaign",
26+
optional: true,
27+
},
28+
from: {
29+
type: "string",
30+
label: "From",
31+
description: "Your e-mail with an optional name (e.g.: John Doe email@domain.com)",
32+
optional: true,
33+
},
34+
recipientListNames: {
35+
propDefinition: [
36+
app,
37+
"listNames",
38+
],
39+
label: "Recipient List Names",
40+
description: "Names of lists from your Account to read recipients from",
41+
},
42+
recipientSegmentNames: {
43+
propDefinition: [
44+
app,
45+
"segmentNames",
46+
],
47+
label: "Recipient Segment Names",
48+
description: "Names of segments from your Account to read recipients from",
49+
optional: true,
50+
},
51+
replyTo: {
52+
type: "string",
53+
label: "Reply To",
54+
description: "To what address should the recipients reply to (e.g. John Doe email@domain.com)",
55+
optional: true,
56+
},
57+
subject: {
58+
type: "string",
59+
label: "Subject",
60+
description: "Default subject of email",
61+
optional: true,
62+
},
63+
templateName: {
64+
propDefinition: [
65+
app,
66+
"templateName",
67+
],
68+
optional: true,
69+
},
70+
status: {
71+
propDefinition: [
72+
app,
73+
"campaignStatus",
74+
],
75+
optional: true,
76+
},
77+
excludeRecipientListNames: {
78+
propDefinition: [
79+
app,
80+
"listNames",
81+
],
82+
label: "Exclude Recipient List Names",
83+
description: "Names of lists from your Account to exclude from the campaign",
84+
},
85+
excludeRecipientSegmentNames: {
86+
propDefinition: [
87+
app,
88+
"segmentNames",
89+
],
90+
label: "Exclude Recipient Segment Names",
91+
description: "Names of segments from your Account to exclude from the campaign",
92+
optional: true,
93+
},
1694
},
17-
async run() {
95+
async run({ $ }) {
96+
const campaign = await this.app.getCampaign({
97+
$,
98+
campaign: this.campaign,
99+
});
100+
101+
const response = await this.app.updateCampaign({
102+
$,
103+
campaign: this.campaign,
104+
data: {
105+
Name: this.name || campaign.Name,
106+
Recipients: {
107+
ListNames: this.recipientListNames || campaign.Recipients.ListNames || undefined,
108+
SegmentNames: this.recipientSegmentNames || campaign.Recipients.SegmentNames || undefined,
109+
},
110+
Content: [
111+
{
112+
From: this.from || campaign.Content[0].From,
113+
ReplyTo: this.replyTo || campaign.Content[0].ReplyTo,
114+
Subject: this.subject || campaign.Content[0].Subject,
115+
TemplateName: this.templateName || campaign.Content[0].TemplateName,
116+
},
117+
],
118+
Status: this.status || campaign.Status,
119+
ExcludeRecipients: this.excludeRecipientListNames || this.excludeRecipientSegmentNames
120+
? {
121+
ListNames: this.excludeRecipientListNames
122+
|| campaign.ExcludeRecipients.ListNames
123+
|| undefined,
124+
SegmentNames: this.excludeRecipientSegmentNames
125+
|| campaign.ExcludeRecipients.SegmentNames
126+
|| undefined,
127+
}
128+
: undefined,
129+
},
130+
});
131+
$.export("$summary", "Campaign updated successfully");
132+
return response;
18133
},
19134
};
Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import app from "../../elastic_email.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
23

34
export default {
45
key: "elastic_email-update-contact",
56
name: "Update Contact",
67
description: "Update a contact in an Elastic Email account. [See the documentation](https://elasticemail.com/developers/api-documentation/rest-api#operation/contactsByEmailPut)",
7-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
89
type: "action",
910
annotations: {
1011
destructiveHint: true,
@@ -13,7 +14,42 @@ export default {
1314
},
1415
props: {
1516
app,
17+
contact: {
18+
propDefinition: [
19+
app,
20+
"contact",
21+
],
22+
},
23+
firstName: {
24+
type: "string",
25+
label: "First Name",
26+
description: "The first name of the contact",
27+
optional: true,
28+
},
29+
lastName: {
30+
type: "string",
31+
label: "Last Name",
32+
description: "The last name of the contact",
33+
optional: true,
34+
},
35+
customFields: {
36+
type: "object",
37+
label: "Custom Fields",
38+
description: "A key-value collection of custom contact fields which can be used in the system. Only already existing custom fields will be saved.",
39+
optional: true,
40+
},
1641
},
17-
async run() {
42+
async run({ $ }) {
43+
const response = await this.app.updateContact({
44+
$,
45+
contact: this.contact,
46+
data: {
47+
FirstName: this.firstName,
48+
LastName: this.lastName,
49+
CustomFields: parseObject(this.customFields),
50+
},
51+
});
52+
$.export("$summary", "Contact updated successfully");
53+
return response;
1854
},
1955
};

components/elastic_email/elastic_email.app.mjs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default {
5252
label: "Campaign",
5353
description: "The name of a campaign",
5454
async options({ page }) {
55-
const { campaigns } = await this.listCampaigns({
55+
const campaigns = await this.listCampaigns({
5656
params: {
5757
limit: LIMIT,
5858
offset: LIMIT * page,
@@ -66,7 +66,7 @@ export default {
6666
label: "Contact",
6767
description: "The email address of a contact",
6868
async options({ page }) {
69-
const { contacts } = await this.listContacts({
69+
const contacts = await this.listContacts({
7070
params: {
7171
limit: LIMIT,
7272
offset: LIMIT * page,
@@ -80,7 +80,7 @@ export default {
8080
label: "Segment Names",
8181
description: "The name of a segment",
8282
async options({ page }) {
83-
const { segments } = await this.listSegments({
83+
const segments = await this.listSegments({
8484
params: {
8585
limit: LIMIT,
8686
offset: LIMIT * page,
@@ -103,6 +103,22 @@ export default {
103103
"Cancelled",
104104
"Draft",
105105
],
106+
},
107+
contactStatus: {
108+
type: "string",
109+
label: "Contact Status",
110+
description: "The status of a contact",
111+
options: [
112+
"Transactional",
113+
"Engaged",
114+
"Active",
115+
"Bounced",
116+
"Unsubscribed",
117+
"Abuse",
118+
"Inactive",
119+
"Stale",
120+
"NotConfirmed",
121+
],
106122
optional: true,
107123
},
108124
},
@@ -124,6 +140,14 @@ export default {
124140
...opts,
125141
});
126142
},
143+
getCampaign({
144+
campaign, ...opts
145+
}) {
146+
return this._makeRequest({
147+
path: `/campaigns/${campaign}`,
148+
...opts,
149+
});
150+
},
127151
loadEvents(opts = {}) {
128152
return this._makeRequest({
129153
path: "/events",

0 commit comments

Comments
 (0)