Skip to content

Commit 1c2e06c

Browse files
New Components - slicktext (#16596)
* slicktext init * [Components] slicktext #13364 Actions - Create Contact - Edit Contact - Add Contact To Lists * pnpm update * fix api key constant name * Update components/slicktext/actions/create-contact/create-contact.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 a9b1757 commit 1c2e06c

File tree

11 files changed

+461
-20
lines changed

11 files changed

+461
-20
lines changed

components/slicktext/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import slicktext from "../../slicktext.app.mjs";
3+
4+
export default {
5+
key: "slicktext-add-contact-to-lists",
6+
name: "Add Contact To Lists",
7+
description: "Add a contact to lists. [See the documentation](https://api.slicktext.com/docs/v2/lists#scroll-to-add-contacts-to-lists)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
slicktext,
12+
contactId: {
13+
propDefinition: [
14+
slicktext,
15+
"contactId",
16+
],
17+
},
18+
listIds: {
19+
propDefinition: [
20+
slicktext,
21+
"listIds",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.slicktext.addContactToLists({
27+
$,
28+
data: [
29+
{
30+
contact_id: this.contactId,
31+
lists: parseObject(this.listIds),
32+
},
33+
],
34+
});
35+
36+
$.export("$summary", `Successfully added contact with ID: ${this.contactId} to lists with ID: ${parseObject(this.listIds).join()}`);
37+
return response;
38+
},
39+
};
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import slicktext from "../../slicktext.app.mjs";
2+
3+
export const commonProps = {
4+
firstName: {
5+
propDefinition: [
6+
slicktext,
7+
"firstName",
8+
],
9+
optional: true,
10+
},
11+
lastName: {
12+
propDefinition: [
13+
slicktext,
14+
"lastName",
15+
],
16+
optional: true,
17+
},
18+
email: {
19+
propDefinition: [
20+
slicktext,
21+
"email",
22+
],
23+
optional: true,
24+
},
25+
birthdate: {
26+
propDefinition: [
27+
slicktext,
28+
"birthdate",
29+
],
30+
optional: true,
31+
},
32+
address: {
33+
propDefinition: [
34+
slicktext,
35+
"address",
36+
],
37+
optional: true,
38+
},
39+
city: {
40+
propDefinition: [
41+
slicktext,
42+
"city",
43+
],
44+
optional: true,
45+
},
46+
state: {
47+
propDefinition: [
48+
slicktext,
49+
"state",
50+
],
51+
optional: true,
52+
},
53+
zip: {
54+
propDefinition: [
55+
slicktext,
56+
"zip",
57+
],
58+
optional: true,
59+
},
60+
country: {
61+
propDefinition: [
62+
slicktext,
63+
"country",
64+
],
65+
optional: true,
66+
},
67+
timezone: {
68+
propDefinition: [
69+
slicktext,
70+
"timezone",
71+
],
72+
optional: true,
73+
},
74+
language: {
75+
propDefinition: [
76+
slicktext,
77+
"language",
78+
],
79+
optional: true,
80+
},
81+
optInStatus: {
82+
propDefinition: [
83+
slicktext,
84+
"optInStatus",
85+
],
86+
optional: true,
87+
},
88+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { objectCamelToSnakeCase } from "../../common/utils.mjs";
2+
import slicktext from "../../slicktext.app.mjs";
3+
import { commonProps } from "../common/base.mjs";
4+
5+
export default {
6+
key: "slicktext-create-contact",
7+
name: "Create Contact",
8+
description: "Add a new contact to your messaging list. [See the documentation](https://api.slicktext.com/docs/v1/contacts)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
slicktext,
13+
mobileNumber: {
14+
propDefinition: [
15+
slicktext,
16+
"mobileNumber",
17+
],
18+
},
19+
...commonProps,
20+
forceDoubleOptIn: {
21+
propDefinition: [
22+
slicktext,
23+
"forceDoubleOptIn",
24+
],
25+
optional: true,
26+
},
27+
},
28+
async run({ $ }) {
29+
const {
30+
slicktext,
31+
...data
32+
} = this;
33+
34+
const response = await slicktext.createContact({
35+
$,
36+
data: objectCamelToSnakeCase(data),
37+
});
38+
$.export("$summary", `Successfully initiated opt-in for contact with number: ${this.mobileNumber}`);
39+
return response;
40+
},
41+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { objectCamelToSnakeCase } from "../../common/utils.mjs";
2+
import slicktext from "../../slicktext.app.mjs";
3+
import { commonProps } from "../common/base.mjs";
4+
5+
export default {
6+
key: "slicktext-edit-contact",
7+
name: "Edit Contact",
8+
description: "Updates personal details of an existing contact. [See the documentation](https://api.slicktext.com/docs/v1/contacts#6)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
slicktext,
13+
contactId: {
14+
propDefinition: [
15+
slicktext,
16+
"contactId",
17+
],
18+
},
19+
mobileNumber: {
20+
propDefinition: [
21+
slicktext,
22+
"mobileNumber",
23+
],
24+
optional: true,
25+
},
26+
...commonProps,
27+
},
28+
async run({ $ }) {
29+
const {
30+
slicktext,
31+
contactId,
32+
...data
33+
} = this;
34+
35+
const response = await slicktext.updateContact({
36+
$,
37+
contactId,
38+
data: objectCamelToSnakeCase(data),
39+
});
40+
41+
$.export("$summary", `Successfully updated contact with ID: ${this.contactId}`);
42+
return response;
43+
},
44+
};

components/slicktext/app/slicktext.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const LIMIT = 250;
2+
3+
export const OPT_IN_STATUS_OPTIONS = [
4+
"not subscribed",
5+
"subscribed",
6+
"unsubscribed",
7+
"blocked",
8+
];
9+
10+
export const TIMEZONE_OPTIONS = [
11+
"America/New_York",
12+
"America/Chicago",
13+
"America/Denver",
14+
"America/Los_Angeles",
15+
];

components/slicktext/common/utils.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export const objectCamelToSnakeCase = (obj) => {
2+
return Object.entries(obj).reduce((acc, [
3+
key,
4+
value,
5+
]) => {
6+
const newKey = key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
7+
acc[newKey] = value;
8+
return acc;
9+
}
10+
, {});
11+
};
12+
13+
export const parseObject = (obj) => {
14+
if (!obj) return undefined;
15+
16+
if (Array.isArray(obj)) {
17+
return obj.map((item) => {
18+
if (typeof item === "string") {
19+
try {
20+
return JSON.parse(item);
21+
} catch (e) {
22+
return item;
23+
}
24+
}
25+
return item;
26+
});
27+
}
28+
if (typeof obj === "string") {
29+
try {
30+
return JSON.parse(obj);
31+
} catch (e) {
32+
return obj;
33+
}
34+
}
35+
return obj;
36+
};

components/slicktext/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"name": "@pipedream/slicktext",
3-
"version": "0.0.3",
3+
"version": "0.1.0",
44
"description": "Pipedream SlickText Components",
5-
"main": "dist/app/slicktext.app.mjs",
5+
"main": "slicktext.app.mjs",
66
"keywords": [
77
"pipedream",
88
"slicktext"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/slicktext",
1211
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1312
"publishConfig": {
1413
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1517
}
1618
}

0 commit comments

Comments
 (0)