Skip to content

Conversation

@michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented Apr 15, 2025

Resolves #16264

Updated existing actions. Confirmed with Instantly support that they no longer support creating webhooks programmatically, so I removed "New Event Instant" and created three new polling sources:

  • New Email Received
  • New Lead Created
  • New Background Job Completed

Summary by CodeRabbit

  • New Features
    • Introduced event sources to emit events for new leads created, new emails received, and completed background jobs.
  • Improvements
    • Enhanced campaign, tag, and lead selection with improved labels and cursor-based pagination for easier navigation.
    • Updated authentication to use Bearer tokens and switched to new API endpoints for improved security and compatibility.
    • Added support for polling background job completion when adding leads to campaigns.
    • Updated lead status options with clearer labels and numeric codes.
  • Bug Fixes
    • Corrected and clarified summary messages and property descriptions across actions.
  • Removals
    • Removed obsolete instant event source and its test data.

@vercel
Copy link

vercel bot commented Apr 15, 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 17, 2025 3:05am
pipedream-docs ⬜️ Ignored (Inspect) Apr 17, 2025 3:05am
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Apr 17, 2025 3:05am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 15, 2025

"""

Walkthrough

This update migrates the Instantly integration from API v1 to API v2, refactoring all existing actions and triggers to align with the new API endpoints, authentication, and data structures. It introduces new source components for background job completion, email reception, and lead creation events, while removing the old instant event webhook source and its test data. The package's authentication is updated to use Bearer tokens in headers instead of API keys in query parameters. Several methods and prop definitions are revised for cursor-based pagination, new endpoint paths, and updated payloads. Constants are realigned to match v2 status codes and event types.

Changes

Files/Paths Change Summary
components/instantly/instantly.app.mjs Refactored for API v2: authentication via Bearer token in headers, all endpoint paths updated, cursor-based pagination implemented, propDefinitions revised, new methods for background jobs and pagination, webhook methods removed.
components/instantly/actions/add-lead-campaign/add-lead-campaign.mjs Updated for v2: metadata revised, payload keys changed, input property renamed, new boolean for polling completion, API request and polling logic aligned with v2 endpoints.
components/instantly/actions/add-tags-campaign/add-tags-campaign.mjs Updated description and version, added property description, summary export simplified, documentation URL updated for v2.
components/instantly/actions/update-lead-status/update-lead-status.mjs Updated for v2: description and version updated, propDefinition revised to use leadIds, payload keys changed, summary export simplified.
components/instantly/common/constants.mjs Removed old event type/status constants, added new status options array matching v2 numeric codes and labels.
components/instantly/sources/common/base.mjs New: Base source component for polling-based event triggers, with timestamp-based deduplication, pagination, and abstract methods for resource-specific logic.
components/instantly/sources/new-background-job-completed/new-background-job-completed.mjs New: Source component emitting events when background jobs complete (success or failure), extends common base, uses background jobs endpoint.
components/instantly/sources/new-email-received/new-email-received.mjs New: Source component emitting events when new emails are received, extends common base, uses emails endpoint.
components/instantly/sources/new-lead-created/new-lead-created.mjs New: Source component emitting events when new leads are created, extends common base, uses leads endpoint.
components/instantly/sources/new-event-instant/new-event-instant.mjs,
.../test-event.mjs
Removed: Old instant event webhook source and associated test event data, as webhooks are no longer supported or have changed in v2.
components/instantly/package.json Version bumped from 0.1.0 to 0.1.1.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Action
    participant InstantlyApp
    participant InstantlyAPI

    User->>Action: Trigger action (e.g., Add Leads to Campaign)
    Action->>InstantlyApp: Prepare API v2 request (Bearer token, new payload)
    InstantlyApp->>InstantlyAPI: Send request to v2 endpoint
    InstantlyAPI-->>InstantlyApp: Respond with job or result
    alt Wait for completion (if enabled)
        Action->>InstantlyApp: Poll getBackgroundJob
        InstantlyApp->>InstantlyAPI: GET /background-jobs/{jobId}
        InstantlyAPI-->>InstantlyApp: Return job status
        Action->>User: Return summary when complete
    else No polling
        Action->>User: Return immediate summary
    end
Loading
sequenceDiagram
    participant Source
    participant InstantlyApp
    participant InstantlyAPI
    participant User

    loop On timer
        Source->>InstantlyApp: Fetch items (e.g., leads, emails, jobs)
        InstantlyApp->>InstantlyAPI: Call v2 list endpoint with cursor
        InstantlyAPI-->>InstantlyApp: Return paginated results
        Source->>User: Emit new events with metadata
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Update all Instantly actions and triggers to use API v2 endpoints and data structures (#16264)
Switch authentication to API v2 method (Bearer token in header) (#16264)
Remove/replace old webhook-based triggers incompatible with API v2 (#16264)
Add support for new endpoints and event types available in API v2 (#16264)

Suggested labels

ai-assisted

Suggested reviewers

  • luancazarine

Poem

A hop, a skip, a leap to v2—
Instantly’s code is shiny and new!
Bearer tokens now unlock the gate,
Cursor pages, triggers that poll and wait.
Old webhooks gone, new sources in bloom,
This rabbit’s proud—just look at this room!
🐇✨
"""

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/instantly/sources/new-lead-created/new-lead-created.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)

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 15d4422 and 6a252ad.

📒 Files selected for processing (1)
  • components/instantly/sources/new-lead-created/new-lead-created.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/instantly/sources/new-lead-created/new-lead-created.mjs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Publish TypeScript components

🪧 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.

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: 1

🔭 Outside diff range comments (1)
components/instantly/actions/add-tags-campaign/add-tags-campaign.mjs (1)

31-32: ⚠️ Potential issue

Potential inconsistency in campaign ID parameter

There appears to be a potential issue. Line 31 uses campaignId (singular) while line 35 uses campaignIds (plural) as parsed from props. This might lead to unexpected behavior.

-        campaign_id: this.campaignId,
+        campaign_id: parseObject(this.campaignIds)[0], // If single ID is needed

Or remove this line if it's not needed in the API v2 payload.

🧹 Nitpick comments (4)
components/instantly/sources/common/base.mjs (2)

25-31: Handle potential invalid timestamps.

The code uses Date.parse(item[this.getTsField()]) but never validates whether the timestamp string is valid. If the timestamp is undefined or invalid, Date.parse() can return NaN, which may break the logic.

Consider short-circuiting or defaulting to 0 when the timestamp is invalid to avoid unexpected results:

- ts: Date.parse(item[this.getTsField()]),
+ const rawTs = Date.parse(item[this.getTsField()]);
+ const parsedTs = Number.isNaN(rawTs) ? 0 : rawTs;
+ // then use `parsedTs`

48-51: Avoid re-emitting items with the same timestamp unless intentional.

Currently, items with a timestamp exactly equal to lastTs will be re-emitted. If you want to ensure each item is only emitted once, change the condition to ts > lastTs.

- if (ts >= lastTs) {
+ if (ts > lastTs) {
    results.push(item);
    maxTs = Math.max(ts, maxTs);
  }
components/instantly/sources/new-lead-created/new-lead-created.mjs (1)

7-7: Missing closing parenthesis in documentation URL

The documentation link is missing a closing parenthesis, which will break the markdown rendering.

-  description: "Emit new event when a new lead is created. [See the documentation](https://developer.instantly.ai/api/v2/lead/listleads",
+  description: "Emit new event when a new lead is created. [See the documentation](https://developer.instantly.ai/api/v2/lead/listleads)",
components/instantly/actions/add-lead-campaign/add-lead-campaign.mjs (1)

47-57: Consider adding a timeout and error handling to the polling loop

While the polling implementation works, it could be improved with a timeout mechanism to prevent infinite polling and better error handling for network issues.

 if (this.waitForCompletion) {
   const jobId = response.id;
   const timer = (ms) => new Promise((res) => setTimeout(res, ms));
+  const startTime = Date.now();
+  const MAX_POLLING_TIME = 300000; // 5 minutes in milliseconds
   while (response.status === "pending" || response.status === "in-progress") {
+    if (Date.now() - startTime > MAX_POLLING_TIME) {
+      $.export("$summary", `Operation timed out after waiting for 5 minutes. Job ID: ${jobId} is still in progress.`);
+      break;
+    }
-    response = await this.instantly.getBackgroundJob({
-      $,
-      jobId,
-    });
+    try {
+      response = await this.instantly.getBackgroundJob({
+        $,
+        jobId,
+      });
+    } catch (error) {
+      console.log(`Error polling job status: ${error.message}. Retrying...`);
+    }
     await timer(3000);
   }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cd04a13 and 5e5d4db.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • components/instantly/actions/add-lead-campaign/add-lead-campaign.mjs (2 hunks)
  • components/instantly/actions/add-tags-campaign/add-tags-campaign.mjs (3 hunks)
  • components/instantly/actions/update-lead-status/update-lead-status.mjs (3 hunks)
  • components/instantly/common/constants.mjs (1 hunks)
  • components/instantly/instantly.app.mjs (1 hunks)
  • components/instantly/package.json (1 hunks)
  • components/instantly/sources/common/base.mjs (1 hunks)
  • components/instantly/sources/new-background-job-completed/new-background-job-completed.mjs (1 hunks)
  • components/instantly/sources/new-email-received/new-email-received.mjs (1 hunks)
  • components/instantly/sources/new-event-instant/new-event-instant.mjs (0 hunks)
  • components/instantly/sources/new-event-instant/test-event.mjs (0 hunks)
  • components/instantly/sources/new-lead-created/new-lead-created.mjs (1 hunks)
💤 Files with no reviewable changes (2)
  • components/instantly/sources/new-event-instant/test-event.mjs
  • components/instantly/sources/new-event-instant/new-event-instant.mjs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: pnpm publish
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (22)
components/instantly/sources/common/base.mjs (1)

32-72: Overall logic in processEvent is clear and well-structured.

No major issues found, and the approach to store and update lastTs for incremental polling is correct.

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

15-60: Props for campaignId and tagIds look good.

The usage of pagination and dynamic options is consistent with the new API.


63-88: leadIds prop definition is well-implemented.

Great job providing dynamic labels and properly referencing the lead IDs in the new v2 API.


90-104: Bearer authentication approach is correct.

Shifting from query parameters to a Bearer token in headers aligns with best practices and the v2 Instantly API.

components/instantly/package.json (1)

3-3: Version bump acknowledged.

Updating to 0.1.1 is appropriate to reflect these enhancements and API changes.

components/instantly/common/constants.mjs (1)

3-36: LGTM: Status options structure updated for API v2

The constants have been properly updated to align with Instantly's API v2 format. The new status options are defined as objects with label and value properties, which is a more robust approach compared to the previous string array.

This new format supports the updated payload structure and status codes for lead management in the API v2.

components/instantly/actions/add-tags-campaign/add-tags-campaign.mjs (3)

7-8: Updated API documentation link and version bump

The description now correctly references the v2 API documentation, and the version has been incremented appropriately.


18-19: Improved property description

The description for the campaignIds property has been clarified to better explain its purpose.


38-39: Fixed summary message for consistency

The export summary has been updated to use a static message instead of relying on the API response, which provides more consistent output for the user.

components/instantly/sources/new-email-received/new-email-received.mjs (1)

1-32: LGTM: Well-structured new polling source component

This new polling source for email events is well-structured and properly implements the common base patterns. The component:

  1. Extends the common base source
  2. Properly defines metadata (key, name, description, version)
  3. Implements required methods for resource fetching and processing
  4. Uses appropriate pagination and sorting (descending by timestamp_created)
  5. Provides clear summaries for emitted events

This is a good replacement for the removed webhook functionality and aligns with the API v2 patterns.

components/instantly/sources/new-lead-created/new-lead-created.mjs (1)

1-29: Well-implemented polling source for new leads

This new source component is properly structured and follows the common patterns established for the Instantly integration. It correctly:

  1. Extends the common base source
  2. Uses the listLeads API method from the upgraded app module
  3. Defines appropriate timestamp field for deduplication
  4. Provides clear event summaries

This is a good implementation that aligns with the upgrade to API v2.

components/instantly/sources/new-background-job-completed/new-background-job-completed.mjs (1)

1-32: Well-implemented polling source for background job completion events

This new component correctly implements the polling pattern needed to replace the removed webhook functionality. The implementation is clean and appropriate, with proper filtering for completed jobs (both successful and failed) and sorting by update timestamp.

components/instantly/actions/update-lead-status/update-lead-status.mjs (5)

7-8: Documentation and version updated appropriately

The description now correctly references the new API v2 endpoint and documentation link. Version increment is appropriate for the API version update.


21-24: Property definition updated for API v2 compatibility

The change from "leads" to "leadIds" with a valueKey of "email" aligns with the updated API structure. This approach allows for better reuse of property definitions across the integration.


27-29: Improved property metadata

The label and description additions provide better clarity for users of this action.


42-44: Request payload updated to match API v2 parameter names

The payload structure is correctly updated to use "lead_email" and "interest_value" instead of the previous field names, aligning with the new API requirements.


47-47: Simplified summary message

The export summary is now more concise while still providing the essential information.

components/instantly/actions/add-lead-campaign/add-lead-campaign.mjs (5)

6-8: Action name and description updated to reflect multiple leads support

The changes appropriately update the name to plural form and reference the new API v2 documentation.


12-12: Property renamed to match API v2 conventions

The property renaming from "leads" to "leadIds" maintains consistency with other components in the integration.


30-35: Useful new feature for job completion monitoring

Adding the ability to wait for background job completion is a valuable enhancement that will make workflows more reliable when actions need to be performed after leads are successfully added.


41-44: Request payload updated to match API v2 parameter names

The payload structure is correctly updated to use the new field names required by API v2.


59-59: Improved summary message

The summary now correctly indicates the number of leads being processed, which is more informative for the user.

GTFalcao
GTFalcao previously approved these changes Apr 16, 2025
Copy link
Collaborator

@GTFalcao GTFalcao left a comment

Choose a reason for hiding this comment

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

LGTM!

@michelle0927
Copy link
Collaborator Author

/approve

@michelle0927
Copy link
Collaborator Author

/approve

@michelle0927 michelle0927 merged commit 74dd14f into master Apr 18, 2025
11 checks passed
@michelle0927 michelle0927 deleted the issue-16264 branch April 18, 2025 20:43
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] Upgrade Instantly to API V2

4 participants