Skip to content

fix: intercom rETL flow when user_id only provided as identifier - #4739

Merged
ItsSudip merged 2 commits into
developfrom
fix/intercom-rETL-flow
Nov 5, 2025
Merged

ItsSudip merged 2 commits into
developfrom
fix/intercom-rETL-flow

Conversation

@ItsSudip

Copy link
Copy Markdown
Member

What are the changes introduced in this PR?

This PR fixes the Intercom destination integration for rETL (reverse ETL) flow by properly handling user identification when email is not present in the traits. The changes ensure that user_id is correctly mapped to external_id for lookups when operating in rETL mode without an email identifier.

What is the related Linear task?

Resolves INT-4261

Please explain the objectives of your changes below

Any changes to existing capabilities/behaviour, mention the reason & what are the changes?

Changes:

  • Modified the contact search logic in Intercom integration to handle rETL flow when email is not present
  • Updated the processor workflow to conditionally set external_id based on email presence
  • Enhanced the searchContact function to detect rETL flow and use external_id for user lookup

Reason:
In rETL scenarios, when users are identified by user_id without an email, the Intercom API requires external_id for contact lookups, and if the lookups fail, it tries to create a new user. Previously, the integration wasn't mapping user_id to external_id correctly, causing lookup failures and also creating new users to fail, as the' external_id' was not present.

Any new dependencies introduced with this change?

No new dependencies introduced.

Any new generic utility introduced or modified. Please explain the changes.

No new utilities introduced. Modified existing utility function searchContact in src/cdk/v2/destinations/intercom/utils.js to:

  • Check for message.context.mappedToDestination flag (indicating rETL flow)
  • Use external_id from traits as the lookup field when this flag is present
  • Maintain backward compatibility with existing flows

Any technical or performance related pointers to consider with the change?

  • The changes are conditional and only affect rETL flows (when mappedToDestination flag is true)
  • No performance impact as the logic adds minimal conditional checks
  • The contact search API behavior remains unchanged for non-rETL flows

@coderabbitai review

Developer checklist

  • My code follows the style guidelines of this project
  • No breaking changes are being introduced.
  • All related docs linked with the PR?
  • All changes manually tested?
  • Any documentation changes needed with this change?
  • Is the PR limited to 10 file changes?
  • Is the PR limited to one linear task?
  • Are relevant unit and component test-cases added in new readability format?

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?
  • Verified that there are no credentials or confidential data exposed with the changes.

Technical Details

Files Modified:

  1. src/cdk/v2/destinations/intercom/procWorkflow.yaml - Added conditional logic to set external_id to user_id when email is not present
  2. src/cdk/v2/destinations/intercom/utils.js - Enhanced searchContact function to handle rETL flow by using external_id for lookups
  3. test/integrations/destinations/intercom/network.ts - Added 2 mock network responses for external_id based searches
  4. test/integrations/destinations/intercom/processor/identifyTestData.ts - Added 2 comprehensive test cases covering:
    • New user creation in rETL flow (user not found scenario)
    • Existing user update in rETL flow (user found scenario)
  5. test/integrations/destinations/intercom/processor/trackTestData.ts - Updated test to include external_id in payload

Key Code Changes:

Workflow Update (procWorkflow.yaml):

// if email is present, we are not mapping user_id to external_id
payload.external_id = !payload.email ? payload.user_id : null;

Utils Update (utils.js):

// we are mapping user_id to external_id in the message for rEtl flow when email is not present in traits
if (message.context?.mappedToDestination && message.traits?.external_id &&  !message.traits?.email) {
  lookupField = 'external_id';
  lookupFieldValue = message.traits.external_id;
}

Test Coverage:

  • Total Lines Changed: 287 lines (283 additions, 4 deletions)
  • New Test Cases: 2 integration tests for rETL scenarios
  • Test Coverage: Both create and update operations for users identified by external_id

@ItsSudip
ItsSudip requested a review from a team as a code owner October 28, 2025 12:34
@coderabbitai

coderabbitai Bot commented Oct 28, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Improved Intercom destination to use external ID as a fallback for user identification when email data is unavailable, enhancing contact matching accuracy in these scenarios.

Walkthrough

Modified Intercom destination's contact lookup logic by adding explicit external_id mapping in ETL payload based on email presence, and enhancing the searchContact function to conditionally use external_id as a lookup field when email is absent.

Changes

Cohort / File(s) Summary
External ID lookup fallback mechanism
src/cdk/v2/destinations/intercom/procWorkflow.yaml, src/cdk/v2/destinations/intercom/utils.js
procWorkflow.yaml: Added conditional mapping that sets payload.external_id to payload.user_id when email is absent, otherwise null. utils.js: Changed lookupField from constant to mutable variable; added conditional to use external_id as lookup field when external_id is present and email is absent.

Sequence Diagram(s)

sequenceDiagram
    participant ETL
    participant SearchContact
    participant Intercom

    alt Email Present
        ETL->>SearchContact: message with email + external_id
        SearchContact->>SearchContact: lookupField = 'email'
        SearchContact->>Intercom: search by email
    else Email Absent
        ETL->>SearchContact: message with external_id (mapped to user_id)
        SearchContact->>SearchContact: lookupField = 'external_id'
        SearchContact->>Intercom: search by external_id
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Areas requiring attention:

  • Verify that external_id lookup is supported by Intercom's API and behaves consistently with email-based lookups
  • Confirm the priority/precedence: ensure email lookups are attempted before external_id fallback as intended
  • Validate that the null assignment for external_id when email is present doesn't cause unintended side effects in downstream systems
  • Test edge cases where both email and external_id are absent

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "fix: intercom rETL flow when user_id only provided as identifier" directly aligns with the primary objective of the changeset. The title is specific and clearly conveys that this is a fix addressing the rETL flow behavior when user identification relies solely on user_id without an email. The changes to procWorkflow.yaml and utils.js both support this exact fix by mapping user_id to external_id for lookups in rETL scenarios. The title uses conventional commit styling and is concise without unnecessary noise.
Description Check ✅ Passed The PR description comprehensively follows the repository template with all required sections completed. It includes a clear explanation of the changes, the related Linear task (INT-4261), detailed objectives with reasoning for the modifications, information about dependencies and utilities, and technical considerations. The description provides additional context with technical details, file modifications, code snippets, and test coverage information that demonstrate thorough preparation. While a few non-critical developer checklist items remain unchecked (documentation links and documentation changes), the substantive content sections are fully populated and meet the template requirements.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/intercom-rETL-flow

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/cdk/v2/destinations/intercom/procWorkflow.yaml (1)

50-51: Logic looks good for rETL external_id mapping.

The conditional assignment correctly maps user_id to external_id when email is absent, enabling Intercom contact lookups via external_id in rETL flows. The inline comment is helpful.

Minor suggestion: The comment describes the positive case ("if email is present...") while the code checks the negative case (!payload.email). Consider rephrasing for clarity:

// map user_id to external_id when email is absent, otherwise leave it null

Also, verify that downstream validation properly handles the case where both email and user_id are absent (line 86 includes this assertion, which is good).

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b9f896f and 875c893.

⛔ Files ignored due to path filters (3)
  • test/integrations/destinations/intercom/network.ts is excluded by !**/test/**
  • test/integrations/destinations/intercom/processor/identifyTestData.ts is excluded by !**/test/**
  • test/integrations/destinations/intercom/processor/trackTestData.ts is excluded by !**/test/**
📒 Files selected for processing (2)
  • src/cdk/v2/destinations/intercom/procWorkflow.yaml (1 hunks)
  • src/cdk/v2/destinations/intercom/utils.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js

⚙️ CodeRabbit configuration file

Focus on ESLint errors (max 3) and warnings (max 5).

Files:

  • src/cdk/v2/destinations/intercom/utils.js
🧠 Learnings (1)
📓 Common learnings
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4589
File: scripts/common.ts:74-78
Timestamp: 2025-08-28T15:39:08.293Z
Learning: User ItsSudip prefers simpler solutions over complex edge case handling, especially when the simpler approach is sufficient for the actual use case.
🧬 Code graph analysis (1)
src/cdk/v2/destinations/intercom/utils.js (1)
src/v0/util/index.js (3)
  • message (1157-1157)
  • message (1191-1191)
  • getFieldValueFromMessage (683-689)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Code Coverage
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
src/cdk/v2/destinations/intercom/utils.js (2)

278-278: Good change to enable dynamic lookup field adjustment.

Changing lookupField from const to let is necessary to support the rETL flow logic below where the field is reassigned to external_id when appropriate.


283-291: Excellent alignment with workflow logic for rETL lookup.

This conditional correctly detects the rETL scenario and switches the contact lookup to use external_id when email is absent. The three-part condition properly handles the edge cases:

  1. message.context?.mappedToDestination - identifies rETL flow
  2. message.traits?.external_id - confirms external_id was set (falsy if null from workflow when email present)
  3. !message.traits?.email - mirrors the workflow's email absence check

The comment clearly explains the business logic, and the implementation maintains consistency with the procWorkflow.yaml mapping on lines 50-51.

@codecov

codecov Bot commented Oct 28, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.92%. Comparing base (690dc83) to head (875c893).
⚠️ Report is 28 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4739      +/-   ##
===========================================
- Coverage    91.92%   91.92%   -0.01%     
===========================================
  Files          651      651              
  Lines        34609    34624      +15     
  Branches      8121     8130       +9     
===========================================
+ Hits         31816    31827      +11     
- Misses        2563     2567       +4     
  Partials       230      230              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

Copy link
Copy Markdown

@ItsSudip
ItsSudip merged commit c44292f into develop Nov 5, 2025
@ItsSudip
ItsSudip deleted the fix/intercom-rETL-flow branch November 5, 2025 06:56
ItsSudip added a commit that referenced this pull request Nov 12, 2025
* feat: introduce e2e tests UT (#4686)

* chore: update slack notification list (#4706)

* chore: skip pushing docker images for dependabot (#4714)

* chore: skip building images for debendabot

* chore: review comments

* chore: skip docker login for dependabot

* chore: skip docker login for dependabot

* chore: misc

* chore: misc

* chore: misc

* chore: misc

* chore: review comments

* chore: review comments

* chore: review comments

* chore: review comments

* chore: review comments

* chore: add dub to new test structure (#4717)

* chore: add readme for campaign_manager (#4710)

* chore: update GAOC readme with quota link (#4723)

* chore: apply security best practices (#4708)

[StepSecurity] Apply security best practices

Signed-off-by: StepSecurity Bot <[email protected]>

* feat: add validation of diff in staging deployment workflow (#4722)

* chore(deps-dev): bump commander from 10.0.1 to 14.0.2

Bumps [commander](https://github.com/tj/commander.js) from 10.0.1 to 14.0.2.
- [Release notes](https://github.com/tj/commander.js/releases)
- [Changelog](https://github.com/tj/commander.js/blob/master/CHANGELOG.md)
- [Commits](tj/commander.js@v10.0.1...v14.0.2)

---
updated-dependencies:
- dependency-name: commander
  dependency-version: 14.0.2
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps-dev): bump supertest from 6.3.4 to 7.1.4 (#4525)

---
updated-dependencies:
- dependency-name: supertest
  dependency-version: 7.1.4
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: add env vars for controlling the connection pooling on python transformations (#4738)

* chore: update facebook conversion api version from 22.0 to 24.0 (#4734)

* chore: update facebook conversion api version from 22.0 to 23.0

* chore: update facebook conversion api version from 23.0 to 45.0

* chore: fix typo

* chore: update facebook custom audience api version from 22.0 to 23.0 (#4735)

* chore: update facebook custom audience api version from 22.0 to 23.0

* chore: update facebook custom audience api version from 23.0 to 24.0

* chore: update facebook custom audience api version from 24.0 to 23.0 as it has some breaking changes

* chore: update facebook pixel api version from 22.0 to 24.0 (#4737)

* chore: update facebook pixel api version from 22.0 to 24.0

* chore: update facebook app events api version from 22.0 to 24.0 (#4736)

* chore: move rs-ai memory bank to transformer

* chore: add nodemon for hot reloading (#4748)

* chore: refactor code to update variable name in more readable format (#4747)

* feat: source transformation endpoint for facebook_lead_ads_native source (#4746)

* chore: disable clustering in nodemon configuration (#4749)

* chore: run format check on all files (#4750)

* fix: intercom rETL flow when user_id only provided as identifier (#4739)

* chore: apply security best practices from step security (#4727)

[StepSecurity] Apply security best practices

Signed-off-by: StepSecurity Bot <[email protected]>
Co-authored-by: stepsecurity-app[bot] <188008098+stepsecurity-app[bot]@users.noreply.github.com>

* chore(deps): bump actions/setup-node from 5.0.0 to 6.0.0

Bumps [actions/setup-node](https://github.com/actions/setup-node) from 5.0.0 to 6.0.0.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](actions/setup-node@v5.0.0...v6.0.0)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: 6.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore: remove logs logging request/response body (#4754)

* chore: disable pyroscope for primary process in cluster mode (#4756)

* feat(reddit): onboard v3 api (#4699)

* feat(reddit): onboard v3 api

* chore: implement router batching flow

* feat: enable batching scenario

* chore: add test cases

* chore: address coderabbit comments

* chore: add mock for timestamp

* chore: add documentation for reddit

* fix: use crypto for hashing

* chore: address coderabbit comment

* chore: address comments

* chore: add validation and remove double type assertion

* chore: remove undefined files from final palyload

* chore: fix test case

* feat(reddit): onboard v3 api

* chore: implement router batching flow

* feat: enable batching scenario

* chore: add test cases

* chore: address coderabbit comments

* chore: add mock for timestamp

* chore: add documentation for reddit

* fix: use crypto for hashing

* chore: address coderabbit comment

* chore: address comments

* chore: add validation and remove double type assertion

* chore: remove undefined files from final palyload

* chore: fix test case

* chore: apply format

* chore: apply format

* chore(deps): bump actions/checkout from 4.3.0 to 5.0.0

Bumps [actions/checkout](https://github.com/actions/checkout) from 4.3.0 to 5.0.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v4.3.0...08c6903)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 5.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* feat: add advertiser_tracking_enabled mapping for pinterest without featureFlag (#4740)

* chore(deps): bump actions/stale from 10.0.0 to 10.1.0

Bumps [actions/stale](https://github.com/actions/stale) from 10.0.0 to 10.1.0.
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](actions/stale@v10.0.0...v10.1.0)

---
updated-dependencies:
- dependency-name: actions/stale
  dependency-version: 10.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore: handle breaking changes for commander

* chore: fix breaking commander changes

* chore(release): 1.112.0

---------

Signed-off-by: StepSecurity Bot <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Rohith BCS <[email protected]>
Co-authored-by: Vinay Teki <[email protected]>
Co-authored-by: Mahesh Kutty <[email protected]>
Co-authored-by: Sudip Paul <[email protected]>
Co-authored-by: stepsecurity-app[bot] <188008098+stepsecurity-app[bot]@users.noreply.github.com>
Co-authored-by: Krishna Chaitanya <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jayachand Mopidevi <[email protected]>
Co-authored-by: GitHub Actions <[email protected]>
Co-authored-by: shekhar-rudder <[email protected]>
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.

5 participants