Skip to content

Commit d00d425

Browse files
committed
[ACTION] Clevertap new campaign components
1 parent 26b2da6 commit d00d425

File tree

10 files changed

+330
-19
lines changed

10 files changed

+330
-19
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import app from "../../clevertap.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "clevertap-create-campaign",
6+
name: "Create Campaign",
7+
description: "Create a campaign. [See the documentation](https://developer.clevertap.com/docs/create-campaign-api)",
8+
version: "0.0.8",
9+
type: "action",
10+
props: {
11+
app,
12+
name: {
13+
type: "string",
14+
label: "Campaign Name",
15+
description: "The name of your campaign shown in the CleverTap dashboard.",
16+
},
17+
providerNickName: {
18+
type: "string",
19+
label: "Provider Nickname",
20+
description: "Allows you to specify which vendor/provider to use for your campaign. Required for WhatsApp and SMS.",
21+
},
22+
where: {
23+
type: "object",
24+
label: "Where",
25+
description: `Allows you to filter target base on the user events and profile properties. Send an empty object ({}) to target your entire user base. **Example:**
26+
\`\`\`
27+
{
28+
"event_name": "Charged",
29+
"from": 20171001,
30+
"to": 20171220,
31+
"common_profile_properties": {
32+
"profile_fields": [
33+
{
34+
"property_name": "Country",
35+
"operator": "equals",
36+
"property_value": "US"
37+
}
38+
]
39+
}
40+
}
41+
\`\`\``,
42+
optional: true,
43+
},
44+
contentSubject: {
45+
type: "string",
46+
label: "Content Subject",
47+
description: "The subject line of your email.",
48+
optional: true,
49+
},
50+
contentBody: {
51+
type: "string",
52+
label: "Content Body",
53+
description: "The body of your message. Can be plain text or HTML for emails.",
54+
optional: true,
55+
},
56+
contentSenderName: {
57+
type: "string",
58+
label: "Content Sender Name",
59+
description: "The sender name for your email.",
60+
optional: true,
61+
},
62+
when: {
63+
type: "object",
64+
label: "When",
65+
description: `Allows you to set Date, time and Delivery preferences of the message. **Example:**
66+
\`\`\`
67+
{
68+
"type": "later",
69+
"delivery_date_time": ["20230503 15:20"],
70+
"delivery_timezone": "user",
71+
"user_timezone_wrap_around": true,
72+
"dnd": {
73+
"message_state": "delay",
74+
"dnd_timezone": "user"
75+
},
76+
"campaign_cutoff": "14:20"
77+
}
78+
\`\`\``,
79+
optional: true,
80+
},
81+
},
82+
async run({ $ }) {
83+
const {
84+
app,
85+
name,
86+
providerNickName,
87+
when,
88+
where,
89+
contentSubject,
90+
contentBody,
91+
contentSenderName,
92+
} = this;
93+
94+
const response = await app.createCampaign({
95+
$,
96+
data: {
97+
name,
98+
provider_nick_name: providerNickName,
99+
when: utils.parseJson(when) || {},
100+
where: utils.parseJson(where) || {},
101+
...(
102+
contentSubject
103+
|| contentBody
104+
|| contentSenderName
105+
? {
106+
content: {
107+
subject: contentSubject,
108+
body: contentBody,
109+
sender_name: contentSenderName,
110+
},
111+
}
112+
: {}
113+
),
114+
},
115+
});
116+
117+
$.export("$summary", "Successfully created campaign");
118+
119+
return response;
120+
},
121+
};

components/clevertap/actions/create-or-update-user/create-or-update-user.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import app from "../../clevertap.app.mjs";
22

33
export default {
44
name: "Create Or Update User",
5-
version: "0.0.1",
5+
version: "0.0.2",
66
key: "clevertap-create-or-update-user",
77
description: "Create or update an user. [See the documentation](https://developer.clevertap.com/docs/upload-user-profiles-api)",
88
type: "action",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import app from "../../clevertap.app.mjs";
2+
3+
export default {
4+
key: "clevertap-get-campaign-report",
5+
name: "Get Campaign Report",
6+
description: "Get the report for a completed campaign. [See the documentation](https://developer.clevertap.com/docs/get-campaign-report-api)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
campaignId: {
12+
description: "The ID of the campaign to retrieve the report for.",
13+
propDefinition: [
14+
app,
15+
"campaignId",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const {
21+
app,
22+
campaignId,
23+
} = this;
24+
25+
const response = await app.getCampaignReport({
26+
$,
27+
data: {
28+
id: campaignId,
29+
},
30+
});
31+
32+
$.export("$summary", "Successfully retrieved report for campaign");
33+
34+
return response;
35+
},
36+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import app from "../../clevertap.app.mjs";
2+
3+
export default {
4+
key: "clevertap-get-campaigns",
5+
name: "Get Campaigns",
6+
description: "Get a list of campaigns within a specified date range. [See the documentation](https://developer.clevertap.com/docs/get-campaigns-api)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
from: {
12+
type: "string",
13+
label: "From Date",
14+
description: "Start of the date range for which you want to retrieve campaigns. Use `YYYYMMDD` format.",
15+
},
16+
to: {
17+
type: "string",
18+
label: "To Date",
19+
description: "End of the date range for which you want to retrieve campaigns. Use `YYYYMMDD` format.",
20+
},
21+
},
22+
async run({ $ }) {
23+
const {
24+
app,
25+
from,
26+
to,
27+
} = this;
28+
29+
const response = await app.getCampaigns({
30+
$,
31+
data: {
32+
from,
33+
to,
34+
},
35+
});
36+
37+
$.export("$summary", "Successfully retrieved campaigns");
38+
39+
return response;
40+
},
41+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import app from "../../clevertap.app.mjs";
2+
3+
export default {
4+
key: "clevertap-stop-campaign",
5+
name: "Stop Campaign",
6+
description: "Stop a running campaign. [See the documentation](https://developer.clevertap.com/docs/stop-campaign-api)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
campaignId: {
12+
propDefinition: [
13+
app,
14+
"campaignId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const {
20+
app,
21+
campaignId,
22+
} = this;
23+
24+
const response = await app.stopCampaign({
25+
$,
26+
data: {
27+
id: campaignId,
28+
},
29+
});
30+
31+
$.export("$summary", "Successfully stopped campaign");
32+
33+
return response;
34+
},
35+
};

components/clevertap/actions/upload-events/upload-events.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import app from "../../clevertap.app.mjs";
22

33
export default {
44
name: "Upload Events",
5-
version: "0.0.1",
5+
version: "0.0.2",
66
key: "clevertap-upload-events",
77
description: "Upload events. [See the documentation](https://developer.clevertap.com/docs/upload-events-api)",
88
type: "action",

components/clevertap/clevertap.app.mjs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,22 @@ import { axios } from "@pipedream/platform";
33
export default {
44
type: "app",
55
app: "clevertap",
6-
propDefinitions: {},
6+
propDefinitions: {
7+
campaignId: {
8+
type: "integer",
9+
label: "Campaign ID",
10+
description: "The ID of the campaign you want to stop.",
11+
async options() {
12+
const { targets } = await this.getCampaigns();
13+
return targets?.map(({
14+
id, name,
15+
}) => ({
16+
label: name,
17+
value: id,
18+
})) || [];
19+
},
20+
},
21+
},
722
methods: {
823
_projectId() {
924
return this.$auth.project_id;
@@ -17,7 +32,7 @@ export default {
1732
_apiUrl() {
1833
return `https://${this._region()}.clevertap.com/1`;
1934
},
20-
async _makeRequest({
35+
_makeRequest({
2136
$ = this, path, ...args
2237
}) {
2338
return axios($, {
@@ -30,7 +45,35 @@ export default {
3045
},
3146
});
3247
},
33-
async uploadEvent(args = {}) {
48+
getCampaigns(args = {}) {
49+
return this._makeRequest({
50+
path: "/targets/list.json",
51+
method: "post",
52+
...args,
53+
});
54+
},
55+
createCampaign(args = {}) {
56+
return this._makeRequest({
57+
path: "/targets/create.json",
58+
method: "post",
59+
...args,
60+
});
61+
},
62+
getCampaignReport(args = {}) {
63+
return this._makeRequest({
64+
path: "/targets/result.json",
65+
method: "post",
66+
...args,
67+
});
68+
},
69+
stopCampaign(args = {}) {
70+
return this._makeRequest({
71+
path: "/targets/stop.json",
72+
method: "post",
73+
...args,
74+
});
75+
},
76+
uploadEvent(args = {}) {
3477
return this._makeRequest({
3578
path: "/upload",
3679
method: "post",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const parseJson = (input, maxDepth = 100) => {
2+
const seen = new WeakSet();
3+
const parse = (value) => {
4+
if (maxDepth <= 0) {
5+
return value;
6+
}
7+
if (typeof(value) === "string") {
8+
// Only parse if the string looks like a JSON object or array
9+
const trimmed = value.trim();
10+
if (
11+
(trimmed.startsWith("{") && trimmed.endsWith("}")) ||
12+
(trimmed.startsWith("[") && trimmed.endsWith("]"))
13+
) {
14+
try {
15+
return parseJson(JSON.parse(value), maxDepth - 1);
16+
} catch (e) {
17+
return value;
18+
}
19+
}
20+
return value;
21+
} else if (typeof(value) === "object" && value !== null && !Array.isArray(value)) {
22+
if (seen.has(value)) {
23+
return value;
24+
}
25+
seen.add(value);
26+
return Object.entries(value)
27+
.reduce((acc, [
28+
key,
29+
val,
30+
]) => Object.assign(acc, {
31+
[key]: parse(val),
32+
}), {});
33+
} else if (Array.isArray(value)) {
34+
return value.map((item) => parse(item));
35+
}
36+
return value;
37+
};
38+
39+
return parse(input);
40+
};
41+
42+
export default {
43+
parseJson,
44+
};

components/clevertap/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/clevertap",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream CleverTap Components",
55
"main": "clevertap.app.mjs",
66
"keywords": [
@@ -13,6 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^1.5.1"
16+
"@pipedream/platform": "^3.1.0"
1717
}
1818
}

0 commit comments

Comments
 (0)