Skip to content

Commit 38dac8f

Browse files
luancazarinecoderabbitai[bot]michelle0927
authored
New Components - icontact (#16870)
* icontact init * [Components] icontact #13263 Sources - New Contact (Instant) - Updated Contact (Instant) - Contact Subscribed (Instant) Actions - Create Contact - Create Message - Subscribe Contact List * pnpm update * Update components/icontact/actions/create-message/create-message.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update components/icontact/actions/create-contact/create-contact.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update components/icontact/actions/create-contact/create-contact.mjs * some adjusts --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: michelle0927 <michelle0927@users.noreply.github.com>
1 parent e06598a commit 38dac8f

File tree

17 files changed

+632
-20
lines changed

17 files changed

+632
-20
lines changed

components/icontact/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import { STATUS_OPTIONS } from "../../common/constants.mjs";
2+
import { checkWarnings } from "../../common/utils.mjs";
3+
import icontact from "../../icontact.app.mjs";
4+
5+
export default {
6+
key: "icontact-create-contact",
7+
name: "Create Contact",
8+
description: "Creates a new contact within the iContact account. [See the documentation](https://help.icontact.com/customers/s/article/Contacts-iContact-API?r=153&ui-knowledge-components-aura-actions.KnowledgeArticleVersionCreateDraftFromOnlineAction.createDraftFromOnlineArticle=1)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
icontact,
13+
email: {
14+
type: "string",
15+
label: "Email",
16+
description: "The contact's email address. **Note: The email address must be unique**.",
17+
},
18+
prefix: {
19+
type: "string",
20+
label: "Prefix",
21+
description: "The contact's salutation. **E.g. Miss**",
22+
optional: true,
23+
},
24+
firstName: {
25+
type: "string",
26+
label: "First Name",
27+
description: "The contact's first name.",
28+
optional: true,
29+
},
30+
lastName: {
31+
type: "string",
32+
label: "Last Name",
33+
description: "The contact's last name.",
34+
optional: true,
35+
},
36+
suffix: {
37+
type: "string",
38+
label: "Suffix",
39+
description: "The contact's name qualifications **E.g. III**.",
40+
optional: true,
41+
},
42+
street: {
43+
type: "string",
44+
label: "Street",
45+
description: "The contact's street address information.",
46+
optional: true,
47+
},
48+
street2: {
49+
type: "string",
50+
label: "Street 2",
51+
description: "The contact's line 2 information.",
52+
optional: true,
53+
},
54+
city: {
55+
type: "string",
56+
label: "City",
57+
description: "The contact's city information.",
58+
optional: true,
59+
},
60+
state: {
61+
type: "string",
62+
label: "State",
63+
description: "The contact's state information.",
64+
optional: true,
65+
},
66+
postalCode: {
67+
type: "string",
68+
label: "Postal Code",
69+
description: "The contact's postal code information.",
70+
optional: true,
71+
},
72+
phone: {
73+
type: "string",
74+
label: "Phone",
75+
description: "The contact's phone number.",
76+
optional: true,
77+
},
78+
fax: {
79+
type: "string",
80+
label: "Fax",
81+
description: "The contact's fax number.",
82+
optional: true,
83+
},
84+
business: {
85+
type: "string",
86+
label: "Business",
87+
description: "The contact's business phone number.",
88+
optional: true,
89+
},
90+
status: {
91+
type: "string",
92+
label: "Status",
93+
description: "The subscription status of the contact.",
94+
options: STATUS_OPTIONS,
95+
optional: true,
96+
},
97+
},
98+
async run({ $ }) {
99+
const {
100+
icontact,
101+
...contact
102+
} = this;
103+
104+
const { contacts } = await icontact.searchContact({
105+
params: {
106+
email: contact.email,
107+
},
108+
});
109+
110+
if (contacts.length) throw new Error("A contact with the provided email already exists.");
111+
112+
const response = await icontact.createContact({
113+
$,
114+
data: {
115+
contact,
116+
},
117+
});
118+
119+
checkWarnings(response);
120+
121+
$.export("$summary", `Successfully created contact with ID: ${response.contacts[0].contactId}`);
122+
return response.contacts[0];
123+
},
124+
};
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { MESSAGE_TYPE_OPTIONS } from "../../common/constants.mjs";
2+
import { checkWarnings } from "../../common/utils.mjs";
3+
import icontact from "../../icontact.app.mjs";
4+
5+
export default {
6+
key: "icontact-create-message",
7+
name: "Create and Dispatch Message",
8+
description: "Creates and dispatches a new message using custom HTML. [See the documentation](https://help.icontact.com/customers/s/article/Messages-iContact-API?r=153&ui-knowledge-components-aura-actions.KnowledgeArticleVersionCreateDraftFromOnlineAction.createDraftFromOnlineArticle=1)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
icontact,
13+
campaignId: {
14+
propDefinition: [
15+
icontact,
16+
"campaignId",
17+
],
18+
},
19+
messageType: {
20+
type: "string",
21+
label: "Message Type",
22+
description: "The kind of message being added.",
23+
options: MESSAGE_TYPE_OPTIONS,
24+
},
25+
subject: {
26+
type: "string",
27+
label: "Subject",
28+
description: "The subject line of the email.",
29+
},
30+
htmlBody: {
31+
type: "string",
32+
label: "HTML Body",
33+
description: "Contains the HTML version of the email message body.",
34+
optional: true,
35+
},
36+
textBody: {
37+
type: "string",
38+
label: "Text Body",
39+
description: "Contains the text version of the email message body.",
40+
optional: true,
41+
},
42+
messageName: {
43+
type: "string",
44+
label: "Message Name",
45+
description: "The reference name of the message. This is used for organizational purposes and will not be seen by your contacts.",
46+
optional: true,
47+
},
48+
previewText: {
49+
type: "string",
50+
label: "Preview Text",
51+
description: "Indicates the preview text that some email systems display before opening the email.",
52+
optional: true,
53+
},
54+
replyToCampaignId: {
55+
propDefinition: [
56+
icontact,
57+
"campaignId",
58+
],
59+
label: "Reply To Campaign Id",
60+
description: "Indicates the sender property where you want reply emails to be sent to.",
61+
optional: true,
62+
},
63+
},
64+
async run({ $ }) {
65+
const {
66+
icontact,
67+
...message
68+
} = this;
69+
70+
const response = await icontact.createMessage({
71+
$,
72+
data: {
73+
message,
74+
},
75+
});
76+
77+
checkWarnings(response);
78+
79+
$.export("$summary", `Successfully created message with ID: ${response.messages[0].messageId}`);
80+
return response.messages[0];
81+
},
82+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { checkWarnings } from "../../common/utils.mjs";
2+
import icontact from "../../icontact.app.mjs";
3+
4+
export default {
5+
key: "icontact-subscribe-contact-list",
6+
name: "Subscribe Contact to List",
7+
description: "Adds a contact to a specific list within iContact. [See the documentation](https://help.icontact.com/customers/s/article/Subscriptions-iContact-API?r=153&ui-knowledge-components-aura-actions.KnowledgeArticleVersionCreateDraftFromOnlineAction.createDraftFromOnlineArticle=1)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
icontact,
12+
contactId: {
13+
propDefinition: [
14+
icontact,
15+
"contactId",
16+
],
17+
},
18+
listId: {
19+
propDefinition: [
20+
icontact,
21+
"listId",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.icontact.subscribeContactToList({
27+
data: {
28+
subscription: {
29+
contactId: this.contactId,
30+
listId: this.listId,
31+
status: "normal",
32+
},
33+
},
34+
});
35+
36+
checkWarnings(response);
37+
38+
$.export("$summary", `Successfully created subscription with ID: ${response.subscriptions[0].subscriptionId}`);
39+
return response.subscriptions[0];
40+
},
41+
};

components/icontact/app/icontact.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export const STATUS_OPTIONS = [
2+
{
3+
label: "Normal - Contact can receive emails sent to them.",
4+
value: "normal",
5+
},
6+
{
7+
label: "Bounced - Contact is unreachable via email.",
8+
value: "bounced",
9+
},
10+
{
11+
label: "Do Not Contact - Contact is blocked from receiving emails.",
12+
value: "donotcontact",
13+
},
14+
{
15+
label: "Pending - Contact must confirm a subscription before receiving emails.",
16+
value: "pending",
17+
},
18+
{
19+
label: "Invitable - Contact must be sent an invitation message before receiving emails.",
20+
value: "invitable",
21+
},
22+
{
23+
label: "Deleted - Contact was deleted from your records",
24+
value: "deleted",
25+
},
26+
];
27+
28+
export const MESSAGE_TYPE_OPTIONS = [
29+
{
30+
label: "Normal - An email message.",
31+
value: "normal",
32+
},
33+
{
34+
label: "Confirmation - An email that requests a contact to confirm their subscription",
35+
value: "confirmation",
36+
},
37+
];

components/icontact/common/utils.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
3+
export const checkWarnings = (response) => {
4+
if (response.warnings) {
5+
throw new ConfigurationError(response.warnings[0]);
6+
}
7+
if (response.notices) {
8+
throw new ConfigurationError(response.notices[0]);
9+
}
10+
};

0 commit comments

Comments
 (0)