Skip to content

Commit 987b934

Browse files
authored
New Components - hullo (#14271)
* init * new components * pnpm-lock.yaml * package.json
1 parent ff70ac9 commit 987b934

File tree

5 files changed

+252
-59
lines changed

5 files changed

+252
-59
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import hullo from "../../hullo.app.mjs";
2+
3+
export default {
4+
key: "hullo-add-update-member",
5+
name: "Add or Update Member",
6+
description: "Adds a new member or updates an existing member's data in Hullo. [See the documentation](https://app.hullo.me/docs/index.html#?route=post-/endpoints/members)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
hullo,
11+
phoneNumber: {
12+
propDefinition: [
13+
hullo,
14+
"phoneNumber",
15+
],
16+
},
17+
fullName: {
18+
type: "string",
19+
label: "Full Name",
20+
description: "The full name of the member. REQUIRED if creating a new member.",
21+
optional: true,
22+
},
23+
registrationDate: {
24+
type: "string",
25+
label: "Registration Date",
26+
description: "The date the member was registered in ISO-8601 format. Example: `2000-01-23T04:56:07.000+00:00`",
27+
optional: true,
28+
},
29+
groups: {
30+
type: "string[]",
31+
label: "Groups",
32+
description: "An array containing the names of groups this member belongs to",
33+
optional: true,
34+
},
35+
attributes: {
36+
propDefinition: [
37+
hullo,
38+
"attributes",
39+
],
40+
reloadProps: true,
41+
},
42+
},
43+
async additionalProps() {
44+
const props = {};
45+
if (!this.attributes?.length) {
46+
return props;
47+
}
48+
for (const attribute of this.attributes) {
49+
props[attribute] = {
50+
type: "string",
51+
label: attribute,
52+
description: `Value for ${attribute}`,
53+
};
54+
}
55+
return props;
56+
},
57+
methods: {
58+
async formatAttributes(attributeKeys, attributeValues) {
59+
const attributes = await this.hullo.listAttributes();
60+
const formattedAttributes = {};
61+
for (const key of attributeKeys) {
62+
const { type } = attributes.find(({ name }) => name === key);
63+
const value = type === "NUMBER"
64+
? +attributeValues[key]
65+
: type === "LIST"
66+
? JSON.parse(attributeValues[key])
67+
: attributeValues[key];
68+
formattedAttributes[key] = [
69+
value,
70+
];
71+
}
72+
return formattedAttributes;
73+
},
74+
},
75+
async run({ $ }) {
76+
const {
77+
hullo,
78+
formatAttributes,
79+
phoneNumber,
80+
fullName,
81+
registrationDate,
82+
groups,
83+
attributes,
84+
...attributeValues
85+
} = this;
86+
87+
const response = await hullo.addOrUpdateMember({
88+
$,
89+
data: {
90+
phoneNumber,
91+
fullName,
92+
registrationDate,
93+
groups,
94+
attributes: attributes?.length
95+
? await formatAttributes(attributes, attributeValues)
96+
: undefined,
97+
},
98+
});
99+
$.export("$summary", `Successfully added or updated member with phone number ${this.phoneNumber}`);
100+
return response;
101+
},
102+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import hullo from "../../hullo.app.mjs";
2+
3+
export default {
4+
key: "hullo-send-message",
5+
name: "Send Message",
6+
description: "Sends a personalized message to a Hullo member. [See the documentation](https://app.hullo.me/docs/index.html#?route=post-/endpoints/messages)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
hullo,
11+
phoneNumber: {
12+
propDefinition: [
13+
hullo,
14+
"phoneNumber",
15+
],
16+
},
17+
messageText: {
18+
type: "string",
19+
label: "Message Text",
20+
description: "The message text to send. Min length: 1, Max length: 640",
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.hullo.sendMessage({
25+
$,
26+
data: {
27+
phoneNumber: this.phoneNumber,
28+
messageText: this.messageText,
29+
},
30+
});
31+
$.export("$summary", `Successfully sent message to member with phone number: ${this.phoneNumber}`);
32+
return response;
33+
},
34+
};

components/hullo/hullo.app.mjs

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "hullo",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
attributes: {
8+
type: "string[]",
9+
label: "Attributes",
10+
description: "The attributes that describe the member",
11+
optional: true,
12+
async options() {
13+
const attributes = await this.listAttributes();
14+
return attributes?.map(({ name }) => name ) || [];
15+
},
16+
},
17+
phoneNumber: {
18+
type: "string",
19+
label: "Phone Number",
20+
description: "The phone number of the member",
21+
},
22+
},
523
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
24+
_baseUrl() {
25+
return "https://app.hullo.me/api/endpoints";
26+
},
27+
_makeRequest(opts = {}) {
28+
const {
29+
$ = this,
30+
path,
31+
...otherOpts
32+
} = opts;
33+
return axios($, {
34+
...otherOpts,
35+
url: `${this._baseUrl()}${path}`,
36+
headers: {
37+
"X-API-KEY": `${this.$auth.api_key}`,
38+
},
39+
});
40+
},
41+
listAttributes(opts = {}) {
42+
return this._makeRequest({
43+
path: "/attributes",
44+
...opts,
45+
});
46+
},
47+
sendMessage(opts = {}) {
48+
return this._makeRequest({
49+
method: "POST",
50+
path: "/messages",
51+
...opts,
52+
});
53+
},
54+
addOrUpdateMember(opts = {}) {
55+
return this._makeRequest({
56+
method: "POST",
57+
path: "/members",
58+
...opts,
59+
});
960
},
1061
},
11-
};
62+
};

components/hullo/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/hullo",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Hullo Components",
55
"main": "hullo.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+
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)