Skip to content

Commit d6497c5

Browse files
committed
SMSlink: New action components
1 parent e5ad5d4 commit d6497c5

File tree

8 files changed

+417
-7
lines changed

8 files changed

+417
-7
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import app from "../../smslink_nc.app.mjs";
2+
3+
export default {
4+
key: "smslink_nc-create-contact",
5+
name: "Create Contact",
6+
description: "Create a new contact in smslink_nc. [See the documentation](https://api.smslink.nc/api/documentation#/Contact/556b84f384422939a9db51e60685798a).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
phoneNumber: {
12+
type: "string",
13+
label: "Phone Number",
14+
description: "The phone number of the contact.",
15+
},
16+
email: {
17+
type: "string",
18+
label: "Email",
19+
description: "The email of the contact.",
20+
optional: true,
21+
},
22+
firstName: {
23+
type: "string",
24+
label: "First Name",
25+
description: "The first name of the contact.",
26+
optional: true,
27+
},
28+
lastName: {
29+
type: "string",
30+
label: "Last Name",
31+
description: "The last name of the contact.",
32+
optional: true,
33+
},
34+
param1: {
35+
type: "string",
36+
label: "Param 1",
37+
description: "Custom parameter 1.",
38+
optional: true,
39+
},
40+
param2: {
41+
type: "string",
42+
label: "Param 2",
43+
description: "Custom parameter 2.",
44+
optional: true,
45+
},
46+
param3: {
47+
type: "string",
48+
label: "Param 3",
49+
description: "Custom parameter 3.",
50+
optional: true,
51+
},
52+
},
53+
methods: {
54+
createContact(args = {}) {
55+
return this.app.post({
56+
path: "/contact",
57+
...args,
58+
});
59+
},
60+
},
61+
async run({ $ }) {
62+
const {
63+
createContact,
64+
phoneNumber,
65+
email,
66+
firstName,
67+
lastName,
68+
param1,
69+
param2,
70+
param3,
71+
} = this;
72+
73+
const response = await createContact({
74+
$,
75+
data: {
76+
contacts: [
77+
{
78+
phone_number: phoneNumber,
79+
email,
80+
first_name: firstName,
81+
last_name: lastName,
82+
param_1: param1,
83+
param_2: param2,
84+
param_3: param3,
85+
},
86+
],
87+
},
88+
});
89+
$.export("$summary", "Successfully created a new contact.");
90+
return response;
91+
},
92+
};
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import utils from "../../common/utils.mjs";
2+
import app from "../../smslink_nc.app.mjs";
3+
4+
export default {
5+
key: "smslink_nc-create-sms-campaign",
6+
name: "Create SMS Campaign",
7+
description: "Create a new SMS campaign.",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
title: {
13+
type: "string",
14+
label: "Title",
15+
description: "The title of the SMS campaign.",
16+
},
17+
sender: {
18+
type: "string",
19+
label: "Sender",
20+
description: "The sender of the SMS campaign. Eg. `SMSLink`.",
21+
default: "SMSLink",
22+
},
23+
text: {
24+
type: "string",
25+
label: "Text",
26+
description: "The text of the SMS campaign.",
27+
},
28+
autoOptimizeText: {
29+
type: "boolean",
30+
label: "Auto Optimize Text",
31+
description: "Whether to auto optimize the text of the SMS campaign.",
32+
},
33+
autoRemoveBlocklistedNumbers: {
34+
type: "boolean",
35+
label: "Auto Remove Blocklisted Numbers",
36+
description: "Whether to auto remove blocklisted numbers.",
37+
optional: true,
38+
},
39+
purpose: {
40+
type: "string",
41+
label: "Purpose",
42+
description: "The purpose of the SMS campaign.",
43+
optional: true,
44+
options: [
45+
"push",
46+
],
47+
},
48+
test: {
49+
type: "boolean",
50+
label: "Test",
51+
description: "Whether the SMS campaign is a test.",
52+
optional: true,
53+
},
54+
recipients: {
55+
type: "string[]",
56+
label: "Recipients",
57+
description: "The recipients of the SMS campaign. Where each recipient should be a phone number.",
58+
propDefinition: [
59+
app,
60+
"contactId",
61+
() => ({
62+
mapper: ({
63+
phone_number: value, first_name: firstName, last_name: lastName,
64+
}) => ({
65+
value,
66+
label: `${firstName || ""} ${lastName || ""} (${value})`.trim(),
67+
}),
68+
}),
69+
],
70+
},
71+
},
72+
methods: {
73+
createCampaign(args = {}) {
74+
return this.app.post({
75+
path: "/sms-campaign",
76+
...args,
77+
});
78+
},
79+
},
80+
async run({ $ }) {
81+
const {
82+
createCampaign,
83+
title,
84+
sender,
85+
text,
86+
autoOptimizeText,
87+
autoRemoveBlocklistedNumbers,
88+
purpose,
89+
test,
90+
recipients,
91+
} = this;
92+
93+
const response = await createCampaign({
94+
$,
95+
data: {
96+
title,
97+
sender,
98+
text,
99+
auto_optimize_text: autoOptimizeText,
100+
auto_remove_blocklisted_numbers: autoRemoveBlocklistedNumbers,
101+
purpose,
102+
test,
103+
recipients: utils.parseArray(recipients)?.map((phoneNumber) => ({
104+
phone_number: phoneNumber,
105+
})),
106+
},
107+
});
108+
$.export("$summary", "Successfully created SMS campaign.");
109+
return response;
110+
},
111+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import app from "../../smslink_nc.app.mjs";
2+
3+
export default {
4+
key: "smslink_nc-delete-contact",
5+
name: "Delete Contact",
6+
description: "Deletes a contact. [See the documentation](https://api.smslink.nc/api/documentation)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
phoneNumber: {
12+
label: "Contact Phone Number",
13+
description: "The phone number of the contact to delete.",
14+
propDefinition: [
15+
app,
16+
"contactId",
17+
() => ({
18+
mapper: ({
19+
phone_number: value, first_name: firstName, last_name: lastName,
20+
}) => ({
21+
value,
22+
label: `${firstName || ""} ${lastName || ""} (${value})`.trim(),
23+
}),
24+
}),
25+
],
26+
},
27+
},
28+
methods: {
29+
deleteContact(args = {}) {
30+
return this.app.delete({
31+
path: "/contact",
32+
...args,
33+
});
34+
},
35+
},
36+
async run({ $ }) {
37+
const {
38+
deleteContact,
39+
phoneNumber,
40+
} = this;
41+
42+
const response = await deleteContact({
43+
$,
44+
data: {
45+
phone_numbers: [
46+
phoneNumber,
47+
],
48+
},
49+
});
50+
$.export("$summary", "Successfully deleted contact.");
51+
return response;
52+
},
53+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import app from "../../smslink_nc.app.mjs";
2+
3+
export default {
4+
key: "smslink_nc-delete-sms-campaign",
5+
name: "Delete SMS Campaign",
6+
description: "Delete an existing SMS campaign. [See the documentation](https://api.smslink.nc/api/documentation)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
campaignId: {
12+
propDefinition: [
13+
app,
14+
"campaignId",
15+
],
16+
},
17+
},
18+
methods: {
19+
deleteCampaign({
20+
campaignId, ...args
21+
} = {}) {
22+
return this.app.delete({
23+
path: `/sms-campaign/${campaignId}`,
24+
...args,
25+
});
26+
},
27+
},
28+
async run({ $ }) {
29+
const {
30+
deleteCampaign,
31+
campaignId,
32+
} = this;
33+
34+
await deleteCampaign({
35+
$,
36+
campaignId,
37+
params: {
38+
by: "id",
39+
},
40+
});
41+
42+
$.export("$summary", "Successfully deleted SMS campaign.");
43+
return {
44+
sucess: true,
45+
};
46+
},
47+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
3+
function parseArray(value) {
4+
try {
5+
if (!value) {
6+
return [];
7+
}
8+
9+
if (Array.isArray(value)) {
10+
return value;
11+
}
12+
13+
const parsedValue = JSON.parse(value);
14+
15+
if (!Array.isArray(parsedValue)) {
16+
throw new Error("Not an array");
17+
}
18+
19+
return parsedValue;
20+
21+
} catch (e) {
22+
throw new ConfigurationError("Make sure the custom expression contains a valid array object");
23+
}
24+
}
25+
26+
export default {
27+
parseArray,
28+
};

components/smslink_nc/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/smslink_nc",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream SMSlink nc Components",
55
"main": "smslink_nc.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)