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
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { DEFAULT_EMAIL_PROPERTIES } from "../../common/constants.mjs";
import hubspot from "../../hubspot.app.mjs";

export default {
key: "hubspot-get-associated-emails",
name: "Get Associated Emails",
description: "Retrieves emails associated with a specific object (contact, company, or deal). [See the documentation](https://developers.hubspot.com/docs/reference/api/crm/search)",
version: "0.0.1",
type: "action",
props: {
hubspot,
objectType: {
propDefinition: [
hubspot,
"objectType",
() => ({
includeCustom: true,
}),
],
label: "Associated Object Type",
description: "The type of the object the emails are associated with",
},
objectId: {
type: "string",
label: "Object ID",
description: "The ID of the object to get associated emails for",
propDefinition: [
hubspot,
"objectIds",
({ objectType }) => ({
objectType,
}),
],
},
additionalProperties: {
type: "string[]",
label: "Additional Properties",
description: "Additional properties to retrieve for the emails",
optional: true,
},
limit: {
type: "integer",
label: "Limit",
description: "Maximum number of emails to retrieve",
optional: true,
default: 20,
min: 1,
max: 100,
},
},
async run({ $ }) {
const properties = [
...DEFAULT_EMAIL_PROPERTIES,
...(this.additionalProperties || []),
];

const {
objectType, objectId, limit,
} = this;

const { results } = await this.hubspot.getAssociations({
$,
objectType,
objectId,
toObjectType: "emails",
params: {
limit,
},
});

if (!results?.length > 0) {
$.export("$summary", "No emails found with this association");
return [];
}

const emailIds = results.map((association) => ({
id: association.toObjectId,
}));

const { results: emails } = await this.hubspot.batchGetObjects({
$,
objectType: "emails",
data: {
properties,
inputs: emailIds,
},
});

// Sort emails by timestamp in descending order (most recent first)
emails?.sort((a, b) => {
const timestampA = new Date(a.properties?.hs_timestamp || 0).getTime();
const timestampB = new Date(b.properties?.hs_timestamp || 0).getTime();
return timestampB - timestampA;
}) || [];

const summary = `Successfully retrieved ${emails.length} email(s)`;

$.export("$summary", summary);

return emails;
},
};
12 changes: 12 additions & 0 deletions components/hubspot/common/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ const DEFAULT_LEAD_PROPERTIES = [
"hs_associated_company_name",
];

const DEFAULT_EMAIL_PROPERTIES = [
"hs_timestamp",
"hs_email_direction",
"hs_email_html",
"hs_email_status",
"hs_email_subject",
"hs_email_text",
"hs_attachment_ids",
"hs_email_headers",
];

const DEFAULT_MEETING_PROPERTIES = [
"hs_timestamp",
"hubspot_owner_id",
Expand Down Expand Up @@ -225,5 +236,6 @@ export {
DEFAULT_LINE_ITEM_PROPERTIES,
DEFAULT_LEAD_PROPERTIES,
ENGAGEMENT_TYPE_OPTIONS,
DEFAULT_EMAIL_PROPERTIES,
DEFAULT_MEETING_PROPERTIES,
};
2 changes: 1 addition & 1 deletion components/hubspot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/hubspot",
"version": "1.5.0",
"version": "1.6.0",
"description": "Pipedream Hubspot Components",
"main": "hubspot.app.mjs",
"keywords": [
Expand Down
9 changes: 3 additions & 6 deletions pnpm-lock.yaml

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

Loading