diff --git a/components/hubspot/actions/create-communication/common-app-prop.mjs b/components/hubspot/actions/create-communication/common-app-prop.mjs new file mode 100644 index 0000000000000..c7c1252b09765 --- /dev/null +++ b/components/hubspot/actions/create-communication/common-app-prop.mjs @@ -0,0 +1,10 @@ +import hubspot from "../../hubspot.app.mjs"; + +export default { + props: { + hubspot: { + ...hubspot, + reloadProps: true, + }, + }, +}; diff --git a/components/hubspot/actions/create-communication/create-communication.mjs b/components/hubspot/actions/create-communication/create-communication.mjs new file mode 100644 index 0000000000000..ef3113dce46c5 --- /dev/null +++ b/components/hubspot/actions/create-communication/create-communication.mjs @@ -0,0 +1,99 @@ +import common from "../common/common-create.mjs"; +import appProp from "./common-app-prop.mjs"; +import { ConfigurationError } from "@pipedream/platform"; +import { ASSOCIATION_CATEGORY } from "../../common/constants.mjs"; + +export default { + ...common, + key: "hubspot-create-communication", + name: "Create Communication", + description: "Create a WhatsApp, LinkedIn, or SMS message. [See the documentation](https://developers.hubspot.com/beta-docs/reference/api/crm/engagements/communications/v3#post-%2Fcrm%2Fv3%2Fobjects%2Fcommunications)", + version: "0.0.1", + type: "action", + props: { + ...appProp.props, + toObjectType: { + propDefinition: [ + appProp.props.hubspot, + "objectType", + ], + label: "Associated Object Type", + description: "Type of object the communication is being associated with", + optional: true, + }, + toObjectId: { + propDefinition: [ + appProp.props.hubspot, + "objectId", + (c) => ({ + objectType: c.toObjectType, + }), + ], + label: "Associated Object", + description: "ID of object the communication is being associated with", + optional: true, + }, + associationType: { + propDefinition: [ + appProp.props.hubspot, + "associationType", + (c) => ({ + fromObjectType: "communications", + toObjectType: c.toObjectType, + }), + ], + description: "A unique identifier to indicate the association type between the communication and the other object", + optional: true, + }, + }, + methods: { + ...common.methods, + getObjectType() { + return "communications"; + }, + }, + async run({ $ }) { + const { + hubspot, + /* eslint-disable no-unused-vars */ + toObjectType, + toObjectId, + associationType, + getObjectType, + ...properties + } = this; + + if ((toObjectId && !associationType) || (!toObjectId && associationType)) { + throw new ConfigurationError("Both `toObjectId` and `associationType` must be entered"); + } + + const response = await hubspot.createObject({ + $, + objectType: getObjectType(), + data: { + associations: toObjectId + ? [ + { + types: [ + { + associationTypeId: associationType, + associationCategory: ASSOCIATION_CATEGORY.HUBSPOT_DEFINED, + }, + ], + to: { + id: toObjectId, + }, + }, + ] + : undefined, + properties: { + ...properties, + hs_communication_logged_from: "CRM", + }, + }, + }); + + $.export("$summary", `Successfully created communication with ID ${response.id}`); + return response; + }, +}; diff --git a/components/hubspot/package.json b/components/hubspot/package.json index 6bfcb75459a27..2b12b525df711 100644 --- a/components/hubspot/package.json +++ b/components/hubspot/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/hubspot", - "version": "0.8.5", + "version": "0.9.0", "description": "Pipedream Hubspot Components", "main": "hubspot.app.mjs", "keywords": [ @@ -10,7 +10,7 @@ "homepage": "https://pipedream.com/apps/hubspot", "author": "Pipedream (https://pipedream.com/)", "dependencies": { - "@pipedream/platform": "^1.6.0", + "@pipedream/platform": "^3.0.0", "bottleneck": "^2.19.5" }, "gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 342337b599d8c..37d0964e4bd6a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4258,11 +4258,11 @@ importers: components/hubspot: specifiers: - '@pipedream/platform': ^1.6.0 + '@pipedream/platform': ^3.0.0 bottleneck: ^2.19.5 package: ^1.0.1 dependencies: - '@pipedream/platform': 1.6.0 + '@pipedream/platform': 3.0.0 bottleneck: 2.19.5 devDependencies: package: 1.0.1