Skip to content

Commit 3465789

Browse files
New Components - selzy (#16692)
* selzy init * [Components] selzy #16657 Sources - New Campaign - New Campaign Status (Instant) - New Subscriber (Instant) Actions - Create Subscriber - Send Campaign - Create Campaign * pnpm update * pnpm update * some adjusts * some adjusts * some adjusts * Update components/selzy/actions/create-campaign/create-campaign.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update components/selzy/sources/new-campaign/new-campaign.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * lint fix --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 3047069 commit 3465789

File tree

14 files changed

+748
-8
lines changed

14 files changed

+748
-8
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { clearEmpty } from "../../common/utils.mjs";
3+
import selzy from "../../selzy.app.mjs";
4+
5+
export default {
6+
key: "selzy-create-campaign",
7+
name: "Create Campaign",
8+
description: "Creates a new campaign. [See the documentation](https://selzy.com/en/support/api/messages/createcampaign/)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
selzy,
13+
messageId: {
14+
type: "string",
15+
label: "Message ID",
16+
description: "Code of the message to be sent. The code returned by the **Create Email Message** method should be transferred.",
17+
optional: true,
18+
},
19+
startTime: {
20+
type: "string",
21+
label: "Start Time",
22+
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.",
23+
optional: true,
24+
},
25+
trackRead: {
26+
type: "boolean",
27+
label: "Track Read",
28+
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.",
29+
optional: true,
30+
},
31+
trackLinks: {
32+
type: "boolean",
33+
label: "Track Links",
34+
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.",
35+
optional: true,
36+
},
37+
contactsUrl: {
38+
type: "string",
39+
label: "Contacts URL",
40+
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.",
41+
optional: true,
42+
},
43+
trackGa: {
44+
type: "boolean",
45+
label: "Track GA",
46+
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).",
47+
optional: true,
48+
reloadProps: true,
49+
},
50+
gaMedium: {
51+
type: "string",
52+
label: "GA Medium",
53+
description: "Integration parameters with Google Analytics (valid if track_ga=1). Only explicitly indicated values are valid, default usage parameters are not applied.",
54+
optional: true,
55+
hidden: true,
56+
},
57+
gaSource: {
58+
type: "string",
59+
label: "GA Source",
60+
description: "Integration parameters with Google Analytics (valid if track_ga=1). Only explicitly indicated values are valid, default usage parameters are not applied.",
61+
optional: true,
62+
hidden: true,
63+
},
64+
gaCampaign: {
65+
type: "string",
66+
label: "GA Campaign",
67+
description: "Integration parameters with Google Analytics (valid if track_ga=1). Only explicitly indicated values are valid, default usage parameters are not applied.",
68+
optional: true,
69+
hidden: true,
70+
},
71+
gaContent: {
72+
type: "string",
73+
label: "GA Content",
74+
description: "Integration parameters with Google Analytics (valid if track_ga=1). Only explicitly indicated values are valid, default usage parameters are not applied.",
75+
optional: true,
76+
hidden: true,
77+
},
78+
gaTerm: {
79+
type: "string",
80+
label: "GA Term",
81+
description: "Integration parameters with Google Analytics (valid if track_ga=1). Only explicitly indicated values are valid, default usage parameters are not applied.",
82+
optional: true,
83+
hidden: true,
84+
},
85+
},
86+
async additionalProps(props) {
87+
const gaAllowed = this.trackGa;
88+
props.gaMedium.hidden = !gaAllowed;
89+
props.gaSource.hidden = !gaAllowed;
90+
props.gaCampaign.hidden = !gaAllowed;
91+
props.gaContent.hidden = !gaAllowed;
92+
props.gaTerm.hidden = !gaAllowed;
93+
94+
return {};
95+
},
96+
async run({ $ }) {
97+
if (this.contacts && this.contactsUrl) {
98+
throw new ConfigurationError("You can't set both contacts and contactsUrl parameters at the same time");
99+
}
100+
101+
const response = await this.selzy.createCampaign({
102+
$,
103+
params: clearEmpty({
104+
message_id: this.messageId,
105+
start_time: this.startTime,
106+
track_read: this.trackRead
107+
? 1
108+
: 0,
109+
track_links: this.trackLinks
110+
? 1
111+
: 0,
112+
contacts_url: this.contactsUrl,
113+
track_ga: this.trackGa && +this.trackGa,
114+
ga_medium: this.gaMedium,
115+
ga_source: this.gaSource,
116+
ga_campaign: this.gaCampaign,
117+
ga_content: this.gaContent,
118+
ga_term: this.gaTerm,
119+
}),
120+
});
121+
122+
if (response.error) throw new ConfigurationError(response.error);
123+
124+
$.export("$summary", `Successfully created email campaign with ID: ${response.result.campaign_id}`);
125+
return response;
126+
},
127+
};
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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";
6+
import selzy from "../../selzy.app.mjs";
7+
8+
export default {
9+
key: "selzy-create-email-message",
10+
name: "Create Email Message",
11+
description: "Adds a new email message. [See the documentation](https://selzy.com/en/support/category/api/messages/)",
12+
version: "0.0.1",
13+
type: "action",
14+
props: {
15+
selzy,
16+
senderName: {
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).",
20+
},
21+
senderEmail: {
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).",
25+
},
26+
subject: {
27+
type: "string",
28+
label: "Subject",
29+
description: "String with the letter subject. It may include substitution fields. If you wish to use substitution fields, specify a string within a Pipedream Custom Expression and escape the curly brackets with a backslash. For example: `{{ \"Welcome to Our Newsletter, \\{\\{Name\\}\\}!\" }}`. The parameter is optional if Template Id is indicated.",
30+
},
31+
body: {
32+
type: "string",
33+
label: "Body",
34+
description: "HTML body of the letter. It may include substitution fields. If you wish to use substitution fields, specify an HTML string within a Pipedream Custom Expression and escape the curly brackets with a backslash. For example: `{{ \"<p>Hello \\{\\{Name\\}\\},</p><p>Here is your update.</p>\" }}`.",
35+
},
36+
listId: {
37+
propDefinition: [
38+
selzy,
39+
"listId",
40+
],
41+
},
42+
textBody: {
43+
type: "string",
44+
label: "Text Body",
45+
description: "Text body of the letter. It may include substitution fields. If you wish to use substitution fields, specify a text string within a Pipedream Custom Expression and escape the curly brackets with a backslash. For example: `{{ \"Hello \\{\\{Name\\}\\},\\nHere is your update.\" }}`.",
46+
optional: true,
47+
},
48+
generateText: {
49+
type: "boolean",
50+
label: "Generate Text",
51+
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.",
52+
},
53+
rawBody: {
54+
type: "string",
55+
label: "Raw Body",
56+
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.",
57+
optional: true,
58+
},
59+
messageFormat: {
60+
type: "string",
61+
label: "Message Format",
62+
description: `It defines the manner of creating a letter.
63+
\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.
64+
\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**.
65+
\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.`,
66+
options: MESSAGE_FORMAT_OPTIONS,
67+
optional: true,
68+
},
69+
lang: {
70+
type: "string",
71+
label: "Lang",
72+
description: `Two-letter language code for the string with the unsubscribe link that is added to each letter automatically.
73+
If it is not specified, the language code from the API URL is used.
74+
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.`,
75+
optional: true,
76+
},
77+
templateId: {
78+
propDefinition: [
79+
selzy,
80+
"templateId",
81+
],
82+
optional: true,
83+
},
84+
systemTemplateId: {
85+
propDefinition: [
86+
selzy,
87+
"systemTemplateId",
88+
],
89+
optional: true,
90+
},
91+
wrapType: {
92+
type: "string",
93+
label: "Wrap Type",
94+
description: "Alignment of the message text on the specified side. If the argument is missing, the text will not be aligned.",
95+
options: WRAP_TYPE_OPTIONS,
96+
optional: true,
97+
},
98+
categories: {
99+
type: "string[]",
100+
label: "Categories",
101+
description: "A list of letter categories.",
102+
optional: true,
103+
},
104+
},
105+
async run({ $ }) {
106+
if (this.templateId && this.systemTemplateId) {
107+
throw new ConfigurationError("You can only use one of the Template Id or System Template Id parameters.");
108+
}
109+
const response = await this.selzy.createEmailMessage({
110+
$,
111+
params: {
112+
sender_name: this.senderName,
113+
sender_email: this.senderEmail,
114+
subject: this.subject,
115+
body: this.body,
116+
list_id: this.listId,
117+
118+
text_body: this.textBody,
119+
generate_text: +this.generateText,
120+
raw_body: this.rawBody,
121+
message_format: this.messageFormat,
122+
lang: this.lang,
123+
template_id: this.templateId,
124+
system_template_id: this.systemTemplateId,
125+
wrap_type: this.wrapType,
126+
categories: parseObject(this.categories)?.join(","),
127+
},
128+
});
129+
130+
if (response.error) throw new ConfigurationError(response.error);
131+
132+
$.export("$summary", `Email message created successfully with ID ${response.result.message_id}.`);
133+
return response;
134+
},
135+
};
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+
];

components/selzy/common/utils.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
};
25+
26+
export const clearEmpty = (obj) => {
27+
if (!obj) return undefined;
28+
29+
const newObj = {
30+
...obj,
31+
};
32+
Object.keys(newObj).forEach((key) => {
33+
if (newObj[key] === "" || newObj[key] === null || newObj[key] === undefined) {
34+
delete newObj[key];
35+
}
36+
});
37+
return newObj;
38+
};

components/selzy/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/selzy",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Selzy Components",
55
"main": "selzy.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)