Skip to content

feat: Add support for call diversion handling in media calls#40560

Draft
aleksandernsilva wants to merge 3 commits into
developfrom
feat/sip-call-diversion
Draft

feat: Add support for call diversion handling in media calls#40560
aleksandernsilva wants to merge 3 commits into
developfrom
feat/sip-call-diversion

Conversation

@aleksandernsilva
Copy link
Copy Markdown
Contributor

@aleksandernsilva aleksandernsilva commented May 15, 2026

Proposed changes (including videos or screenshots)

This pull request adds support for handling SIP call diversion by introducing a new divertedBy field to the media calls system. The changes allow the system to detect when an incoming SIP call has been diverted, extract the relevant contact from the SIP Diversion header, and propagate this information through the media call creation and handling process.

SIP Diversion Support:

  • Added a new divertedBy field to the IMediaCall type and related internal call parameter types to represent the contact whose line was diverted at the SIP level.

SIP Call Handling Improvements:

  • Enhanced IncomingSipCall to detect and parse the SIP Diversion header from incoming calls, extract the diverting contact, and include it when creating new calls.
  • Added a new utility function parseDiversionHeader to parse the Diversion header and extract the extension and display name.

Call Transfer Logic:

  • Updated getNewCallTransferredBy to return the divertedBy contact when available, ensuring accurate reporting of call transfers caused by SIP diversion.

For the UI this change is transparent and incoming diverted calls will be treated as incoming call transfers.

Issue(s)

DMV-5

Steps to test or reproduce

If you are running freeswitch in a local container you can execute the following command to test
fs_cli -x "originate {sip_h_Diversion='\"John Doe\" <sip:sipp@[freeswitch_adress]>;reason=follow-me;privacy=off'}sofia/internal/[target_extension]@[sip_server_adress] &echo()"

Further comments

Summary by CodeRabbit

  • New Features
    • Added call diversion support for voice calls, enabling the system to track which contact diverted a call and maintain detailed diversion records in call history.

Review Change Stack

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented May 15, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 15, 2026

🦋 Changeset detected

Latest commit: f713a65

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 42 packages
Name Type
@rocket.chat/core-typings Minor
@rocket.chat/media-calls Minor
@rocket.chat/meteor Minor
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Major
@rocket.chat/gazzodown Major
@rocket.chat/http-router Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/models Patch
@rocket.chat/rest-typings Minor
@rocket.chat/ui-avatar Major
@rocket.chat/ui-client Major
@rocket.chat/ui-contexts Major
@rocket.chat/ui-voip Major
@rocket.chat/web-ui-registration Major
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/license Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/mock-providers Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch
@rocket.chat/ui-video-conf Major
@rocket.chat/ui-composer Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f1cdf457-885b-4653-bbac-b5850b698733

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR adds SIP Diversion header support to track call diversions in the media-calls system. A new data field divertedBy flows from type definitions through SIP parsing, incoming call processing, and call lifecycle management, with priority given to diverted contacts in call transfer signal determination.

Changes

Call Diversion Handling in Voice Calls

Layer / File(s) Summary
Type contracts for diversion data
packages/core-typings/src/mediaCalls/IMediaCall.ts, ee/packages/media-calls/src/definition/common.ts
IMediaCall and InternalCallParams each gain an optional divertedBy field of type MediaCallContact to represent the SIP-level diverted party sourced from the Diversion header.
SIP Diversion header parsing utility
ee/packages/media-calls/src/sip/utils/parseDiversionHeader.ts
New parseDiversionHeader(raw: string) utility parses RFC 5806 SIP Diversion headers, extracting user extension and display name from quoted name-addr and bare addr-spec forms, returning ParsedDiversion or null on invalid input.
Incoming SIP call diversion extraction
ee/packages/media-calls/src/sip/providers/IncomingSipCall.ts
processInvite extracts the Diversion header from incoming SIP invites, resolves the diverted contact via getDiversionContactFromInvite helper (which performs SIP extension lookup and builds contact metadata), and passes divertedBy to call creation.
Call creation and transferred-by signal propagation
ee/packages/media-calls/src/server/CallDirector.ts, ee/packages/media-calls/src/server/signals/getNewCallTransferredBy.ts
CallDirector.createCall destructures and conditionally persists divertedBy in the IMediaCall document; getNewCallTransferredBy prioritizes returning divertedBy over createdBy when determining call transfer origin.
Release notes
.changeset/gold-jobs-help.md
Changeset documents minor version bumps for @rocket.chat/core-typings and @rocket.chat/media-calls with call diversion handling support.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type: feature

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main feature added in this PR: support for call diversion handling in media calls, which is the primary objective across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • DMV-5: Request failed with status code 401

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

Updates versioning for core-typings and media-calls to minor. Adds support for call diversion handling in voice calls.
@aleksandernsilva
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot added the type: feature Pull requests that introduces new feature label May 15, 2026
Copy link
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core-typings/src/mediaCalls/IMediaCall.ts`:
- Around line 67-68: The JSDoc for the divertedBy property claims the contact is
"signed with the session contract" but the type is MediaCallContact (which lacks
contractId) and IncomingSipCall.getDiversionContactFromInvite returns an
unsigned contact; update the comment on divertedBy to reflect that it may be
unsigned (i.e., remove or rephrase "signed with the session contract") or
explicitly state it can be either signed or unsigned, and if you intend it to
always be signed change the type to MediaCallSignedContact and update
IncomingSipCall.getDiversionContactFromInvite to populate contractId
accordingly; reference divertedBy, MediaCallContact, MediaCallSignedContact, and
IncomingSipCall.getDiversionContactFromInvite when making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 388a87f0-efb0-4e50-a2f0-1e73667650c6

📥 Commits

Reviewing files that changed from the base of the PR and between fe65e8f and 8aacbdc.

📒 Files selected for processing (7)
  • .changeset/gold-jobs-help.md
  • ee/packages/media-calls/src/definition/common.ts
  • ee/packages/media-calls/src/server/CallDirector.ts
  • ee/packages/media-calls/src/server/signals/getNewCallTransferredBy.ts
  • ee/packages/media-calls/src/sip/providers/IncomingSipCall.ts
  • ee/packages/media-calls/src/sip/utils/parseDiversionHeader.ts
  • packages/core-typings/src/mediaCalls/IMediaCall.ts
📜 Review details
⏰ 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). (3)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • ee/packages/media-calls/src/server/signals/getNewCallTransferredBy.ts
  • packages/core-typings/src/mediaCalls/IMediaCall.ts
  • ee/packages/media-calls/src/sip/utils/parseDiversionHeader.ts
  • ee/packages/media-calls/src/server/CallDirector.ts
  • ee/packages/media-calls/src/definition/common.ts
  • ee/packages/media-calls/src/sip/providers/IncomingSipCall.ts
🧠 Learnings (4)
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.

Applied to files:

  • .changeset/gold-jobs-help.md
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • ee/packages/media-calls/src/server/signals/getNewCallTransferredBy.ts
  • packages/core-typings/src/mediaCalls/IMediaCall.ts
  • ee/packages/media-calls/src/sip/utils/parseDiversionHeader.ts
  • ee/packages/media-calls/src/server/CallDirector.ts
  • ee/packages/media-calls/src/definition/common.ts
  • ee/packages/media-calls/src/sip/providers/IncomingSipCall.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • ee/packages/media-calls/src/server/signals/getNewCallTransferredBy.ts
  • packages/core-typings/src/mediaCalls/IMediaCall.ts
  • ee/packages/media-calls/src/sip/utils/parseDiversionHeader.ts
  • ee/packages/media-calls/src/server/CallDirector.ts
  • ee/packages/media-calls/src/definition/common.ts
  • ee/packages/media-calls/src/sip/providers/IncomingSipCall.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • ee/packages/media-calls/src/server/signals/getNewCallTransferredBy.ts
  • packages/core-typings/src/mediaCalls/IMediaCall.ts
  • ee/packages/media-calls/src/sip/utils/parseDiversionHeader.ts
  • ee/packages/media-calls/src/server/CallDirector.ts
  • ee/packages/media-calls/src/definition/common.ts
  • ee/packages/media-calls/src/sip/providers/IncomingSipCall.ts
🔇 Additional comments (9)
.changeset/gold-jobs-help.md (1)

1-6: LGTM!

ee/packages/media-calls/src/definition/common.ts (1)

19-19: LGTM!

ee/packages/media-calls/src/sip/utils/parseDiversionHeader.ts (1)

1-47: LGTM!

ee/packages/media-calls/src/sip/providers/IncomingSipCall.ts (3)

21-21: LGTM!

Also applies to: 87-91


115-115: LGTM!


467-495: LGTM!

ee/packages/media-calls/src/server/CallDirector.ts (2)

185-186: LGTM!


235-235: LGTM!

ee/packages/media-calls/src/server/signals/getNewCallTransferredBy.ts (1)

5-9: LGTM!

Comment thread packages/core-typings/src/mediaCalls/IMediaCall.ts Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.66%. Comparing base (fe65e8f) to head (f713a65).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #40560      +/-   ##
===========================================
+ Coverage    69.61%   69.66%   +0.04%     
===========================================
  Files         3325     3325              
  Lines       122797   122797              
  Branches     21831    21865      +34     
===========================================
+ Hits         85490    85548      +58     
+ Misses       33957    33915      -42     
+ Partials      3350     3334      -16     
Flag Coverage Δ
e2e 59.18% <ø> (+0.10%) ⬆️
e2e-api 47.11% <ø> (+0.82%) ⬆️
unit 70.36% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Removed reference to session contract from divertedBy comment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Pull requests that introduces new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant