Skip to content

Commit 04ed2bf

Browse files
committed
new components
1 parent 604f940 commit 04ed2bf

File tree

4 files changed

+130
-49
lines changed

4 files changed

+130
-49
lines changed

components/hullo/actions/add-update-member/add-update-member.mjs

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,100 @@ import hullo from "../../hullo.app.mjs";
33
export default {
44
key: "hullo-add-update-member",
55
name: "Add or Update Member",
6-
description: "Adds a new member or updates an existing member's data in Hullo",
7-
version: "0.0.{{ts}}",
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",
88
type: "action",
99
props: {
1010
hullo,
11-
memberId: {
11+
phoneNumber: {
1212
propDefinition: [
1313
hullo,
14-
"memberId",
14+
"phoneNumber",
1515
],
1616
},
17-
memberInfo: {
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: {
1836
propDefinition: [
1937
hullo,
20-
"memberInfo",
38+
"attributes",
2139
],
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;
2273
},
2374
},
2475
async run({ $ }) {
25-
const response = await this.hullo.addOrUpdateMember(this.memberId, this.memberInfo);
26-
$.export("$summary", `Successfully added or updated member with ID ${this.memberId}`);
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}`);
27100
return response;
28101
},
29102
};

components/hullo/actions/send-message/send-message.mjs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,32 @@ import hullo from "../../hullo.app.mjs";
33
export default {
44
key: "hullo-send-message",
55
name: "Send Message",
6-
description: "Sends a personalized message to a Hullo member.",
7-
version: "0.0.{{ts}}",
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",
88
type: "action",
99
props: {
1010
hullo,
11-
memberId: {
11+
phoneNumber: {
1212
propDefinition: [
1313
hullo,
14-
"memberId",
14+
"phoneNumber",
1515
],
1616
},
17-
messageContent: {
18-
propDefinition: [
19-
hullo,
20-
"messageContent",
21-
],
17+
messageText: {
18+
type: "string",
19+
label: "Message Text",
20+
description: "The message text to send. Min length: 1, Max length: 640",
2221
},
2322
},
2423
async run({ $ }) {
25-
const response = await this.hullo.sendMessage(this.memberId, this.messageContent);
26-
$.export("$summary", `Successfully sent message to member with ID: ${this.memberId}`);
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}`);
2732
return response;
2833
},
2934
};

components/hullo/hullo.app.mjs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,58 @@ export default {
44
type: "app",
55
app: "hullo",
66
propDefinitions: {
7-
memberId: {
8-
type: "string",
9-
label: "Member ID",
10-
description: "The ID of the Hullo member",
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+
},
1116
},
12-
messageContent: {
17+
phoneNumber: {
1318
type: "string",
14-
label: "Message Content",
15-
description: "The content of the message to send",
16-
},
17-
memberInfo: {
18-
type: "object",
19-
label: "Member Info",
20-
description: "Details of the member such as name, email, etc.",
19+
label: "Phone Number",
20+
description: "The phone number of the member",
2121
},
2222
},
2323
methods: {
2424
_baseUrl() {
25-
return "https://app.hullo.me/api";
25+
return "https://app.hullo.me/api/endpoints";
2626
},
27-
async _makeRequest(opts = {}) {
27+
_makeRequest(opts = {}) {
2828
const {
2929
$ = this,
30-
method = "GET",
3130
path,
32-
headers,
3331
...otherOpts
3432
} = opts;
3533
return axios($, {
3634
...otherOpts,
37-
method,
38-
url: this._baseUrl() + path,
35+
url: `${this._baseUrl()}${path}`,
3936
headers: {
40-
...headers,
41-
Authorization: `Bearer ${this.$auth.api_token}`,
37+
"X-API-KEY": `${this.$auth.api_key}`,
4238
},
4339
});
4440
},
45-
async sendMessage(memberId, messageContent) {
41+
listAttributes(opts = {}) {
42+
return this._makeRequest({
43+
path: "/attributes",
44+
...opts,
45+
});
46+
},
47+
sendMessage(opts = {}) {
4648
return this._makeRequest({
4749
method: "POST",
48-
path: `/members/${memberId}/messages`,
49-
data: {
50-
content: messageContent,
51-
},
50+
path: "/messages",
51+
...opts,
5252
});
5353
},
54-
async addOrUpdateMember(memberId, memberInfo) {
54+
addOrUpdateMember(opts = {}) {
5555
return this._makeRequest({
56-
method: "PUT",
57-
path: `/members/${memberId}`,
58-
data: memberInfo,
56+
method: "POST",
57+
path: "/members",
58+
...opts,
5959
});
6060
},
6161
},

components/hullo/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
}

0 commit comments

Comments
 (0)