Skip to content

New Components - slicktext #16596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions components/slicktext/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { parseObject } from "../../common/utils.mjs";
import slicktext from "../../slicktext.app.mjs";

export default {
key: "slicktext-add-contact-to-lists",
name: "Add Contact To Lists",
description: "Add a contact to lists. [See the documentation](https://api.slicktext.com/docs/v2/lists#scroll-to-add-contacts-to-lists)",
version: "0.0.1",
type: "action",
props: {
slicktext,
contactId: {
propDefinition: [
slicktext,
"contactId",
],
},
listIds: {
propDefinition: [
slicktext,
"listIds",
],
},
},
async run({ $ }) {
const response = await this.slicktext.addContactToLists({
$,
data: [
{
contact_id: this.contactId,
lists: parseObject(this.listIds),
},
],
});

$.export("$summary", `Successfully added contact with ID: ${this.contactId} to lists with ID: ${parseObject(this.listIds).join()}`);
return response;
},
};
88 changes: 88 additions & 0 deletions components/slicktext/actions/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import slicktext from "../../slicktext.app.mjs";

export const commonProps = {
firstName: {
propDefinition: [
slicktext,
"firstName",
],
optional: true,
},
lastName: {
propDefinition: [
slicktext,
"lastName",
],
optional: true,
},
email: {
propDefinition: [
slicktext,
"email",
],
optional: true,
},
birthdate: {
propDefinition: [
slicktext,
"birthdate",
],
optional: true,
},
address: {
propDefinition: [
slicktext,
"address",
],
optional: true,
},
city: {
propDefinition: [
slicktext,
"city",
],
optional: true,
},
state: {
propDefinition: [
slicktext,
"state",
],
optional: true,
},
zip: {
propDefinition: [
slicktext,
"zip",
],
optional: true,
},
country: {
propDefinition: [
slicktext,
"country",
],
optional: true,
},
timezone: {
propDefinition: [
slicktext,
"timezone",
],
optional: true,
},
language: {
propDefinition: [
slicktext,
"language",
],
optional: true,
},
optInStatus: {
propDefinition: [
slicktext,
"optInStatus",
],
optional: true,
},
};
41 changes: 41 additions & 0 deletions components/slicktext/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { objectCamelToSnakeCase } from "../../common/utils.mjs";
import slicktext from "../../slicktext.app.mjs";
import { commonProps } from "../common/base.mjs";

export default {
key: "slicktext-create-contact",
name: "Create Contact",
description: "Add a new contact to your messaging list. [See the documentation](https://api.slicktext.com/docs/v1/contacts)",
version: "0.0.1",
type: "action",
props: {
slicktext,
mobileNumber: {
propDefinition: [
slicktext,
"mobileNumber",
],
},
...commonProps,
forceDoubleOptIn: {
propDefinition: [
slicktext,
"forceDoubleOptIn",
],
optional: true,
},
},
async run({ $ }) {
const {
slicktext,
...data
} = this;

const response = await slicktext.createContact({
$,
data: objectCamelToSnakeCase(data),
});
$.export("$summary", `Successfully initiated opt-in for contact with number: ${this.mobileNumber}`);
return response;
},
};
44 changes: 44 additions & 0 deletions components/slicktext/actions/edit-contact/edit-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { objectCamelToSnakeCase } from "../../common/utils.mjs";
import slicktext from "../../slicktext.app.mjs";
import { commonProps } from "../common/base.mjs";

export default {
key: "slicktext-edit-contact",
name: "Edit Contact",
description: "Updates personal details of an existing contact. [See the documentation](https://api.slicktext.com/docs/v1/contacts#6)",
version: "0.0.1",
type: "action",
props: {
slicktext,
contactId: {
propDefinition: [
slicktext,
"contactId",
],
},
mobileNumber: {
propDefinition: [
slicktext,
"mobileNumber",
],
optional: true,
},
...commonProps,
},
async run({ $ }) {
const {
slicktext,
contactId,
...data
} = this;

const response = await slicktext.updateContact({
$,
contactId,
data: objectCamelToSnakeCase(data),
});

$.export("$summary", `Successfully updated contact with ID: ${this.contactId}`);
return response;
},
};
13 changes: 0 additions & 13 deletions components/slicktext/app/slicktext.app.ts

This file was deleted.

15 changes: 15 additions & 0 deletions components/slicktext/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const LIMIT = 250;

export const OPT_IN_STATUS_OPTIONS = [
"not subscribed",
"subscribed",
"unsubscribed",
"blocked",
];

export const TIMEZONE_OPTIONS = [
"America/New_York",
"America/Chicago",
"America/Denver",
"America/Los_Angeles",
];
36 changes: 36 additions & 0 deletions components/slicktext/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export const objectCamelToSnakeCase = (obj) => {
return Object.entries(obj).reduce((acc, [
key,
value,
]) => {
const newKey = key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
acc[newKey] = value;
return acc;
}
, {});
};

export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
8 changes: 5 additions & 3 deletions components/slicktext/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "@pipedream/slicktext",
"version": "0.0.3",
"version": "0.1.0",
"description": "Pipedream SlickText Components",
"main": "dist/app/slicktext.app.mjs",
"main": "slicktext.app.mjs",
"keywords": [
"pipedream",
"slicktext"
],
"files": ["dist"],
"homepage": "https://pipedream.com/apps/slicktext",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
Loading
Loading