-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Learned patterns from labels ( cold emails only ) #689
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
8 commits
Select commit
Hold shift + click to select a range
b0f993c
Initial commit for learned patterns from labels
edulelis b07e327
Update consts to string references
edulelis 2686f75
Remove moving ColdEmails. Update tests
edulelis 40fabc2
Categorize event type for processed history
edulelis f9a67ff
simplify var name
edulelis b10af1f
Separate files and PR feedback
edulelis 098740b
PR feedback
edulelis 0b886d7
Handle only cold email tag removal for now
edulelis 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,10 @@ import { ColdEmailSetting } from "@prisma/client"; | |
| import { captureException } from "@/utils/error"; | ||
| import { unwatchEmails } from "@/app/api/watch/controller"; | ||
| import { createEmailProvider } from "@/utils/email/provider"; | ||
| import type { ProcessHistoryOptions } from "@/app/api/google/webhook/types"; | ||
| import { | ||
| HistoryEventType, | ||
| type ProcessHistoryOptions, | ||
| } from "@/app/api/google/webhook/types"; | ||
| import { processHistoryItem } from "@/app/api/google/webhook/process-history-item"; | ||
| import { logger } from "@/app/api/google/webhook/logger"; | ||
| import { getHistory } from "@/utils/gmail/history"; | ||
|
|
@@ -162,7 +165,7 @@ export async function processHistoryForUser( | |
| // NOTE this can cause problems if we're way behind | ||
| // NOTE this doesn't include startHistoryId in the results | ||
| startHistoryId, | ||
| historyTypes: ["messageAdded", "labelAdded"], | ||
| historyTypes: ["messageAdded", "labelAdded", "labelRemoved"], | ||
| maxResults: 500, | ||
| }); | ||
|
|
||
|
|
@@ -232,26 +235,43 @@ async function processHistory(options: ProcessHistoryOptions) { | |
| const historyMessages = [ | ||
| ...(h.messagesAdded || []), | ||
| ...(h.labelsAdded || []), | ||
| ...(h.labelsRemoved || []), | ||
| ]; | ||
|
|
||
| if (!historyMessages.length) continue; | ||
|
|
||
| const inboxMessages = historyMessages.filter(isInboxOrSentMessage); | ||
| const uniqueMessages = uniqBy(inboxMessages, (m) => m.message?.id); | ||
| const allEvents = [ | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a message type field here, wrapping the event item, so it is possible to discover the actual event tied to the message in the underlying functions. |
||
| ...(h.messagesAdded || []) | ||
| .filter(isInboxOrSentMessage) | ||
| .map((m) => ({ type: HistoryEventType.MESSAGE_ADDED, item: m })), | ||
| ...(h.labelsAdded || []).map((m) => ({ | ||
| type: HistoryEventType.LABEL_ADDED, | ||
| item: m, | ||
| })), | ||
| ...(h.labelsRemoved || []).map((m) => ({ | ||
| type: HistoryEventType.LABEL_REMOVED, | ||
| item: m, | ||
| })), | ||
| ]; | ||
|
|
||
| const uniqueEvents = uniqBy( | ||
| allEvents, | ||
| (e) => `${e.type}:${e.item.message?.id}`, | ||
| ); | ||
|
|
||
| for (const m of uniqueMessages) { | ||
| for (const event of uniqueEvents) { | ||
| try { | ||
| await processHistoryItem(m, options); | ||
| await processHistoryItem(event, options); | ||
| } catch (error) { | ||
| captureException( | ||
| error, | ||
| { extra: { userEmail, messageId: m.message?.id } }, | ||
| { extra: { userEmail, messageId: event.item.message?.id } }, | ||
| userEmail, | ||
| ); | ||
| logger.error("Error processing history item", { | ||
| userEmail, | ||
| messageId: m.message?.id, | ||
| threadId: m.message?.threadId, | ||
| messageId: event.item.message?.id, | ||
| threadId: event.item.message?.threadId, | ||
| error: | ||
| error instanceof Error | ||
| ? { | ||
|
|
||
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.