-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Instantly - upgrade to API V2 #16298
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 ↗︎ 3 Skipped Deployments
|
|
""" WalkthroughThis 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
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
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
Assessment against linked issues
Suggested labels
Suggested reviewers
Poem
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
components/instantly/sources/new-lead-created/new-lead-created.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
🪧 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: 1
🔭 Outside diff range comments (1)
components/instantly/actions/add-tags-campaign/add-tags-campaign.mjs (1)
31-32:⚠️ Potential issuePotential inconsistency in campaign ID parameter
There appears to be a potential issue. Line 31 uses
campaignId(singular) while line 35 usescampaignIds(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 neededOr 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 returnNaN, which may break the logic.Consider short-circuiting or defaulting to
0when 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
lastTswill be re-emitted. If you want to ensure each item is only emitted once, change the condition tots > 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 URLThe 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 loopWhile 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis 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 inprocessEventis clear and well-structured.No major issues found, and the approach to store and update
lastTsfor incremental polling is correct.components/instantly/instantly.app.mjs (3)
15-60: Props forcampaignIdandtagIdslook good.The usage of pagination and dynamic options is consistent with the new API.
63-88:leadIdsprop 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
Bearertoken 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.1is appropriate to reflect these enhancements and API changes.components/instantly/common/constants.mjs (1)
3-36: LGTM: Status options structure updated for API v2The 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 bumpThe description now correctly references the v2 API documentation, and the version has been incremented appropriately.
18-19: Improved property descriptionThe description for the campaignIds property has been clarified to better explain its purpose.
38-39: Fixed summary message for consistencyThe 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 componentThis new polling source for email events is well-structured and properly implements the common base patterns. The component:
- Extends the common base source
- Properly defines metadata (key, name, description, version)
- Implements required methods for resource fetching and processing
- Uses appropriate pagination and sorting (descending by timestamp_created)
- 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 leadsThis new source component is properly structured and follows the common patterns established for the Instantly integration. It correctly:
- Extends the common base source
- Uses the listLeads API method from the upgraded app module
- Defines appropriate timestamp field for deduplication
- 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 eventsThis 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 appropriatelyThe 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 compatibilityThe 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 metadataThe label and description additions provide better clarity for users of this action.
42-44: Request payload updated to match API v2 parameter namesThe 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 messageThe 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 supportThe changes appropriately update the name to plural form and reference the new API v2 documentation.
12-12: Property renamed to match API v2 conventionsThe property renaming from "leads" to "leadIds" maintains consistency with other components in the integration.
30-35: Useful new feature for job completion monitoringAdding 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 namesThe payload structure is correctly updated to use the new field names required by API v2.
59-59: Improved summary messageThe summary now correctly indicates the number of leads being processed, which is more informative for the user.
GTFalcao
left a comment
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.
LGTM!
components/instantly/sources/new-lead-created/new-lead-created.mjs
Outdated
Show resolved
Hide resolved
|
/approve |
|
/approve |
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:
Summary by CodeRabbit