-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Pipedrive - search-notes & remove-duplicate-notes actions #17045
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
312f1c7
new actions
michelle0927 bbe30b4
pnpm-lock.yaml
michelle0927 f23c3b1
updates
michelle0927 cdd06b8
update
michelle0927 36f6ebb
update
michelle0927 ff56676
pnpm-lock.yaml
michelle0927 52270ef
remove console.log
michelle0927 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
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
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
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
148 changes: 148 additions & 0 deletions
148
components/pipedrive/actions/remove-duplicate-notes/remove-duplicate-notes.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,148 @@ | ||
import pipedriveApp from "../../pipedrive.app.mjs"; | ||
import { decode } from "html-entities"; | ||
|
||
export default { | ||
key: "pipedrive-remove-duplicate-notes", | ||
name: "Remove Duplicate Notes", | ||
description: "Remove duplicate notes from an object in Pipedrive. See the documentation for [getting notes](https://developers.pipedrive.com/docs/api/v1/Notes#getNotes) and [deleting notes](https://developers.pipedrive.com/docs/api/v1/Notes#deleteNote)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
pipedriveApp, | ||
leadId: { | ||
propDefinition: [ | ||
pipedriveApp, | ||
"leadId", | ||
], | ||
description: "The ID of the lead that the notes are attached to", | ||
}, | ||
dealId: { | ||
propDefinition: [ | ||
pipedriveApp, | ||
"dealId", | ||
], | ||
description: "The ID of the deal that the notes are attached to", | ||
}, | ||
personId: { | ||
propDefinition: [ | ||
pipedriveApp, | ||
"personId", | ||
], | ||
description: "The ID of the person that the notes are attached to", | ||
}, | ||
organizationId: { | ||
propDefinition: [ | ||
pipedriveApp, | ||
"organizationId", | ||
], | ||
description: "The ID of the organization that the notes are attached to", | ||
}, | ||
userId: { | ||
propDefinition: [ | ||
pipedriveApp, | ||
"userId", | ||
], | ||
description: "The ID of the user that the notes are attached to", | ||
}, | ||
projectId: { | ||
propDefinition: [ | ||
pipedriveApp, | ||
"projectId", | ||
], | ||
description: "The ID of the project that the notes are attached to", | ||
}, | ||
keyword: { | ||
type: "string", | ||
label: "Keyword", | ||
description: "Only remove duplicate notes that contain the specified keyword(s)", | ||
optional: true, | ||
}, | ||
}, | ||
methods: { | ||
getDuplicateNotes(notes) { | ||
const seenContent = new Map(); | ||
const uniqueNotes = []; | ||
const duplicates = []; | ||
|
||
// Sort notes by add_time (ascending) to keep the oldest duplicate | ||
const sortedNotes = notes.sort((a, b) => { | ||
const dateA = new Date(a.add_time); | ||
const dateB = new Date(b.add_time); | ||
return dateA - dateB; | ||
}); | ||
|
||
for (const note of sortedNotes) { | ||
// Normalize content by removing extra whitespace and converting to lowercase | ||
const decodedContent = decode(note.content || ""); | ||
const normalizedContent = decodedContent?.replace(/^\s*<br\s*\/?>|<br\s*\/?>\s*$/gi, "").trim() | ||
.toLowerCase(); | ||
|
||
if (!normalizedContent) { | ||
// Skip notes with empty content | ||
continue; | ||
} | ||
|
||
if (seenContent.has(normalizedContent)) { | ||
// This is a duplicate | ||
duplicates.push({ | ||
duplicate: note, | ||
original: seenContent.get(normalizedContent), | ||
}); | ||
} else { | ||
// This is the first occurrence | ||
seenContent.set(normalizedContent, note); | ||
uniqueNotes.push(note); | ||
} | ||
} | ||
|
||
return { | ||
uniqueNotes, | ||
duplicates, | ||
duplicateCount: duplicates.length, | ||
}; | ||
}, | ||
}, | ||
async run({ $ }) { | ||
let notes = await this.pipedriveApp.getPaginatedResources({ | ||
fn: this.pipedriveApp.getNotes, | ||
params: { | ||
user_id: this.userId, | ||
lead_id: this.leadId, | ||
deal_id: this.dealId, | ||
person_id: this.personId, | ||
org_id: this.organizationId, | ||
project_id: this.projectId, | ||
}, | ||
}); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (this.keyword) { | ||
notes = notes.filter((note) => | ||
note.content?.toLowerCase().includes(this.keyword.toLowerCase())); | ||
} | ||
|
||
let result = { | ||
notes, | ||
totalNotes: notes.length, | ||
}; | ||
|
||
const { | ||
uniqueNotes, duplicates, duplicateCount, | ||
} = this.getDuplicateNotes(notes); | ||
|
||
for (const note of duplicates) { | ||
await this.pipedriveApp.deleteNote(note.duplicate.id); | ||
} | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
result = { | ||
notes: uniqueNotes, | ||
totalNotes: uniqueNotes.length, | ||
duplicatesFound: duplicateCount, | ||
duplicates: duplicates, | ||
originalCount: notes.length, | ||
}; | ||
|
||
$.export("$summary", `Found ${notes.length} total note(s), removed ${duplicateCount} duplicate(s), returning ${uniqueNotes.length} unique note(s)`); | ||
|
||
return result; | ||
}, | ||
}; |
179 changes: 179 additions & 0 deletions
179
components/pipedrive/actions/search-notes/search-notes.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,179 @@ | ||
import pipedriveApp from "../../pipedrive.app.mjs"; | ||
|
||
export default { | ||
key: "pipedrive-search-notes", | ||
name: "Search Notes", | ||
description: "Search for notes in Pipedrive. [See the documentation](https://developers.pipedrive.com/docs/api/v1/Notes#getNotes)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
pipedriveApp, | ||
searchTerm: { | ||
type: "string", | ||
label: "Search Term", | ||
description: "The term to search for in the note content", | ||
optional: true, | ||
}, | ||
leadId: { | ||
propDefinition: [ | ||
pipedriveApp, | ||
"leadId", | ||
], | ||
description: "The ID of the lead that the note is attached to", | ||
}, | ||
dealId: { | ||
propDefinition: [ | ||
pipedriveApp, | ||
"dealId", | ||
], | ||
description: "The ID of the deal that the note is attached to", | ||
}, | ||
personId: { | ||
propDefinition: [ | ||
pipedriveApp, | ||
"personId", | ||
], | ||
description: "The ID of the person that the note is attached to", | ||
}, | ||
organizationId: { | ||
propDefinition: [ | ||
pipedriveApp, | ||
"organizationId", | ||
], | ||
description: "The ID of the organization that the note is attached to", | ||
}, | ||
userId: { | ||
propDefinition: [ | ||
pipedriveApp, | ||
"userId", | ||
], | ||
description: "The ID of the user that the note is attached to", | ||
}, | ||
projectId: { | ||
propDefinition: [ | ||
pipedriveApp, | ||
"projectId", | ||
], | ||
description: "The ID of the project that the note is attached to", | ||
}, | ||
sortField: { | ||
type: "string", | ||
label: "Sort Field", | ||
description: "The field name to sort by", | ||
options: [ | ||
"id", | ||
"user_id", | ||
"deal_id", | ||
"org_id", | ||
"person_id", | ||
"content", | ||
"add_time", | ||
"update_time", | ||
], | ||
optional: true, | ||
}, | ||
sortDirection: { | ||
type: "string", | ||
label: "Sort Direction", | ||
description: "The direction to sort the results in", | ||
options: [ | ||
"ASC", | ||
"DESC", | ||
], | ||
default: "DESC", | ||
optional: true, | ||
}, | ||
startDate: { | ||
type: "string", | ||
label: "Start Date", | ||
description: "The date in format of YYYY-MM-DD from which notes to fetch", | ||
optional: true, | ||
}, | ||
endDate: { | ||
type: "string", | ||
label: "End Date", | ||
description: "The date in format of YYYY-MM-DD until which notes to fetch to", | ||
optional: true, | ||
}, | ||
pinnedToLeadFlag: { | ||
type: "boolean", | ||
label: "Pinned to Lead Flag", | ||
description: "If `true`, the results are filtered by note to lead pinning state", | ||
optional: true, | ||
}, | ||
pinnedToDealFlag: { | ||
type: "boolean", | ||
label: "Pinned to Deal Flag", | ||
description: "If `true`, the results are filtered by note to deal pinning state", | ||
optional: true, | ||
}, | ||
pinnedToOrganizationFlag: { | ||
type: "boolean", | ||
label: "Pinned to Organization Flag", | ||
description: "If `true`, the results are filtered by note to organization pinning state", | ||
optional: true, | ||
}, | ||
pinnedToPersonFlag: { | ||
type: "boolean", | ||
label: "Pinned to Person Flag", | ||
description: "If `true`, the results are filtered by note to person pinning state", | ||
optional: true, | ||
}, | ||
pinnedToProjectFlag: { | ||
type: "boolean", | ||
label: "Pinned to Project Flag", | ||
description: "If `true`, the results are filtered by note to project pinning state", | ||
optional: true, | ||
}, | ||
maxResults: { | ||
type: "integer", | ||
label: "Max Results", | ||
description: "The maximum number of results to return", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
let notes = await this.pipedriveApp.getPaginatedResources({ | ||
fn: this.pipedriveApp.getNotes, | ||
params: { | ||
user_id: this.userId, | ||
lead_id: this.leadId, | ||
deal_id: this.dealId, | ||
person_id: this.personId, | ||
org_id: this.organizationId, | ||
project_id: this.projectId, | ||
sort: this.sortField | ||
? `${this.sortField} ${this.sortDirection}` | ||
: undefined, | ||
pinned_to_lead_flag: this.pinnedToLeadFlag === true | ||
? 1 | ||
: undefined, | ||
pinned_to_deal_flag: this.pinnedToDealFlag === true | ||
? 1 | ||
: undefined, | ||
pinned_to_organization_flag: this.pinnedToOrganizationFlag === true | ||
? 1 | ||
: undefined, | ||
pinned_to_person_flag: this.pinnedToPersonFlag === true | ||
? 1 | ||
: undefined, | ||
pinned_to_project_flag: this.pinnedToProjectFlag === true | ||
? 1 | ||
: undefined, | ||
start_date: this.startDate, | ||
end_date: this.endDate, | ||
}, | ||
max: this.maxResults, | ||
}); | ||
|
||
if (this.searchTerm) { | ||
notes = notes.filter((note) => | ||
note.content?.toLowerCase().includes(this.searchTerm.toLowerCase())); | ||
} | ||
|
||
$.export("$summary", `Successfully found ${notes.length} note${notes.length === 1 | ||
? "" | ||
: "s"}`); | ||
return notes; | ||
}, | ||
}; |
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
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.