Skip to content

Microsoft Outlook: New Attachment Received & Download Attachment #16324

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented Apr 16, 2025

Resolves #16270

Summary by CodeRabbit

  • New Features

    • Added the ability to download email attachments in Microsoft Outlook integrations.
    • Introduced a new event source to trigger workflows when new email attachments are received.
    • Enhanced event filtering for new email sources, allowing folder-specific monitoring.
  • Improvements

    • Expanded Microsoft Outlook integration to support listing and fetching email attachments.
  • Bug Fixes

    • Updated and streamlined internal module imports for improved reliability.
  • Chores

    • Incremented version numbers for various actions and sources to reflect recent updates.

Copy link

vercel bot commented Apr 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Apr 18, 2025 3:11pm
pipedream-docs ⬜️ Ignored (Inspect) Apr 18, 2025 3:11pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Apr 18, 2025 3:11pm

Copy link
Contributor

coderabbitai bot commented Apr 16, 2025

"""

Walkthrough

This update introduces new functionality to the Microsoft Outlook integration by adding a "Download Attachment" action and a "New Attachment Received (Instant)" source. The Outlook app component is extended with methods to list and fetch email attachments. The new source emits events for each new email attachment, including detailed metadata, while the new action downloads the specified attachment to a temporary file. Several existing actions and sources receive minor updates, primarily version increments and import path corrections. The package version is also incremented to reflect these enhancements.

Changes

File(s) Change Summary
components/microsoft_outlook/actions/download-attachment/download-attachment.mjs New action: Downloads an email attachment by message and attachment ID, saves it to /tmp, and returns file details.
components/microsoft_outlook/sources/new-attachment-received/new-attachment-received.mjs New source: Emits events for each new email attachment received, including attachment and message metadata.
components/microsoft_outlook/microsoft_outlook.app.mjs Added attachmentId prop, listAttachments and getAttachment methods to support attachment operations.
components/microsoft_outlook/sources/common/common-new-email.mjs New common module: Adds folder filtering and event handling for new email sources.
components/microsoft_outlook/sources/new-email/new-email.mjs Refactored: Uses new common module, removes props/hooks/methods now handled by the imported module, updates version.
components/microsoft_outlook/sources/new-contact/new-contact.mjs Import path corrected for common module, version incremented.
components/microsoft_outlook/sources/common/common.mjs Import path updated for microsoftOutlook app.
components/microsoft_outlook/actions/add-label-to-email/add-label-to-email.mjs
components/microsoft_outlook/actions/approve-workflow/approve-workflow.mjs
components/microsoft_outlook/actions/create-contact/create-contact.mjs
components/microsoft_outlook/actions/create-draft-email/create-draft-email.mjs
components/microsoft_outlook/actions/find-contacts/find-contacts.mjs
components/microsoft_outlook/actions/find-email/find-email.mjs
components/microsoft_outlook/actions/list-contacts/list-contacts.mjs
components/microsoft_outlook/actions/list-folders/list-folders.mjs
components/microsoft_outlook/actions/list-labels/list-labels.mjs
components/microsoft_outlook/actions/move-email-to-folder/move-email-to-folder.mjs
components/microsoft_outlook/actions/remove-label-from-email/remove-label-from-email.mjs
components/microsoft_outlook/actions/reply-to-email/reply-to-email.mjs
components/microsoft_outlook/actions/send-email/send-email.mjs
components/microsoft_outlook/actions/update-contact/update-contact.mjs
Version numbers incremented in action metadata only; no logic changes.
components/microsoft_outlook/package.json Package version updated from 1.4.1 to 1.5.0.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant NewAttachmentSource
    participant MicrosoftOutlookApp
    participant Workflow

    User->>NewAttachmentSource: Configure source (optionally set folder)
    NewAttachmentSource->>MicrosoftOutlookApp: Subscribe to new message events
    MicrosoftOutlookApp-->>NewAttachmentSource: Notifies on new message
    NewAttachmentSource->>MicrosoftOutlookApp: Fetch message details
    NewAttachmentSource->>MicrosoftOutlookApp: List attachments for message
    loop For each attachment
        NewAttachmentSource->>Workflow: Emit event with attachment and message metadata
    end
Loading
sequenceDiagram
    participant User
    participant DownloadAttachmentAction
    participant MicrosoftOutlookApp
    participant FileSystem

    User->>DownloadAttachmentAction: Provide messageId, attachmentId, filename
    DownloadAttachmentAction->>MicrosoftOutlookApp: getAttachment(messageId, attachmentId)
    MicrosoftOutlookApp-->>DownloadAttachmentAction: Attachment data (array buffer)
    DownloadAttachmentAction->>FileSystem: Write buffer to /tmp/filename
    DownloadAttachmentAction-->>User: Return filename, contentType, filePath
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement "New Attachment Received" source emitting events for each attachment with required metadata (#16270)
Implement "Download Attachment" action retrieving raw attachment content, saving to tmp, returning details (#16270)
Use Microsoft Graph API endpoints for listing and retrieving attachments (#16270)
Support folder filtering and correct event emission logic in new attachment source (#16270)

Suggested labels

ai-assisted

Suggested reviewers

  • luancazarine

Poem

A hop, a leap, a brand new feat,
Attachments now land at your furry feet!
With downloads swift and triggers keen,
Outlook’s secrets are now seen.
Into /tmp/ we burrow deep,
Bringing files for you to keep.
🐇✨ Another patch, another cheer—
Attachments handled, loud and clear!
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

components/microsoft_outlook/sources/new-attachment-received/new-attachment-received.mjs

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 149e90c and 0a05f67.

📒 Files selected for processing (1)
  • components/microsoft_outlook/sources/new-attachment-received/new-attachment-received.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/microsoft_outlook/sources/new-attachment-received/new-attachment-received.mjs

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@michelle0927 michelle0927 marked this pull request as ready for review April 16, 2025 21:41
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🔭 Outside diff range comments (1)
components/microsoft_outlook/sources/new-email/new-email.mjs (1)

54-76: ⚠️ Potential issue

Same self‑recursion issue in run()

As with the attachment source, the new e‑mail source’s run() overrides the base method but calls this.run() internally, leading to infinite recursion.

-await this.run({
+await this.processEvents({
   event,
   emitFn: async ({ resourceId } = {}) => {

Rename the helper or call the inherited implementation directly.
This affects all live runs of the source.

🧹 Nitpick comments (5)
components/microsoft_outlook/sources/common/common.mjs (1)

5-7: Clarify unit consistency for renewal intervals.
Currently, getRenewalInterval() returns seconds when called without an argument, and milliseconds when period is truthy (day * 2.5 * 1000). This dual‐unit behavior can be confusing and error‑prone. Consider:

  • Renaming the period parameter to something like asMilliseconds for clarity.
  • Splitting into two separate functions (e.g., getRenewalIntervalSeconds and getRenewalIntervalMilliseconds).
    Also verify that the 2.5‑day (60‑hour) renewal period aligns with the Graph API’s 4230‑minute maximum.
components/microsoft_outlook/actions/download-attachment/download-attachment.mjs (1)

49-54: Return object looks good, consider adding success message

The return object contains all necessary information. Consider adding a user-friendly summary message using $.export("$summary", "...") like other actions do.

+    $.export("$summary", `Successfully downloaded attachment '${this.filename}'`);
     return {
       fileName: this.filename,
       contentType,
       filePath: downloadedFilepath,
     };
components/microsoft_outlook/sources/common/common-new-email.mjs (1)

43-47: Gracefully handle missing folders

getFolderIdByName() returns undefined when the folder is not found, which then gets persisted to the DB and later compared in isRelevant().
If Outlook is configured in a language other than English, the display names “Sent Items” / “Drafts” will differ, leading to unexpected behaviour.

Consider:

const folder = folders.find(({ displayName }) => displayName === name);
-return folder?.id;
+if (!folder) this.$logger.debug(`Folder "${name}" not found`);
+return folder?.id ?? null;

And make the “sent”/“drafts” names configurable or use the well‑known folder names API (/me/mailFolders/sentitems).

components/microsoft_outlook/sources/new-attachment-received/new-attachment-received.mjs (2)

14-39: Speed‑up sample generation with parallel requests

getSampleEvents() fetches attachments sequentially – first messages per folder, then attachments per message – which can take several seconds for large mailboxes.

A low‑risk optimisation:

-const attachments = [];
-for (const message of messagesWithAttachments) {
-  const messageAttachments = await this.getMessageAttachments(message);
-  attachments.push(...messageAttachments);
-}
-return attachments;
+const attachments = await Promise.all(
+  messagesWithAttachments.map((m) => this.getMessageAttachments(m)),
+);
+return attachments.flat();

Wrap the Promise.all in a throttler if you fear Graph API rate limits.


64-66: Missing fallback for malformed dates

Date.parse(item.messageReceivedDateTime) returns NaN if the field is missing or non‑ISO.
Consider defaulting to Date.now() to ensure a valid timestamp for the event metadata.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 435555b and 149e90c.

📒 Files selected for processing (22)
  • components/microsoft_outlook/actions/add-label-to-email/add-label-to-email.mjs (1 hunks)
  • components/microsoft_outlook/actions/approve-workflow/approve-workflow.mjs (1 hunks)
  • components/microsoft_outlook/actions/create-contact/create-contact.mjs (1 hunks)
  • components/microsoft_outlook/actions/create-draft-email/create-draft-email.mjs (1 hunks)
  • components/microsoft_outlook/actions/download-attachment/download-attachment.mjs (1 hunks)
  • components/microsoft_outlook/actions/find-contacts/find-contacts.mjs (1 hunks)
  • components/microsoft_outlook/actions/find-email/find-email.mjs (1 hunks)
  • components/microsoft_outlook/actions/list-contacts/list-contacts.mjs (1 hunks)
  • components/microsoft_outlook/actions/list-folders/list-folders.mjs (1 hunks)
  • components/microsoft_outlook/actions/list-labels/list-labels.mjs (1 hunks)
  • components/microsoft_outlook/actions/move-email-to-folder/move-email-to-folder.mjs (1 hunks)
  • components/microsoft_outlook/actions/remove-label-from-email/remove-label-from-email.mjs (1 hunks)
  • components/microsoft_outlook/actions/reply-to-email/reply-to-email.mjs (1 hunks)
  • components/microsoft_outlook/actions/send-email/send-email.mjs (1 hunks)
  • components/microsoft_outlook/actions/update-contact/update-contact.mjs (1 hunks)
  • components/microsoft_outlook/microsoft_outlook.app.mjs (2 hunks)
  • components/microsoft_outlook/package.json (1 hunks)
  • components/microsoft_outlook/sources/common/common-new-email.mjs (1 hunks)
  • components/microsoft_outlook/sources/common/common.mjs (1 hunks)
  • components/microsoft_outlook/sources/new-attachment-received/new-attachment-received.mjs (1 hunks)
  • components/microsoft_outlook/sources/new-contact/new-contact.mjs (1 hunks)
  • components/microsoft_outlook/sources/new-email/new-email.mjs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: pnpm publish
🔇 Additional comments (24)
components/microsoft_outlook/actions/list-labels/list-labels.mjs (1)

7-7: Bump ACK: Version bump aligns with PR conventions
The version increment from "0.0.5" to "0.0.6" is consistent with the coordinated updates across Outlook actions, and there are no functional changes in this module.

components/microsoft_outlook/actions/create-contact/create-contact.mjs (1)

6-6: Version update looks good.

The version increment from "0.0.12" to "0.0.13" aligns with similar updates across other Microsoft Outlook actions in this PR.

components/microsoft_outlook/microsoft_outlook.app.mjs (3)

173-195: Well-structured property definition for attachments.

The new attachmentId property definition is well implemented with proper label, description, and async options method that includes pagination support. This follows the same pattern as other property definitions in the file.


429-436: Clean implementation of attachment download method.

The getAttachment method properly uses the Microsoft Graph API endpoint with the /$value suffix to get the raw content of an attachment.


437-444: Good implementation of attachment listing method.

The listAttachments method uses the appropriate Microsoft Graph API endpoint to retrieve attachments for a specified message, and correctly handles additional parameters through the args parameter.

components/microsoft_outlook/actions/find-contacts/find-contacts.mjs (1)

6-6: Version update looks good.

The version increment from "0.0.12" to "0.0.13" aligns with similar updates across other Microsoft Outlook actions in this PR.

components/microsoft_outlook/actions/update-contact/update-contact.mjs (1)

6-6: Version update looks good.

The version increment from "0.0.12" to "0.0.13" aligns with similar updates across other Microsoft Outlook actions in this PR.

components/microsoft_outlook/actions/reply-to-email/reply-to-email.mjs (1)

7-7: Approved: Version bump only
The version has been correctly incremented from “0.0.2” to “0.0.3” with no unintended side‑effects.

components/microsoft_outlook/actions/move-email-to-folder/move-email-to-folder.mjs (1)

7-7: Approved: Version bump only
The version has been correctly incremented from “0.0.3” to “0.0.4” with no unintended side‑effects.

components/microsoft_outlook/actions/approve-workflow/approve-workflow.mjs (1)

7-7: Approved: Version bump only
The version has been correctly incremented from “0.0.3” to “0.0.4” with no unintended side‑effects.

components/microsoft_outlook/actions/list-contacts/list-contacts.mjs (1)

6-6: Approved: Version bump only
The version has been correctly incremented from “0.0.12” to “0.0.13” with no unintended side‑effects.

components/microsoft_outlook/actions/remove-label-from-email/remove-label-from-email.mjs (1)

7-7: Approved: Version bump only
The version has been correctly incremented from “0.0.5” to “0.0.6” with no unintended side‑effects.

components/microsoft_outlook/sources/common/common.mjs (1)

1-1: Import path update looks correct.
The relative path now correctly resolves to components/microsoft_outlook/microsoft_outlook.app.mjs.

components/microsoft_outlook/package.json (1)

3-3: Package version bumped appropriately.
The version has been updated to 1.5.0 to encapsulate the new attachment actions and related enhancements. Ensure this matches release notes and any downstream dependencies.

components/microsoft_outlook/actions/add-label-to-email/add-label-to-email.mjs (1)

8-8: Action version bumped to 0.0.6.
No logic changes were made—this aligns with the coordinated version updates across Outlook actions.

components/microsoft_outlook/actions/list-folders/list-folders.mjs (1)

7-7: Action version bump to 0.0.4.
No functional changes here; versions remain consistent across the Microsoft Outlook actions.

components/microsoft_outlook/actions/send-email/send-email.mjs (1)

6-6: Action version incremented to 0.0.14.
No code or logic modifications—this keeps the send‑email action in sync with the broader Outlook integration versioning.

components/microsoft_outlook/actions/create-draft-email/create-draft-email.mjs (1)

6-6: Version increment looks good

The version has been incremented from "0.0.12" to "0.0.13" as part of the broader update to the Microsoft Outlook integration package.

components/microsoft_outlook/actions/find-email/find-email.mjs (1)

7-7: Version increment looks good

The version has been incremented from "0.0.3" to "0.0.4" as part of the broader update to the Microsoft Outlook integration package.

components/microsoft_outlook/sources/new-contact/new-contact.mjs (2)

1-1: Import path update looks good

The import path for the common module has been updated from "../common.mjs" to "../common/common.mjs", which aligns with the restructuring of common modules in the Microsoft Outlook sources.


8-8: Version increment looks good

The version has been incremented from "0.0.13" to "0.0.14" as part of the broader update to the Microsoft Outlook integration package.

components/microsoft_outlook/actions/download-attachment/download-attachment.mjs (3)

1-4: Imports look good

The imports for Microsoft Outlook app, file system (fs), and MIME types are appropriate for the attachment download functionality.


5-34: Action definition and props look good

The action is well-defined with appropriate key, name, description, and version. The props are properly structured with clear descriptions, and the attachment ID prop correctly depends on the message ID.


35-42: API call implementation looks good

The implementation correctly calls the Microsoft Outlook API to retrieve the attachment with the appropriate parameters and response type.

lcaresia
lcaresia previously approved these changes Apr 17, 2025
@michelle0927
Copy link
Collaborator Author

/approve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Microsoft Outlook: New Attachment Received & Download Attachment
2 participants