Skip to content
Merged
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
102 changes: 102 additions & 0 deletions components/hullo/actions/add-update-member/add-update-member.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import hullo from "../../hullo.app.mjs";

export default {
key: "hullo-add-update-member",
name: "Add or Update Member",
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)",
version: "0.0.1",
type: "action",
props: {
hullo,
phoneNumber: {
propDefinition: [
hullo,
"phoneNumber",
],
},
fullName: {
type: "string",
label: "Full Name",
description: "The full name of the member. REQUIRED if creating a new member.",
optional: true,
},
registrationDate: {
type: "string",
label: "Registration Date",
description: "The date the member was registered in ISO-8601 format. Example: `2000-01-23T04:56:07.000+00:00`",
optional: true,
},
groups: {
type: "string[]",
label: "Groups",
description: "An array containing the names of groups this member belongs to",
optional: true,
},
attributes: {
propDefinition: [
hullo,
"attributes",
],
reloadProps: true,
},
},
async additionalProps() {
const props = {};
if (!this.attributes?.length) {
return props;
}
for (const attribute of this.attributes) {
props[attribute] = {
type: "string",
label: attribute,
description: `Value for ${attribute}`,
};
}
return props;
},
methods: {
async formatAttributes(attributeKeys, attributeValues) {
const attributes = await this.hullo.listAttributes();
const formattedAttributes = {};
for (const key of attributeKeys) {
const { type } = attributes.find(({ name }) => name === key);
const value = type === "NUMBER"
? +attributeValues[key]
: type === "LIST"
? JSON.parse(attributeValues[key])
: attributeValues[key];
formattedAttributes[key] = [
value,
];
}
return formattedAttributes;
},
},
async run({ $ }) {
const {
hullo,
formatAttributes,
phoneNumber,
fullName,
registrationDate,
groups,
attributes,
...attributeValues
} = this;

const response = await hullo.addOrUpdateMember({
$,
data: {
phoneNumber,
fullName,
registrationDate,
groups,
attributes: attributes?.length
? await formatAttributes(attributes, attributeValues)
: undefined,
},
});
$.export("$summary", `Successfully added or updated member with phone number ${this.phoneNumber}`);
return response;
},
};
34 changes: 34 additions & 0 deletions components/hullo/actions/send-message/send-message.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import hullo from "../../hullo.app.mjs";

export default {
key: "hullo-send-message",
name: "Send Message",
description: "Sends a personalized message to a Hullo member. [See the documentation](https://app.hullo.me/docs/index.html#?route=post-/endpoints/messages)",
version: "0.0.1",
type: "action",
props: {
hullo,
phoneNumber: {
propDefinition: [
hullo,
"phoneNumber",
],
},
messageText: {
type: "string",
label: "Message Text",
description: "The message text to send. Min length: 1, Max length: 640",
},
},
async run({ $ }) {
const response = await this.hullo.sendMessage({
$,
data: {
phoneNumber: this.phoneNumber,
messageText: this.messageText,
},
});
$.export("$summary", `Successfully sent message to member with phone number: ${this.phoneNumber}`);
return response;
},
};
61 changes: 56 additions & 5 deletions components/hullo/hullo.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,62 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "hullo",
propDefinitions: {},
propDefinitions: {
attributes: {
type: "string[]",
label: "Attributes",
description: "The attributes that describe the member",
optional: true,
async options() {
const attributes = await this.listAttributes();
return attributes?.map(({ name }) => name ) || [];
},
},
phoneNumber: {
type: "string",
label: "Phone Number",
description: "The phone number of the member",
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://app.hullo.me/api/endpoints";
},
_makeRequest(opts = {}) {
const {
$ = this,
path,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: {
"X-API-KEY": `${this.$auth.api_key}`,
},
});
},
listAttributes(opts = {}) {
return this._makeRequest({
path: "/attributes",
...opts,
});
},
sendMessage(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/messages",
...opts,
});
},
addOrUpdateMember(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/members",
...opts,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/hullo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/hullo",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Hullo Components",
"main": "hullo.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
107 changes: 55 additions & 52 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading