Skip to content

Commit bd32636

Browse files
committed
Added actions
1 parent b4fb1d8 commit bd32636

File tree

8 files changed

+299
-24
lines changed

8 files changed

+299
-24
lines changed

components/engage/.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 app from "../../engage.app.mjs";
2+
3+
export default {
4+
key: "engage-add-customer",
5+
name: "Add Customer",
6+
description: "Adds Customer to Accounts. [See the documentation](https://docs.engage.so/en-us/a/62bbdd015bfea4dca4834042-users#add-customer-to-accounts)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
uid: {
12+
propDefinition: [
13+
app,
14+
"uid",
15+
],
16+
},
17+
customerId: {
18+
propDefinition: [
19+
app,
20+
"customerId",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.app.addCustomer({
26+
$,
27+
uid: this.uid,
28+
data: {
29+
accounts: [
30+
{
31+
id: this.customerId,
32+
},
33+
],
34+
},
35+
});
36+
$.export("$summary", "add-customer executed successfully");
37+
return response;
38+
},
39+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import app from "../../engage.app.mjs";
2+
3+
export default {
4+
key: "engage-add-event",
5+
name: "Add Event",
6+
description: "Adds user events to Engage. [See the documentation](https://docs.engage.so/en-us/a/62bbdd015bfea4dca4834042-users#track-user-event)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
uid: {
12+
propDefinition: [
13+
app,
14+
"uid",
15+
],
16+
},
17+
event: {
18+
propDefinition: [
19+
app,
20+
"event",
21+
],
22+
},
23+
timestamp: {
24+
propDefinition: [
25+
app,
26+
"timestamp",
27+
],
28+
},
29+
properties: {
30+
propDefinition: [
31+
app,
32+
"properties",
33+
],
34+
},
35+
},
36+
async run({ $ }) {
37+
const response = await this.app.addEvent({
38+
$,
39+
uid: this.uid,
40+
data: {
41+
event: this.event,
42+
timestamp: this.timestamp,
43+
properties: this.properties,
44+
},
45+
});
46+
$.export("$summary", `Successfully added event. Status: ${response.status}`);
47+
return response;
48+
},
49+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import app from "../../engage.app.mjs";
2+
3+
export default {
4+
key: "engage-create-user",
5+
name: "Create User",
6+
description: "Adds a new user to your Engage account. Use this to sync customer data with Engage. [See the documentation](https://docs.engage.so/en-us/a/62bbdd015bfea4dca4834042-users#create-a-user)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
userId: {
12+
propDefinition: [
13+
app,
14+
"userId",
15+
],
16+
},
17+
firstName: {
18+
propDefinition: [
19+
app,
20+
"firstName",
21+
],
22+
},
23+
lastName: {
24+
propDefinition: [
25+
app,
26+
"lastName",
27+
],
28+
},
29+
isAccount: {
30+
propDefinition: [
31+
app,
32+
"isAccount",
33+
],
34+
},
35+
number: {
36+
propDefinition: [
37+
app,
38+
"number",
39+
],
40+
},
41+
email: {
42+
propDefinition: [
43+
app,
44+
"email",
45+
],
46+
},
47+
},
48+
async run({ $ }) {
49+
const response = await this.app.createUser({
50+
$,
51+
data: {
52+
id: this.userId,
53+
first_name: this.firstName,
54+
last_name: this.lastName,
55+
is_account: this.isAccount,
56+
number: this.number,
57+
email: this.email,
58+
},
59+
});
60+
$.export("$summary", `Successfully created user with ID: ${response.id}`);
61+
return response;
62+
},
63+
};

components/engage/app/engage.app.ts

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

components/engage/engage.app.mjs

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import { axios } from "@pipedream/platform";
2+
3+
export default {
4+
type: "app",
5+
app: "engage",
6+
propDefinitions: {
7+
userId: {
8+
type: "string",
9+
label: "User ID",
10+
description: "Unique identifier for the user",
11+
},
12+
firstName: {
13+
type: "string",
14+
label: "First name",
15+
description: "The user's first name",
16+
},
17+
lastName: {
18+
type: "string",
19+
label: "Last name",
20+
description: "The user's last name",
21+
},
22+
isAccount: {
23+
type: "boolean",
24+
label: "Is account",
25+
description: "Indicates whether the user is also an account",
26+
},
27+
number: {
28+
type: "string",
29+
label: "Number",
30+
description: "A contact number associated with the user",
31+
},
32+
email: {
33+
type: "string",
34+
label: "Email",
35+
description: "The user's email address",
36+
},
37+
uid: {
38+
type: "string",
39+
label: "User ID",
40+
description: "ID of the user",
41+
async options() {
42+
const response = await this.getUsers();
43+
const usersIds = response.data;
44+
return usersIds.map(({
45+
uid, first_name, last_name,
46+
}) => ({
47+
label: `${first_name} ${last_name}`,
48+
value: uid,
49+
}));
50+
},
51+
},
52+
customerId: {
53+
type: "string",
54+
label: "Customer ID",
55+
description: "ID of the customer that will be added to the user",
56+
async options() {
57+
const response = await this.getUsers();
58+
const usersIds = response.data;
59+
return usersIds.map(({
60+
uid, first_name, last_name,
61+
}) => ({
62+
label: `${first_name} ${last_name}`,
63+
value: uid,
64+
}));
65+
},
66+
},
67+
event: {
68+
type: "string",
69+
label: "Event",
70+
description: "The name of the event associated with the user",
71+
},
72+
timestamp: {
73+
type: "string",
74+
label: "Timestamp",
75+
description: "Timestamp of the event. If none is provided, the current time is used",
76+
},
77+
properties: {
78+
type: "object",
79+
label: "Properties",
80+
description: "The properties of the event",
81+
},
82+
},
83+
methods: {
84+
_baseUrl() {
85+
return "https://api.engage.so/v1";
86+
},
87+
async _makeRequest(opts = {}) {
88+
const {
89+
$ = this,
90+
path,
91+
auth,
92+
...otherOpts
93+
} = opts;
94+
return axios($, {
95+
...otherOpts,
96+
url: this._baseUrl() + path,
97+
auth: {
98+
...auth,
99+
username: `${this.$auth.public_key}`,
100+
password: `${this.$auth.secret_key}`,
101+
},
102+
});
103+
},
104+
async createUser(args = {}) {
105+
return this._makeRequest({
106+
path: "/users",
107+
method: "post",
108+
...args,
109+
});
110+
},
111+
async addCustomer({
112+
uid, ...args
113+
}) {
114+
return this._makeRequest({
115+
path: `/users/${uid}/accounts`,
116+
method: "post",
117+
...args,
118+
});
119+
},
120+
async addEvent({
121+
uid, ...args
122+
}) {
123+
return this._makeRequest({
124+
path: `/users/${uid}/events`,
125+
method: "post",
126+
...args,
127+
});
128+
},
129+
async getUsers(args = {}) {
130+
return this._makeRequest({
131+
path: "/users",
132+
...args,
133+
});
134+
},
135+
},
136+
};

components/engage/package.json

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

pnpm-lock.yaml

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)