Skip to content

Commit 70c8723

Browse files
Acumbamail - new components (#19864)
* new components * pnpm-lock.yaml * Update components/acumbamail/actions/send-sms/send-sms.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent c6fb9fe commit 70c8723

File tree

12 files changed

+437
-92
lines changed

12 files changed

+437
-92
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import acumbamail from "../../acumbamail.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "acumbamail-add-or-update-subscriber",
6+
name: "Add or Update Subscriber",
7+
description: "Adds a new subscriber to a list or updates an existing subscriber. [See the documentation](https://acumbamail.com/en/apidoc/function/addSubscriber/)",
8+
version: "0.0.1",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
type: "action",
15+
props: {
16+
acumbamail,
17+
listId: {
18+
propDefinition: [
19+
acumbamail,
20+
"listId",
21+
],
22+
reloadProps: true,
23+
},
24+
doubleOptin: {
25+
type: "boolean",
26+
label: "Double Opt-in",
27+
description: "Activates sending of confirmation email when adding the subscriber",
28+
optional: true,
29+
},
30+
updateSubscriber: {
31+
type: "boolean",
32+
label: "Update Subscriber",
33+
description: "Modifies the fields in the case of a subscriber who is already on the list",
34+
optional: true,
35+
},
36+
mergeFields: {
37+
type: "object",
38+
label: "Merge Fields",
39+
description: "Optionally, add merge fields as a single object. This is a Dictionary that contains the merge tags of the subscriber as keys and the value that will be added to the subscriber",
40+
optional: true,
41+
},
42+
},
43+
async additionalProps() {
44+
const props = {};
45+
if (!this.listId) {
46+
return props;
47+
}
48+
const fields = await this.acumbamail.getFields({
49+
params: {
50+
list_id: this.listId,
51+
},
52+
});
53+
for (const key of Object.keys(fields)) {
54+
props[key] = {
55+
type: "string",
56+
label: key,
57+
optional: true,
58+
};
59+
}
60+
return props;
61+
},
62+
async run({ $ }) {
63+
const mergeFields = parseObject(this.mergeFields);
64+
const fields = await this.acumbamail.getFields({
65+
params: {
66+
list_id: this.listId,
67+
},
68+
});
69+
for (const key of Object.keys(fields)) {
70+
if (!this[key]) continue;
71+
mergeFields[key] = this[key];
72+
}
73+
74+
const response = await this.acumbamail.addOrUpdateSubscriber({
75+
$,
76+
data: {
77+
list_id: this.listId,
78+
double_optin: this.doubleOptin,
79+
update_subscriber: this.updateSubscriber,
80+
merge_fields: mergeFields,
81+
complete_json: true,
82+
},
83+
});
84+
85+
$.export("$summary", "Successfully added or updated subscriber.");
86+
return response;
87+
},
88+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import acumbamail from "../../acumbamail.app.mjs";
2+
3+
export default {
4+
key: "acumbamail-get-campaigns",
5+
name: "Get Campaigns",
6+
description: "Get a list of campaigns. [See the documentation](https://acumbamail.com/en/apidoc/function/getCampaigns/)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: true,
12+
},
13+
type: "action",
14+
props: {
15+
acumbamail,
16+
},
17+
async run({ $ }) {
18+
const response = await this.acumbamail.getCampaigns({
19+
$,
20+
params: {
21+
complete_json: true,
22+
},
23+
});
24+
$.export("$summary", "Successfully retrieved campaigns.");
25+
return response;
26+
},
27+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import acumbamail from "../../acumbamail.app.mjs";
2+
3+
export default {
4+
key: "acumbamail-send-sms",
5+
name: "Send SMS",
6+
description: "Send an SMS to a subscriber. [See the documentation](https://acumbamail.com/en/apidoc/function/sendSMS/)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: false,
12+
},
13+
type: "action",
14+
props: {
15+
acumbamail,
16+
recipient: {
17+
type: "string",
18+
label: "Recipient",
19+
description: "The phone number of the recipient. Example: `+1234567890`",
20+
},
21+
message: {
22+
type: "string",
23+
label: "Message",
24+
description: "The message to send",
25+
},
26+
sender: {
27+
type: "string",
28+
label: "Sender",
29+
description: "The name of the sender",
30+
},
31+
},
32+
async run({ $ }) {
33+
const response = await this.acumbamail.sendSMS({
34+
$,
35+
data: {
36+
messages: [
37+
{
38+
recipient: this.recipient,
39+
body: this.message,
40+
sender: this.sender,
41+
},
42+
],
43+
},
44+
});
45+
$.export("$summary", `Successfully sent SMS to ${this.recipient}`);
46+
return response;
47+
},
48+
};
Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,83 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "acumbamail",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
listId: {
8+
type: "string",
9+
label: "List ID",
10+
description: "The ID of a list",
11+
async options() {
12+
const lists = await this.getLists();
13+
const options = [];
14+
for (const [
15+
key,
16+
value,
17+
] of Object.entries(lists)) {
18+
options.push({
19+
label: value.name,
20+
value: key,
21+
});
22+
}
23+
return options;
24+
},
25+
},
26+
},
527
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
28+
_baseUrl() {
29+
return "https://acumbamail.com/api/1";
30+
},
31+
_makeRequest({
32+
$ = this, path, params, ...opts
33+
}) {
34+
return axios($, {
35+
url: `${this._baseUrl()}${path}`,
36+
params: {
37+
...params,
38+
auth_token: `${this.$auth.auth_token}`,
39+
},
40+
...opts,
41+
});
42+
},
43+
configureWebhook(opts = {}) {
44+
return this._makeRequest({
45+
method: "POST",
46+
path: "/configListWebhook/",
47+
...opts,
48+
});
49+
},
50+
getLists(opts = {}) {
51+
return this._makeRequest({
52+
path: "/getLists/",
53+
...opts,
54+
});
55+
},
56+
getFields(opts = {}) {
57+
return this._makeRequest({
58+
path: "/getFields/",
59+
...opts,
60+
});
61+
},
62+
getCampaigns(opts = {}) {
63+
return this._makeRequest({
64+
path: "/getCampaigns/",
65+
...opts,
66+
});
67+
},
68+
addOrUpdateSubscriber(opts = {}) {
69+
return this._makeRequest({
70+
method: "POST",
71+
path: "/addSubscriber/",
72+
...opts,
73+
});
74+
},
75+
sendSMS(opts = {}) {
76+
return this._makeRequest({
77+
method: "POST",
78+
path: "/sendSMS/",
79+
...opts,
80+
});
981
},
1082
},
1183
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return {};
3+
4+
if (typeof obj === "string") {
5+
try {
6+
return JSON.parse(obj);
7+
} catch (e) {
8+
return obj;
9+
}
10+
}
11+
if (Array.isArray(obj)) {
12+
return obj.map((item) => parseObject(item));
13+
}
14+
if (typeof obj === "object") {
15+
const newObj = {};
16+
for (const [
17+
key,
18+
value,
19+
] of Object.entries(obj)) {
20+
newObj[key] = parseObject(value);
21+
}
22+
return newObj;
23+
}
24+
return obj;
25+
};

components/acumbamail/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/acumbamail",
3-
"version": "0.0.4",
3+
"version": "0.1.0",
44
"description": "Pipedream Acumbamail Components",
55
"main": "acumbamail.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.1"
1417
}
1518
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import acumbamail from "../../acumbamail.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
import { EVENT_TYPES } from "./eventTypes.mjs";
4+
5+
export default {
6+
props: {
7+
acumbamail,
8+
http: {
9+
type: "$.interface.http",
10+
customResponse: true,
11+
},
12+
listId: {
13+
propDefinition: [
14+
acumbamail,
15+
"listId",
16+
],
17+
},
18+
},
19+
hooks: {
20+
async activate() {
21+
const eventTypes = EVENT_TYPES;
22+
eventTypes[this.getEventType()] = true;
23+
await this.acumbamail.configureWebhook({
24+
data: {
25+
list_id: this.listId,
26+
callback_url: this.http.endpoint,
27+
active: true,
28+
...eventTypes,
29+
},
30+
});
31+
},
32+
async deactivate() {
33+
await this.acumbamail.configureWebhook({
34+
data: {
35+
list_id: this.listId,
36+
callback_url: this.http.endpoint,
37+
active: false,
38+
},
39+
});
40+
},
41+
},
42+
methods: {
43+
getEventType() {
44+
throw new ConfigurationError("getEventType is not implemented");
45+
},
46+
generateMeta(event) {
47+
return {
48+
id: event.timestamp,
49+
summary: `New ${event.event} event`,
50+
ts: event.timestamp,
51+
};
52+
},
53+
},
54+
async run({ body }) {
55+
this.http.respond({
56+
status: 200,
57+
});
58+
59+
if (!body) return;
60+
61+
if (Array.isArray(body)) {
62+
for (const event of body) {
63+
this.$emit(event, this.generateMeta(event));
64+
}
65+
} else {
66+
this.$emit(body, this.generateMeta(body));
67+
}
68+
},
69+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const EVENT_TYPES = {
2+
subscribes: false,
3+
unsubscribes: false,
4+
hard_bounce: false,
5+
soft_bounce: false,
6+
complain: false,
7+
opens: false,
8+
click: false,
9+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import common from "../common/base-webhook.mjs";
2+
3+
export default {
4+
...common,
5+
key: "acumbamail-new-campaign-opened",
6+
name: "New Campaign Opened (Instant)",
7+
description: "Emit new event when a campaign is opened. Note: Only one webhook can be configured per list. [See the documentation](https://acumbamail.com/en/apidoc/function/configListWebhook/)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getEventType() {
14+
return "opens";
15+
},
16+
},
17+
};

0 commit comments

Comments
 (0)