-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Gmail - new-email-received trigger updates #14665
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
WalkthroughThe pull request includes updates to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
components/gmail/sources/new-email-received/new-email-received.mjs (2)
422-430
: Add JSDoc documentation for better maintainabilityGood extraction of the history retrieval logic into a reusable method. Consider adding JSDoc documentation to describe the parameters and return value.
+/** + * Retrieves email history from Gmail API + * @param {string} startHistoryId - The starting point for history retrieval + * @returns {Promise<Object>} History response from Gmail API + */ getHistoryResponse(startHistoryId) { return this.gmail.listHistory({ startHistoryId, historyTypes: [ "messageAdded", ], labelId: this.label, }); },
491-511
: Enhance error handling specificity and variable declarationThe error handling implementation successfully addresses the PR objective of handling invalid/expired
startHistoryId
. Consider these improvements:
- Be more specific about the error type being caught
- Use object destructuring for cleaner variable declaration
- let startHistoryId = Math.min( - parseInt(lastProcessedHistoryId), - parseInt(receivedHistoryId), - ); + const startHistoryId = Math.min( + parseInt(lastProcessedHistoryId), + parseInt(receivedHistoryId), + ); console.log("Using startHistoryId:", startHistoryId); - let historyResponse; try { - historyResponse = await this.getHistoryResponse(startHistoryId); + const historyResponse = await this.getHistoryResponse(startHistoryId); - } catch { + } catch (error) { + // Check if error is due to invalid/expired historyId + if (error.code !== 404) { + throw error; // Re-throw unexpected errors + } // catch error thrown if startHistoryId is invalid or expired // emit recent messages to attempt to avoid missing any messages await this.emitRecentMessages(); // set startHistoryId to the historyId received from the webhook - startHistoryId = parseInt(receivedHistoryId); + const fallbackHistoryId = parseInt(receivedHistoryId); console.log("Using startHistoryId:", startHistoryId); - historyResponse = await this.getHistoryResponse(startHistoryId); + return await this.getHistoryResponse(fallbackHistoryId); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
components/gmail/package.json
(1 hunks)components/gmail/sources/new-email-received/new-email-received.mjs
(3 hunks)
✅ Files skipped from review due to trivial changes (1)
- components/gmail/package.json
🔇 Additional comments (1)
components/gmail/sources/new-email-received/new-email-received.mjs (1)
18-18
: LGTM: Version bump is appropriate
Version increment from 0.1.7 to 0.1.8 aligns with the scope of changes being introduced.
Hi everyone, all test cases are passed! Ready for release! Test report |
If retrieving history with the existing
startHistoryId
throws an error, fall back to theretrievedHistoryId
retrieved in the webhook payload and emit recent messages to avoid skipping any messages.Summary by CodeRabbit
New Email Received
component with improved error handling and a new method for retrieving email history.New Email Received
functionality.