Skip to content

Commit 5bfb2d4

Browse files
committed
[Components] selzy #16657
Sources - New Campaign - New Campaign Status (Instant) - New Subscriber (Instant) Actions - Create Subscriber - Send Campaign - Create Campaign
1 parent 9d9f86e commit 5bfb2d4

File tree

14 files changed

+620
-462
lines changed

14 files changed

+620
-462
lines changed
Lines changed: 115 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,133 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import {
3+
clearEmpty,
4+
parseObject,
5+
} from "../../common/utils.mjs";
16
import selzy from "../../selzy.app.mjs";
2-
import { axios } from "@pipedream/platform";
37

48
export default {
59
key: "selzy-create-email-campaign",
610
name: "Create Email Campaign",
711
description: "Creates a new email campaign. [See the documentation](https://selzy.com/en/support/api/messages/createcampaign/)",
8-
version: "0.0.{{ts}}",
12+
version: "0.0.1",
913
type: "action",
1014
props: {
1115
selzy,
12-
subject: {
13-
propDefinition: [
14-
selzy,
15-
"subject",
16-
],
17-
},
18-
senderName: {
19-
propDefinition: [
20-
selzy,
21-
"senderName",
22-
],
23-
},
24-
senderEmail: {
25-
propDefinition: [
26-
selzy,
27-
"senderEmail",
28-
],
29-
},
30-
messageContent: {
31-
propDefinition: [
32-
selzy,
33-
"messageContent",
34-
],
35-
},
36-
listId: {
37-
propDefinition: [
38-
selzy,
39-
"listId",
40-
],
16+
messageId: {
17+
type: "string",
18+
label: "Message ID",
19+
description: "Code of the message to be sent. The code returned by the **Create Email Message** method should be transferred.",
20+
optional: true,
21+
},
22+
startTime: {
23+
type: "string",
24+
label: "Start Time",
25+
description: "Campaign launch date and time in the \"YYYY-MM-DD hh:mm\" format, which do not exceed 100 days from the current date. If the argument is not set, the campaign starts immediately. The time zone specified in the settings of the user's personal account is applied. To explicitly specify a time zone, use the **Timezone** argument. To provide additional error protection, you should not schedule two sendings of the same message within an hour.",
26+
optional: true,
27+
},
28+
trackRead: {
29+
type: "boolean",
30+
label: "Track Read",
31+
description: "Whether to track the fact of reading the email message. The default value is `false` (do not track). If `true`, a link to a small image tracking the reference will be added to the email. The **Track Read** argument is ignored for SMS messages.",
32+
optional: true,
33+
},
34+
trackLinks: {
35+
type: "boolean",
36+
label: "Track Links",
37+
description: "To track whether there are any click-throughs in email messages, the default value is `false` (do not track). If `true`, all external links will be replaced with special ones that allow you to track the fact of a click-through, and then forward the user to the desired page. The **Track Links** argument is ignored for SMS messages.",
38+
optional: true,
39+
},
40+
contacts: {
41+
type: "string[]",
42+
label: "Contacts",
43+
description: "Email addresses (or phone numbers for sms messages) to which sending of a message should be limited. If this argument is absent, sending will be made to all contacts on the list for which the message is made (possibly, taking into account segmentation by tags). If the contacts argument is present, only those contacts that are on the list will be taken into account, while the other will be ignored. If there are too many addresses (phone numbers) for sending in the contacts parameter, the **Contacts URL** parameter can be used instead. You can't set both parameters at the same time",
44+
optional: true,
45+
},
46+
contactsUrl: {
47+
type: "string",
48+
label: "Contacts URL",
49+
description: "Instead of the contacts parameter containing the actual email addresses or phone numbers, in this parameter you can specify the URL of the file from which the addresses (phone numbers) will be read. The URL must start with \"http://\", \"https://\" or \"ftp://\". The file must contain one contact per string, without commas; strings must be separated by \"n\" or \"rn\" (Mac format — only \"r\" — not supported). The file can be deleted after the campaign has shifted to the 'scheduled' status.",
50+
optional: true,
51+
},
52+
trackGa: {
53+
type: "boolean",
54+
label: "Track GA",
55+
description: "Whether to enable Google Analytics integration for this campaign. Only explicitly indicated values are valid, default usage parameters are not applied. The default value is `false` (disabled).",
56+
optional: true,
57+
reloadProps: true,
58+
},
59+
gaMedium: {
60+
type: "string",
61+
label: "GA Medium",
62+
description: "Integration parameters with Google Analytics (valid if track_ga=1). Only explicitly indicated values are valid, default usage parameters are not applied.",
63+
optional: true,
64+
hidden: true,
65+
},
66+
gaSource: {
67+
type: "string",
68+
label: "GA Source",
69+
description: "Integration parameters with Google Analytics (valid if track_ga=1). Only explicitly indicated values are valid, default usage parameters are not applied.",
70+
optional: true,
71+
hidden: true,
72+
},
73+
gaCampaign: {
74+
type: "string",
75+
label: "GA Campaign",
76+
description: "Integration parameters with Google Analytics (valid if track_ga=1). Only explicitly indicated values are valid, default usage parameters are not applied.",
77+
optional: true,
78+
hidden: true,
79+
},
80+
gaContent: {
81+
type: "string",
82+
label: "GA Content",
83+
description: "Integration parameters with Google Analytics (valid if track_ga=1). Only explicitly indicated values are valid, default usage parameters are not applied.",
84+
optional: true,
85+
hidden: true,
86+
},
87+
gaTerm: {
88+
type: "string",
89+
label: "GA Term",
90+
description: "Integration parameters with Google Analytics (valid if track_ga=1). Only explicitly indicated values are valid, default usage parameters are not applied.",
91+
optional: true,
92+
hidden: true,
4193
},
4294
},
95+
async additionalProps(props) {
96+
const gaAllowed = this.trackGa;
97+
props.gaMedium.hidden = !gaAllowed;
98+
props.gaSource.hidden = !gaAllowed;
99+
props.gaCampaign.hidden = !gaAllowed;
100+
props.gaContent.hidden = !gaAllowed;
101+
props.gaTerm.hidden = !gaAllowed;
102+
103+
return {};
104+
},
43105
async run({ $ }) {
106+
if (this.contacts && this.contactsUrl) {
107+
throw new ConfigurationError("You can't set both contacts and contactsUrl parameters at the same time");
108+
}
109+
44110
const response = await this.selzy.createCampaign({
45-
subject: this.subject,
46-
sender_name: this.senderName,
47-
sender_email: this.senderEmail,
48-
message_content: this.messageContent,
49-
list_id: this.listId,
111+
$,
112+
params: clearEmpty({
113+
message_id: this.messageId,
114+
start_time: this.startTime,
115+
track_read: this.trackRead && +this.trackRead,
116+
track_links: this.trackLinks && +this.trackLinks,
117+
contacts: parseObject(this.contacts)?.join(","),
118+
contacts_url: this.contactsUrl,
119+
track_ga: this.trackGa && +this.trackGa,
120+
ga_medium: this.gaMedium,
121+
ga_source: this.gaSource,
122+
ga_campaign: this.gaCampaign,
123+
ga_content: this.gaContent,
124+
ga_term: this.gaTerm,
125+
}),
50126
});
51127

52-
$.export("$summary", `Successfully created email campaign with ID: ${response.campaign_id}`);
128+
if (response.error) throw new ConfigurationError(response.error);
129+
130+
$.export("$summary", `Successfully created email campaign with ID: ${response.result.campaign_id}`);
53131
return response;
54132
},
55133
};
Lines changed: 97 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,137 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import {
3+
MESSAGE_FORMAT_OPTIONS, WRAP_TYPE_OPTIONS,
4+
} from "../../common/constants.mjs";
5+
import { parseObject } from "../../common/utils.mjs";
16
import selzy from "../../selzy.app.mjs";
2-
import { axios } from "@pipedream/platform";
37

48
export default {
59
key: "selzy-create-email-message",
610
name: "Create Email Message",
711
description: "Adds a new email message. [See the documentation](https://selzy.com/en/support/category/api/messages/)",
8-
version: "0.0.{{ts}}",
12+
version: "0.0.1",
913
type: "action",
1014
props: {
1115
selzy,
1216
senderName: {
13-
propDefinition: [
14-
selzy,
15-
"senderName",
16-
],
17+
type: "string",
18+
label: "Sender's name",
19+
description: "It is a string that does not match the email address (the sender_email argument).",
1720
},
1821
senderEmail: {
19-
propDefinition: [
20-
selzy,
21-
"senderEmail",
22-
],
22+
type: "string",
23+
label: "Sender's email address",
24+
description: "This email must be checked (to do this, you need to manually create at least one email with this return address via the web interface, then click on the \"send the confirmation request\" link and follow the link from the email).",
2325
},
2426
subject: {
27+
type: "string",
28+
label: "Subject",
29+
description: "String with the letter subject. It may include [substitution fields](https://selzy.com/en/support/letter/other-functions/personalization-tags/). The parameter is optional if **Template Id** is indicated.",
30+
optional: true,
31+
},
32+
body: {
33+
type: "string",
34+
label: "Body",
35+
description: "If you transfer the entire HTML text, test such letters additionally as headers outside the body may be modified. The parameter is optional if **Template Id** or **System Template Id** is indicated.",
36+
},
37+
listId: {
2538
propDefinition: [
2639
selzy,
27-
"subject",
40+
"listId",
2841
],
2942
},
30-
body: {
43+
textBody: {
44+
type: "string",
45+
label: "Text Body",
46+
description: "Text version of the template. It is absent by default. If you do not provide the text version along with the HTML version, you are recommended to set the **Generate Text** parameter to 1 for automatic generation of the text part of the letter.",
47+
optional: true,
48+
},
49+
generateText: {
50+
type: "boolean",
51+
label: "Generate Text",
52+
description: "`True` means that the text part of the letter will be generated automatically based on the HTML part. If you do not provide the text version along with the HTML version, you are recommended to set the **Generate Text** parameter to `true` for automatic generation of the text part of the letter. If the text variant of the letter is provided using the **Text Body** parameter, the **Generate Text** parameter is ignored. Thus, if the **Generate Text** value has been set to `true`, the server's response will contain a warning.",
53+
optional: true,
54+
},
55+
rawBody: {
56+
type: "string",
57+
label: "Raw Body",
58+
description: "It is intended to save the json structure of the block editor data structure (if the value is **Message Format** = block) The parameter obtains only the JSON structure, otherwise it will not be transferred.",
59+
optional: true,
60+
},
61+
messageFormat: {
62+
type: "string",
63+
label: "Message Format",
64+
description: `It defines the manner of creating a letter.
65+
\n 1 - If you transfer the \`text\` value in this parameter and both the body and **Text Body** parameters are filled, the body parameter will be ignored, and the letter will be created from the data, transferred in the **Text Body** parameter.
66+
\n 2 - If you transfer the \`block\` value in this parameter but do not specify **Raw Body**, the letter will be saved as **Raw HTML**.
67+
\n 3 - If you transfer the \`block\` value in this parameter, the **body** and **Raw Body** parameters must be transferred so taht you can save the message in the block editor format.`,
68+
options: MESSAGE_FORMAT_OPTIONS,
69+
optional: true,
70+
},
71+
lang: {
72+
type: "string",
73+
label: "Lang",
74+
description: `Two-letter language code for the string with the unsubscribe link that is added to each letter automatically.
75+
If it is not specified, the language code from the API URL is used.
76+
In addition to the string with the unsubscribe link, this language also affects the interface of the unsubscribe page. Languages en, it, ua and ru are fully supported, and in case of some other languages (da, de, es, fr, nl, pl, pt, tr), the string with a link will be translated, and the control interface will be in English.`,
77+
optional: true,
78+
},
79+
templateId: {
3180
propDefinition: [
3281
selzy,
33-
"body",
82+
"templateId",
3483
],
84+
optional: true,
3585
},
36-
listId: {
86+
systemTemplateId: {
3787
propDefinition: [
3888
selzy,
39-
"listId",
89+
"systemTemplateId",
4090
],
91+
optional: true,
4192
},
42-
name: {
93+
wrapType: {
4394
type: "string",
44-
label: "Name",
45-
description: "The optional name for the email message",
95+
label: "Wrap Type",
96+
description: "Alignment of the message text on the specified side. If the argument is missing, the text will not be aligned.",
97+
options: WRAP_TYPE_OPTIONS,
4698
optional: true,
4799
},
48-
customFields: {
49-
type: "object",
50-
label: "Custom Fields",
51-
description: "Optional custom fields for the email message",
100+
categories: {
101+
type: "string[]",
102+
label: "Categories",
103+
description: "A list of letter categories.",
52104
optional: true,
53105
},
54106
},
55107
async run({ $ }) {
56-
const emailMessageData = {
57-
sender_name: this.senderName,
58-
sender_email: this.senderEmail,
59-
subject: this.subject,
60-
body: this.body,
61-
list_id: this.listId,
62-
};
63-
64-
if (this.name) {
65-
emailMessageData.name = this.name;
108+
if (this.templateId && this.systemTemplateId) {
109+
throw new ConfigurationError("You can only use one of the Template Id or System Template Id parameters.");
66110
}
111+
const response = await this.selzy.createEmailMessage({
112+
$,
113+
params: {
114+
sender_name: this.senderName,
115+
sender_email: this.senderEmail,
116+
subject: this.subject,
117+
body: this.body,
118+
list_id: this.listId,
67119

68-
if (this.customFields) {
69-
Object.assign(emailMessageData, this.customFields);
70-
}
120+
text_body: this.textBody,
121+
generate_text: +this.generateText,
122+
raw_body: this.rawBody,
123+
message_format: this.messageFormat,
124+
lang: this.lang,
125+
template_id: this.templateId,
126+
system_template_id: this.systemTemplateId,
127+
wrap_type: this.wrapType,
128+
categories: parseObject(this.categories)?.join(","),
129+
},
130+
});
71131

72-
const response = await this.selzy.createEmailMessage(emailMessageData);
132+
if (response.error) throw new ConfigurationError(response.error);
73133

74-
$.export("$summary", `Email message created successfully with ID ${response.message_id}.`);
134+
$.export("$summary", `Email message created successfully with ID ${response.result.message_id}.`);
75135
return response;
76136
},
77137
};

components/selzy/common/constants.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export const LIMIT = 100;
2+
3+
export const MESSAGE_FORMAT_OPTIONS = [
4+
{
5+
label: "Raw HTML",
6+
value: "raw_html",
7+
},
8+
{
9+
label: "Block",
10+
value: "block",
11+
},
12+
{
13+
label: "Text",
14+
value: "text",
15+
},
16+
];
17+
18+
export const WRAP_TYPE_OPTIONS = [
19+
{
20+
label: "Skip (Do not apply)",
21+
value: "skip",
22+
},
23+
{
24+
label: "Right (Right alignment)",
25+
value: "right",
26+
},
27+
{
28+
label: "Left (Left alignment)",
29+
value: "left",
30+
},
31+
{
32+
label: "Center (Center alignment)",
33+
value: "center",
34+
},
35+
];

0 commit comments

Comments
 (0)