Skip to content

Commit fdf97fa

Browse files
committed
[Components] ortto #13209
Sources - New Contact Created Actions - Create Custom Activity - Opt Out SMS
1 parent afad520 commit fdf97fa

File tree

16 files changed

+377
-506
lines changed

16 files changed

+377
-506
lines changed

common/constants.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const LIMIT = 100;

components/ortto/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,51 @@
1+
import { parseObject } from "../../common/utils.mjs";
12
import ortto from "../../ortto.app.mjs";
23

34
export default {
45
key: "ortto-create-custom-activity",
56
name: "Create Custom Activity",
6-
description: "Creates a unique activity for a user. Can optionally initialize a new record beforehand. [See the documentation](https://help.ortto.com/developer/latest/api-reference/activity/index.html)",
7-
version: "0.0.{{ts}}",
7+
description: "Creates a unique activity for a person. Can optionally initialize a new record beforehand. [See the documentation](https://help.ortto.com/developer/latest/api-reference/activity/index.html)",
8+
version: "0.0.1",
89
type: "action",
910
props: {
1011
ortto,
11-
activityName: {
12+
activityId: {
1213
propDefinition: [
1314
ortto,
14-
"activityName",
15+
"activityId",
1516
],
1617
},
17-
recordId: {
18+
attributes: {
1819
propDefinition: [
1920
ortto,
20-
"recordId",
21+
"attributes",
2122
],
22-
optional: true,
2323
},
24-
recordType: {
24+
fields: {
2525
propDefinition: [
2626
ortto,
27-
"recordType",
27+
"fields",
2828
],
29-
optional: true,
30-
},
31-
data: {
32-
propDefinition: [
33-
ortto,
34-
"data",
35-
],
36-
optional: true,
3729
},
3830
},
3931
async run({ $ }) {
40-
if (this.recordType && this.data) {
41-
await this.ortto.initializeOrUpdateRecord({
42-
recordType: this.recordType,
43-
data: this.data,
44-
});
45-
}
46-
47-
const response = await this.ortto.createUniqueActivity({
48-
activityName: this.activityName,
49-
recordId: this.recordId,
32+
const response = await this.ortto.createCustomActivity({
33+
$,
34+
data: {
35+
"activities": [
36+
{
37+
activity_id: this.activityId,
38+
attributes: parseObject(this.attributes),
39+
fields: parseObject(this.fields),
40+
},
41+
],
42+
"merge_by": [
43+
"str::email",
44+
],
45+
},
5046
});
5147

52-
$.export("$summary", `Successfully created activity ${response.id}`);
48+
$.export("$summary", "Successfully created activity");
5349
return response;
5450
},
5551
};
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { clearObj } from "../../common/utils.mjs";
2+
import ortto from "../../ortto.app.mjs";
3+
4+
export default {
5+
key: "ortto-create-person",
6+
name: "Create or Update a Person",
7+
description: "Create or update a preexisting person in the Ortto account. [See the documentation](https://help.ortto.com/a-250-api-reference)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
ortto,
12+
firstName: {
13+
type: "string",
14+
label: "First Name",
15+
description: "The person's first name.",
16+
optional: true,
17+
},
18+
lastName: {
19+
type: "string",
20+
label: "Last Name",
21+
description: "The person's last name.",
22+
optional: true,
23+
},
24+
phone: {
25+
type: "string",
26+
label: "Phone",
27+
description: "The person's phone number.",
28+
},
29+
email: {
30+
type: "string",
31+
label: "Email",
32+
description: "The person's email address.",
33+
},
34+
city: {
35+
type: "string",
36+
label: "City",
37+
description: "The person's address city.",
38+
optional: true,
39+
},
40+
country: {
41+
type: "string",
42+
label: "Country",
43+
description: "The person's address country.",
44+
optional: true,
45+
},
46+
region: {
47+
type: "string",
48+
label: "Region",
49+
description: "The person's address region.",
50+
optional: true,
51+
},
52+
birthday: {
53+
type: "string",
54+
label: "Birthday",
55+
description: "The person's birth date.",
56+
optional: true,
57+
},
58+
},
59+
async run({ $ }) {
60+
const {
61+
ortto,
62+
...props
63+
} = this;
64+
65+
const birthday = {};
66+
if (props.birthday) {
67+
const date = new Date(props.birthday);
68+
birthday.day = date.getDate();
69+
birthday.month = date.getMonth() + 1;
70+
birthday.year = date.getFullYear();
71+
}
72+
73+
const response = await ortto.createPerson({
74+
data: {
75+
people: [
76+
{
77+
fields: clearObj({
78+
"str::first": props.firstName,
79+
"str::last": props.lastName,
80+
"phn::phone": {
81+
"phone": props.phone,
82+
"parse_with_country_code": true,
83+
},
84+
"str::email": props.email,
85+
"geo::city": {
86+
name: props.city,
87+
},
88+
"geo::country": {
89+
name: props.country,
90+
},
91+
"geo::region": {
92+
name: props.region,
93+
},
94+
"dtz::b": birthday,
95+
}),
96+
},
97+
],
98+
async: false,
99+
merge_by: [
100+
"str::email",
101+
],
102+
merge_strategy: 3,
103+
find_strategy: 0,
104+
},
105+
});
106+
$.export("$summary", "Person successfully initialized or updated!");
107+
return response;
108+
},
109+
};

components/ortto/actions/create-record/create-record.mjs

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import ortto from "../../ortto.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "ortto-opt-out-sms",
@@ -9,21 +8,32 @@ export default {
98
type: "action",
109
props: {
1110
ortto,
12-
userId: {
11+
userEmail: {
1312
propDefinition: [
1413
ortto,
15-
"userId",
14+
"userEmail",
1615
],
1716
},
1817
},
1918
async run({ $ }) {
20-
const response = await this.ortto.optOutSMS({
21-
pathParams: {
22-
userId: this.userId,
19+
const response = await this.ortto.updatePerson({
20+
data: {
21+
people: [
22+
{
23+
fields: {
24+
"str::email": this.userEmail,
25+
"bol::sp": false,
26+
},
27+
},
28+
],
29+
async: false,
30+
merge_by: [
31+
"str::email",
32+
],
2333
},
2434
});
2535

26-
$.export("$summary", `Successfully opted out SMS for User ID: ${this.userId}`);
36+
$.export("$summary", `Successfully opted out SMS for User ID: ${this.userEmail}`);
2737
return response;
2838
},
2939
};

components/ortto/app/ortto.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

components/ortto/common/utils.mjs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export const clearObj = (obj) => {
2+
return Object.entries(obj)
3+
.filter(([
4+
,
5+
v,
6+
]) => (v != null && v != "" && JSON.stringify(v) != "{}"))
7+
.reduce((acc, [
8+
k,
9+
v,
10+
]) => ({
11+
...acc,
12+
[k]: (!Array.isArray(v) && v === Object(v))
13+
? clearObj(v)
14+
: v,
15+
}), {});
16+
};
17+
18+
export const parseObject = (obj) => {
19+
if (!obj) return undefined;
20+
21+
if (Array.isArray(obj)) {
22+
return obj.map((item) => {
23+
if (typeof item === "string") {
24+
try {
25+
return JSON.parse(item);
26+
} catch (e) {
27+
return item;
28+
}
29+
}
30+
return item;
31+
});
32+
}
33+
if (typeof obj === "string") {
34+
try {
35+
return JSON.parse(obj);
36+
} catch (e) {
37+
return obj;
38+
}
39+
}
40+
return obj;
41+
};

0 commit comments

Comments
 (0)