-
Notifications
You must be signed in to change notification settings - Fork 5.5k
HubSpot new action #18143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
HubSpot new action #18143
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0c6f36d
'Get Associated Emails' action
GTFalcao f40d52a
package/pnpm bump
GTFalcao de4c691
Adjusting action requests
GTFalcao b41f4e2
Expanding objectType prop
GTFalcao e4ae1c6
Adjusting request limit
GTFalcao b956907
Syntax adjustments
GTFalcao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
components/hubspot/actions/get-associated-emails/get-associated-emails.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.