From 604f94034200edccdf1a74f7e7cd769160c5108b Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Wed, 9 Oct 2024 16:01:48 -0400 Subject: [PATCH 1/4] init --- .../add-update-member/add-update-member.mjs | 29 +++++++++ .../actions/send-message/send-message.mjs | 29 +++++++++ components/hullo/hullo.app.mjs | 61 +++++++++++++++++-- 3 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 components/hullo/actions/add-update-member/add-update-member.mjs create mode 100644 components/hullo/actions/send-message/send-message.mjs diff --git a/components/hullo/actions/add-update-member/add-update-member.mjs b/components/hullo/actions/add-update-member/add-update-member.mjs new file mode 100644 index 0000000000000..bdb4fe9a906d5 --- /dev/null +++ b/components/hullo/actions/add-update-member/add-update-member.mjs @@ -0,0 +1,29 @@ +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", + version: "0.0.{{ts}}", + type: "action", + props: { + hullo, + memberId: { + propDefinition: [ + hullo, + "memberId", + ], + }, + memberInfo: { + propDefinition: [ + hullo, + "memberInfo", + ], + }, + }, + async run({ $ }) { + const response = await this.hullo.addOrUpdateMember(this.memberId, this.memberInfo); + $.export("$summary", `Successfully added or updated member with ID ${this.memberId}`); + return response; + }, +}; diff --git a/components/hullo/actions/send-message/send-message.mjs b/components/hullo/actions/send-message/send-message.mjs new file mode 100644 index 0000000000000..e63fdc3a1de1c --- /dev/null +++ b/components/hullo/actions/send-message/send-message.mjs @@ -0,0 +1,29 @@ +import hullo from "../../hullo.app.mjs"; + +export default { + key: "hullo-send-message", + name: "Send Message", + description: "Sends a personalized message to a Hullo member.", + version: "0.0.{{ts}}", + type: "action", + props: { + hullo, + memberId: { + propDefinition: [ + hullo, + "memberId", + ], + }, + messageContent: { + propDefinition: [ + hullo, + "messageContent", + ], + }, + }, + async run({ $ }) { + const response = await this.hullo.sendMessage(this.memberId, this.messageContent); + $.export("$summary", `Successfully sent message to member with ID: ${this.memberId}`); + return response; + }, +}; diff --git a/components/hullo/hullo.app.mjs b/components/hullo/hullo.app.mjs index 57f26a142d195..c1a9df122009e 100644 --- a/components/hullo/hullo.app.mjs +++ b/components/hullo/hullo.app.mjs @@ -1,11 +1,62 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "hullo", - propDefinitions: {}, + propDefinitions: { + memberId: { + type: "string", + label: "Member ID", + description: "The ID of the Hullo member", + }, + messageContent: { + type: "string", + label: "Message Content", + description: "The content of the message to send", + }, + memberInfo: { + type: "object", + label: "Member Info", + description: "Details of the member such as name, email, etc.", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://app.hullo.me/api"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + method = "GET", + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.api_token}`, + }, + }); + }, + async sendMessage(memberId, messageContent) { + return this._makeRequest({ + method: "POST", + path: `/members/${memberId}/messages`, + data: { + content: messageContent, + }, + }); + }, + async addOrUpdateMember(memberId, memberInfo) { + return this._makeRequest({ + method: "PUT", + path: `/members/${memberId}`, + data: memberInfo, + }); }, }, -}; \ No newline at end of file +}; From 04ed2bff8e44a1a2dffe29b6521cde6f41cb4f4c Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Thu, 10 Oct 2024 11:12:46 -0400 Subject: [PATCH 2/4] new components --- .../add-update-member/add-update-member.mjs | 89 +++++++++++++++++-- .../actions/send-message/send-message.mjs | 27 +++--- components/hullo/hullo.app.mjs | 58 ++++++------ components/hullo/package.json | 5 +- 4 files changed, 130 insertions(+), 49 deletions(-) diff --git a/components/hullo/actions/add-update-member/add-update-member.mjs b/components/hullo/actions/add-update-member/add-update-member.mjs index bdb4fe9a906d5..58105ab8d6255 100644 --- a/components/hullo/actions/add-update-member/add-update-member.mjs +++ b/components/hullo/actions/add-update-member/add-update-member.mjs @@ -3,27 +3,100 @@ 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", - version: "0.0.{{ts}}", + 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, - memberId: { + phoneNumber: { propDefinition: [ hullo, - "memberId", + "phoneNumber", ], }, - memberInfo: { + 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, - "memberInfo", + "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 response = await this.hullo.addOrUpdateMember(this.memberId, this.memberInfo); - $.export("$summary", `Successfully added or updated member with ID ${this.memberId}`); + 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; }, }; diff --git a/components/hullo/actions/send-message/send-message.mjs b/components/hullo/actions/send-message/send-message.mjs index e63fdc3a1de1c..80d04b153ee6c 100644 --- a/components/hullo/actions/send-message/send-message.mjs +++ b/components/hullo/actions/send-message/send-message.mjs @@ -3,27 +3,32 @@ import hullo from "../../hullo.app.mjs"; export default { key: "hullo-send-message", name: "Send Message", - description: "Sends a personalized message to a Hullo member.", - version: "0.0.{{ts}}", + 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, - memberId: { + phoneNumber: { propDefinition: [ hullo, - "memberId", + "phoneNumber", ], }, - messageContent: { - propDefinition: [ - hullo, - "messageContent", - ], + 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(this.memberId, this.messageContent); - $.export("$summary", `Successfully sent message to member with ID: ${this.memberId}`); + 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; }, }; diff --git a/components/hullo/hullo.app.mjs b/components/hullo/hullo.app.mjs index c1a9df122009e..2cdfbd108d208 100644 --- a/components/hullo/hullo.app.mjs +++ b/components/hullo/hullo.app.mjs @@ -4,58 +4,58 @@ export default { type: "app", app: "hullo", propDefinitions: { - memberId: { - type: "string", - label: "Member ID", - description: "The ID of the Hullo member", + 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 ) || []; + }, }, - messageContent: { + phoneNumber: { type: "string", - label: "Message Content", - description: "The content of the message to send", - }, - memberInfo: { - type: "object", - label: "Member Info", - description: "Details of the member such as name, email, etc.", + label: "Phone Number", + description: "The phone number of the member", }, }, methods: { _baseUrl() { - return "https://app.hullo.me/api"; + return "https://app.hullo.me/api/endpoints"; }, - async _makeRequest(opts = {}) { + _makeRequest(opts = {}) { const { $ = this, - method = "GET", path, - headers, ...otherOpts } = opts; return axios($, { ...otherOpts, - method, - url: this._baseUrl() + path, + url: `${this._baseUrl()}${path}`, headers: { - ...headers, - Authorization: `Bearer ${this.$auth.api_token}`, + "X-API-KEY": `${this.$auth.api_key}`, }, }); }, - async sendMessage(memberId, messageContent) { + listAttributes(opts = {}) { + return this._makeRequest({ + path: "/attributes", + ...opts, + }); + }, + sendMessage(opts = {}) { return this._makeRequest({ method: "POST", - path: `/members/${memberId}/messages`, - data: { - content: messageContent, - }, + path: "/messages", + ...opts, }); }, - async addOrUpdateMember(memberId, memberInfo) { + addOrUpdateMember(opts = {}) { return this._makeRequest({ - method: "PUT", - path: `/members/${memberId}`, - data: memberInfo, + method: "POST", + path: "/members", + ...opts, }); }, }, diff --git a/components/hullo/package.json b/components/hullo/package.json index 4cb0e1bd5c1f3..f0d60291d0dbb 100644 --- a/components/hullo/package.json +++ b/components/hullo/package.json @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} From 5319707167282b522e10ceba8f7425dd117a8445 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Thu, 10 Oct 2024 11:14:11 -0400 Subject: [PATCH 3/4] pnpm-lock.yaml --- pnpm-lock.yaml | 107 +++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7d0df26443b8f..34023f0b384d9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4645,7 +4645,10 @@ importers: node-fetch: 3.3.2 components/hullo: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/humanitix: specifiers: {} @@ -12938,6 +12941,55 @@ packages: - aws-crt dev: false + /@aws-sdk/client-sso-oidc/3.600.0_tdq3komn4zwyd65w7klbptsu34: + resolution: {integrity: sha512-7+I8RWURGfzvChyNQSyj5/tKrqRbzRl7H+BnTOf/4Vsw1nFOi5ROhlhD4X/Y0QCTacxnaoNcIrqnY7uGGvVRzw==} + engines: {node: '>=16.0.0'} + dependencies: + '@aws-crypto/sha256-browser': 5.2.0 + '@aws-crypto/sha256-js': 5.2.0 + '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/core': 3.598.0 + '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 + '@aws-sdk/middleware-host-header': 3.598.0 + '@aws-sdk/middleware-logger': 3.598.0 + '@aws-sdk/middleware-recursion-detection': 3.598.0 + '@aws-sdk/middleware-user-agent': 3.598.0 + '@aws-sdk/region-config-resolver': 3.598.0 + '@aws-sdk/types': 3.598.0 + '@aws-sdk/util-endpoints': 3.598.0 + '@aws-sdk/util-user-agent-browser': 3.598.0 + '@aws-sdk/util-user-agent-node': 3.598.0 + '@smithy/config-resolver': 3.0.3 + '@smithy/core': 2.2.3 + '@smithy/fetch-http-handler': 3.2.1 + '@smithy/hash-node': 3.0.2 + '@smithy/invalid-dependency': 3.0.2 + '@smithy/middleware-content-length': 3.0.2 + '@smithy/middleware-endpoint': 3.0.4 + '@smithy/middleware-retry': 3.0.6 + '@smithy/middleware-serde': 3.0.3 + '@smithy/middleware-stack': 3.0.3 + '@smithy/node-config-provider': 3.1.3 + '@smithy/node-http-handler': 3.1.2 + '@smithy/protocol-http': 4.0.3 + '@smithy/smithy-client': 3.1.6 + '@smithy/types': 3.3.0 + '@smithy/url-parser': 3.0.3 + '@smithy/util-base64': 3.0.0 + '@smithy/util-body-length-browser': 3.0.0 + '@smithy/util-body-length-node': 3.0.0 + '@smithy/util-defaults-mode-browser': 3.0.6 + '@smithy/util-defaults-mode-node': 3.0.6 + '@smithy/util-endpoints': 2.0.3 + '@smithy/util-middleware': 3.0.3 + '@smithy/util-retry': 3.0.2 + '@smithy/util-utf8': 3.0.0 + tslib: 2.6.3 + transitivePeerDependencies: + - '@aws-sdk/client-sts' + - aws-crt + dev: false + /@aws-sdk/client-sso/3.423.0: resolution: {integrity: sha512-znIufHkwhCIePgaYciIs3x/+BpzR57CZzbCKHR9+oOvGyufEPPpUT5bFLvbwTgfiVkTjuk6sG/ES3U5Bc+xtrA==} engines: {node: '>=14.0.0'} @@ -13173,7 +13225,7 @@ packages: dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0 + '@aws-sdk/client-sso-oidc': 3.600.0_tdq3komn4zwyd65w7klbptsu34 '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 '@aws-sdk/middleware-host-header': 3.598.0 @@ -13215,55 +13267,6 @@ packages: - aws-crt dev: false - /@aws-sdk/client-sts/3.600.0_dseaa2p5u2yk67qiepewcq3hkq: - resolution: {integrity: sha512-KQG97B7LvTtTiGmjlrG1LRAY8wUvCQzrmZVV5bjrJ/1oXAU7DITYwVbSJeX9NWg6hDuSk0VE3MFwIXS2SvfLIA==} - engines: {node: '>=16.0.0'} - dependencies: - '@aws-crypto/sha256-browser': 5.2.0 - '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0 - '@aws-sdk/core': 3.598.0 - '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 - '@aws-sdk/middleware-host-header': 3.598.0 - '@aws-sdk/middleware-logger': 3.598.0 - '@aws-sdk/middleware-recursion-detection': 3.598.0 - '@aws-sdk/middleware-user-agent': 3.598.0 - '@aws-sdk/region-config-resolver': 3.598.0 - '@aws-sdk/types': 3.598.0 - '@aws-sdk/util-endpoints': 3.598.0 - '@aws-sdk/util-user-agent-browser': 3.598.0 - '@aws-sdk/util-user-agent-node': 3.598.0 - '@smithy/config-resolver': 3.0.3 - '@smithy/core': 2.2.3 - '@smithy/fetch-http-handler': 3.2.1 - '@smithy/hash-node': 3.0.2 - '@smithy/invalid-dependency': 3.0.2 - '@smithy/middleware-content-length': 3.0.2 - '@smithy/middleware-endpoint': 3.0.4 - '@smithy/middleware-retry': 3.0.6 - '@smithy/middleware-serde': 3.0.3 - '@smithy/middleware-stack': 3.0.3 - '@smithy/node-config-provider': 3.1.3 - '@smithy/node-http-handler': 3.1.2 - '@smithy/protocol-http': 4.0.3 - '@smithy/smithy-client': 3.1.6 - '@smithy/types': 3.3.0 - '@smithy/url-parser': 3.0.3 - '@smithy/util-base64': 3.0.0 - '@smithy/util-body-length-browser': 3.0.0 - '@smithy/util-body-length-node': 3.0.0 - '@smithy/util-defaults-mode-browser': 3.0.6 - '@smithy/util-defaults-mode-node': 3.0.6 - '@smithy/util-endpoints': 2.0.3 - '@smithy/util-middleware': 3.0.3 - '@smithy/util-retry': 3.0.2 - '@smithy/util-utf8': 3.0.0 - tslib: 2.6.3 - transitivePeerDependencies: - - '@aws-sdk/client-sso-oidc' - - aws-crt - dev: false - /@aws-sdk/core/3.556.0: resolution: {integrity: sha512-vJaSaHw2kPQlo11j/Rzuz0gk1tEaKdz+2ser0f0qZ5vwFlANjt08m/frU17ctnVKC1s58bxpctO/1P894fHLrA==} engines: {node: '>=14.0.0'} @@ -17590,7 +17593,7 @@ packages: '@aws-sdk/client-sns': 3.423.0 '@aws-sdk/client-sqs': 3.423.0 '@aws-sdk/client-ssm': 3.423.0 - '@aws-sdk/client-sts': 3.600.0_dseaa2p5u2yk67qiepewcq3hkq + '@aws-sdk/client-sts': 3.600.0 '@aws-sdk/s3-request-presigner': 3.609.0 '@pipedream/helper_functions': 0.3.12 '@pipedream/platform': 1.6.6 From 8f5f35b1253a6b1be197ec2dc0b8c7a02cda2d9c Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Thu, 10 Oct 2024 11:18:59 -0400 Subject: [PATCH 4/4] package.json --- components/hullo/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/hullo/package.json b/components/hullo/package.json index f0d60291d0dbb..205eb5e0837bd 100644 --- a/components/hullo/package.json +++ b/components/hullo/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/hullo", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Hullo Components", "main": "hullo.app.mjs", "keywords": [