Skip to content

Commit 495e16d

Browse files
committed
SMSlink: New action components
1 parent fb808e1 commit 495e16d

File tree

7 files changed

+305
-7
lines changed

7 files changed

+305
-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. [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: 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+
}
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: "smslink_nc",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
contactId: {
8+
type: "string",
9+
label: "Contact ID",
10+
description: "The ID of the contact to delete or manipulate.",
11+
async options({
12+
mapper = ({
13+
id: value, phone_number: phoneNumber, first_name: firstName, last_name: lastName,
14+
}) => ({
15+
value,
16+
label: `${firstName || ""} ${lastName || ""} (${phoneNumber})`.trim(),
17+
}),
18+
}) {
19+
const { object: { data } } = await this.getContacts();
20+
return data.map(mapper);
21+
},
22+
},
23+
campaignId: {
24+
type: "string",
25+
label: "Campaign ID",
26+
description: "The ID of the SMS campaign to delete or manipulate.",
27+
async options() {
28+
const { object: { data } } = await this.getSMSCampaigns();
29+
return data.map(({
30+
id: value, title: label,
31+
}) => ({
32+
value,
33+
label,
34+
}));
35+
},
36+
},
37+
},
538
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
39+
getUrl(path) {
40+
return `https://api.smslink.nc/api${path}`;
41+
},
42+
getHeaders(headers) {
43+
return {
44+
Accept: "application/json",
45+
Authorization: `Bearer ${this.$auth.personal_access_token}`,
46+
...headers,
47+
};
48+
},
49+
_makeRequest({
50+
$ = this, path, headers, ...args
51+
} = {}) {
52+
return axios($, {
53+
...args,
54+
url: this.getUrl(path),
55+
headers: this.getHeaders(headers),
56+
});
57+
},
58+
post(args = {}) {
59+
return this._makeRequest({
60+
method: "POST",
61+
...args,
62+
});
63+
},
64+
delete(args = {}) {
65+
return this._makeRequest({
66+
method: "DELETE",
67+
...args,
68+
});
69+
},
70+
getContacts(args = {}) {
71+
return this._makeRequest({
72+
path: "/contact",
73+
...args,
74+
});
75+
},
76+
getSMSCampaigns(args = {}) {
77+
return this._makeRequest({
78+
path: "/sms-campaign",
79+
...args,
80+
});
981
},
1082
},
1183
};

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)