Skip to content

Conversation

@lucas-a-pelegrino
Copy link
Contributor

@lucas-a-pelegrino lucas-a-pelegrino commented Sep 18, 2025

Proposed changes (including videos or screenshots)

This PR adds a deprecation warning to livechat:takeInquiry, moves the takeInquiry function to its own file, as well as it replaces the use of livechat:takeInquiry for the livechat/inquiries.take endpoint in the client.

Issue(s)

CTZ-70

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Deprecations

    • livechat:removeRoom deprecated; use livechat/inquiries.take.
    • livechat:takeInquiry deprecated; use REST endpoint /v1/livechat/inquiries.take.
  • API Changes

    • /v1/livechat/inquiries.take now accepts an options object (clientAction, forwardingToDepartment with oldDepartmentId and transferData).
    • Updated request typings and validation to match the new payload.
  • Improvements

    • Agent “Take Inquiry” action now uses the REST API for better reliability; no UI changes.
    • Added a safeguard to avoid calls when no inquiry is present.

@lucas-a-pelegrino lucas-a-pelegrino added this to the 7.11.0 milestone Sep 18, 2025
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Sep 18, 2025

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

  • This PR is targeting the wrong base branch. It should target 7.12.0, but it targets 7.11.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Sep 18, 2025

🦋 Changeset detected

Latest commit: d910c57

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

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

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
Contributor

coderabbitai bot commented Sep 18, 2025

Walkthrough

Centralizes livechat takeInquiry logic into a new server library, updates the Meteor method to delegate and log deprecation, switches the client to use the REST endpoint with new parameter shape, adjusts REST typings to include an options object, updates a REST route import, and adds a changeset noting deprecations/version bumps.

Changes

Cohort / File(s) Summary
Centralized server logic for takeInquiry
apps/meteor/app/livechat/server/lib/takeInquiry.ts
New implementation of takeInquiry with validation, agent resolution, MAC checks, contact handling, and delegation to RoutingManager; wraps errors as Meteor errors; defaults options.
Method delegates to lib + deprecation
apps/meteor/app/livechat/server/methods/takeInquiry.ts
Replaces inline logic with call to lib/takeInquiry; adds deprecation log for method; adds permission check; removes previous dependencies.
Client migration to REST endpoint
apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelInquiry.tsx
Replaces useMethod with useEndpoint POST /v1/livechat/inquiries.take; adjusts parameter shape to object; adds guard for missing inquiry.
REST route import adjustment
apps/meteor/app/livechat/imports/server/rest/inquiries.ts
Changes takeInquiry import path from server/methods to server/lib; route behavior unchanged.
REST typings expansion
packages/rest-typings/src/v1/omnichannel.ts
Adds optional options field to POSTLivechatInquiriesTakeParams and schema, including clientAction and forwardingToDepartment.oldDepartmentId/transferData with strict validation.
Changeset metadata
.changeset/nice-balloons-relax.md
Notes deprecation for livechat:removeRoom and recommends livechat/inquiries.take; bumps patch versions for @rocket.chat/meteor and @rocket.chat/rest-typings.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Agent as Client (Composer)
  participant REST as REST API /v1/livechat/inquiries.take
  participant Lib as Server lib/takeInquiry
  participant Users as Users
  participant Inq as LivechatInquiry
  participant Rooms as LivechatRooms
  participant Omni as Omnichannel (MAC)
  participant Route as RoutingManager

  Agent->>REST: POST { inquiryId, userId?, options{ clientAction, ... } }
  REST->>Lib: takeInquiry(userId, inquiryId, options)
  Lib->>Inq: find inquiry by ID
  Inq-->>Lib: inquiry or not found
  alt inquiry not found or already taken
    Lib-->>REST: throw Meteor.Error
    REST-->>Agent: HTTP error
  else valid inquiry
    Lib->>Users: findOneOnlineAgentById(userId, idleSetting)
    Users-->>Lib: agent or null
    alt agent unavailable
      Lib-->>REST: throw Meteor.Error
      REST-->>Agent: HTTP error
    else
      Lib->>Rooms: get room by inquiry
      Rooms-->>Lib: room
      Lib->>Omni: isWithinMACLimit(room)
      Omni-->>Lib: boolean
      alt MAC limit exceeded
        Lib-->>REST: throw Meteor.Error
        REST-->>Agent: HTTP error
      else ok
        note over Lib,Route: Optionally validate contact availability<br/>and migrate/verify contact
        Lib->>Route: takeInquiry(inquiry, agent, options, room)
        Route-->>Lib: success or error
        alt routing error
          Lib-->>REST: throw Meteor.Error
          REST-->>Agent: HTTP error
        else success
          REST-->>Agent: 200 OK
        end
      end
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • aleksandernsilva
  • tassoevan
  • sampaiodiego

Poem

A hop, a skip—new routes we take,
From method burrow to RESTful lake.
I twitch my nose: inquiries fly,
Through checks and rooms, we route them spry.
Patchy clouds part—logs deprecate—
Thump-thump! Ship it. This looks great. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning Most changes are in-scope for CTZ-70, however the .changeset file references a deprecation for 'livechat:removeRoom' and suggests 'livechat/inquiries.take' as a replacement, which is inconsistent with the PR objectives and appears to be an erroneous or unrelated entry. Aside from that mismatch, the code moves, method delegation, client update, and REST-typings changes are relevant to the issue. Update the .changeset to correctly reference the deprecation of 'livechat:takeInquiry' (or remove the unintended 'livechat:removeRoom' note), confirm the package patch version bumps are intentional, and rerun changeset/changelog tooling so the repository changelog and release notes reflect only the intended changes.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "chore: Adds deprecation warning on livechat:takeInquiry" is concise and directly describes a core change in the PR — adding a deprecation warning for the livechat:takeInquiry method — and aligns with the PR objectives to deprecate the method while migrating clients to the /v1/livechat/inquiries.take endpoint and centralizing implementation. It is specific and clear enough for a teammate scanning history.
Linked Issues Check ✅ Passed The code changes implement the coding objectives from CTZ-70: they add a deprecation log for 'livechat:takeInquiry', move the implementation into apps/meteor/app/livechat/server/lib/takeInquiry.ts, update the Meteor method to delegate and emit the deprecation, and update client code and REST typings to use the /v1/livechat/inquiries.take endpoint with the new options shape. These edits are focused on code-level work and satisfy the linked issue's stated intent.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/v7/CTZ-70

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

@codecov
Copy link

codecov bot commented Sep 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.23%. Comparing base (65b57cc) to head (d910c57).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #36993      +/-   ##
===========================================
- Coverage    67.30%   66.23%   -1.08%     
===========================================
  Files         3337     3391      +54     
  Lines       113326   115579    +2253     
  Branches     20563    21241     +678     
===========================================
+ Hits         76278    76557     +279     
- Misses       34444    36402    +1958     
- Partials      2604     2620      +16     
Flag Coverage Δ
e2e 57.01% <100.00%> (-0.02%) ⬇️
unit 71.12% <ø> (-0.04%) ⬇️

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.

@lucas-a-pelegrino lucas-a-pelegrino marked this pull request as ready for review September 19, 2025 16:17
@lucas-a-pelegrino lucas-a-pelegrino requested review from a team as code owners September 19, 2025 16:17
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (2)

60-66: Bug: options are ignored when calling takeInquiry.

Client sends options (e.g., clientAction: true) but the route drops them. Forward them to the lib.

-			return API.v1.success({
-				inquiry: await takeInquiry(this.bodyParams.userId || this.userId, this.bodyParams.inquiryId),
-			});
+			return API.v1.success({
+				inquiry: await takeInquiry(
+					this.bodyParams.userId || this.userId,
+					this.bodyParams.inquiryId,
+					this.bodyParams.options,
+				),
+			});

64-66: Bug: response returns undefined inquiry (lib returns void).

Contract for /v1/livechat/inquiries.take is { inquiry: ILivechatInquiryRecord }, but takeInquiry() currently returns void. Fix one of these:

  • Preferred: make server/lib/takeInquiry return ILivechatInquiryRecord and keep this route as-is after the options fix.
  • Alternative (if lib stays void): fetch the inquiry after the call.
-			return API.v1.success({
-				inquiry: await takeInquiry(this.bodyParams.userId || this.userId, this.bodyParams.inquiryId, this.bodyParams.options),
-			});
+			await takeInquiry(this.bodyParams.userId || this.userId, this.bodyParams.inquiryId, this.bodyParams.options);
+			const inquiry = await LivechatInquiry.findOneById(this.bodyParams.inquiryId);
+			return API.v1.success({ inquiry });
apps/meteor/app/livechat/server/methods/takeInquiry.ts (2)

10-14: Align DDP options type with REST shape.

Use departmentId (not oldDepartmentId) and avoid any.

-		'livechat:takeInquiry'(
-			inquiryId: string,
-			options?: { clientAction: boolean; forwardingToDepartment?: { oldDepartmentId: string; transferData: any } },
-		): unknown;
+		'livechat:takeInquiry'(
+			inquiryId: string,
+			options?: { clientAction: boolean; forwardingToDepartment?: { departmentId: string; transferData: unknown } },
+		): unknown;

17-29: Return the inquiry from the lib and pass it through the Meteor method.

takeInquiry (apps/meteor/app/livechat/server/lib/takeInquiry.ts) currently returns Promise, so the Meteor method returns undefined over DDP. Change the lib to return the inquiry (the updated inquiry — e.g., refetch with LivechatInquiry.findOneById(inquiryId) after RoutingManager.takeInquiry) and update the Meteor method to await and return it.

Files to change:

  • apps/meteor/app/livechat/server/lib/takeInquiry.ts — change return type and return the (updated) inquiry after RoutingManager.takeInquiry.
  • apps/meteor/app/livechat/server/methods/takeInquiry.ts — return the value (await) from the lib.

Suggested method diff (keep as-is):

-		return takeInquiry(uid, inquiryId, options);
+		return await takeInquiry(uid, inquiryId, options);
🧹 Nitpick comments (2)
.changeset/nice-balloons-relax.md (1)

6-6: Fix changeset entry: wrong method name and missing leading slash.

This PR deprecates livechat:takeInquiry, not livechat:removeRoom. Also prefer the canonical endpoint path with leading slash.

-Adds deprecation warning on `livechat:removeRoom`, use `livechat/inquiries.take` instead
+Adds deprecation warning on `livechat:takeInquiry`; use `/v1/livechat/inquiries.take` instead
apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelInquiry.tsx (1)

36-39: Harden toast error handling.

Ensure a string is shown instead of an object.

-		} catch (error) {
-			dispatchToastMessage({ type: 'error', message: error });
+		} catch (error) {
+			dispatchToastMessage({
+				type: 'error',
+				message: error instanceof Error ? error.message : String(error),
+			});
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 490d4bc and d31d655.

📒 Files selected for processing (6)
  • .changeset/nice-balloons-relax.md (1 hunks)
  • apps/meteor/app/livechat/imports/server/rest/inquiries.ts (1 hunks)
  • apps/meteor/app/livechat/server/lib/takeInquiry.ts (1 hunks)
  • apps/meteor/app/livechat/server/methods/takeInquiry.ts (2 hunks)
  • apps/meteor/client/views/room/composer/ComposerOmnichannel/ComposerOmnichannelInquiry.tsx (3 hunks)
  • packages/rest-typings/src/v1/omnichannel.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/meteor/app/livechat/server/lib/takeInquiry.ts (4)
apps/meteor/app/livechat/server/methods/takeInquiry.ts (1)
  • inquiryId (18-28)
packages/models/src/index.ts (2)
  • LivechatInquiry (173-173)
  • LivechatRooms (175-175)
packages/core-services/src/index.ts (1)
  • Omnichannel (181-181)
apps/meteor/app/livechat/server/lib/RoutingManager.ts (1)
  • RoutingManager (73-346)
🔇 Additional comments (1)
packages/rest-typings/src/v1/omnichannel.ts (1)

3346-3370: Schema looks good; keep transferData typed unknown.

No change requested here; just ensure server accepts this exact structure.

If you change server-side types, re-run REST schema tests that validate additionalProperties: false for options.

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

🧹 Nitpick comments (2)
apps/meteor/app/livechat/server/methods/takeInquiry.ts (2)

5-6: Unify option typing with REST typings to avoid drift

Inline-shaping options can diverge from the REST contract. Import and reuse the shared REST type for parity.

Apply this diff to add the type import:

 import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';
 import { takeInquiry } from '../lib/takeInquiry';
+import type { POSTLivechatInquiriesTakeParams } from '@rocket.chat/rest-typings';

Then update the method signature to reuse it (outside this hunk):

// in the ServerMethods interface
'livechat:takeInquiry'(inquiryId: string, options?: POSTLivechatInquiriesTakeParams['options']): unknown;

Also confirm that runtime validation now lives in lib/takeInquiry; if not, consider keeping a lightweight boundary check for inquiryId here.


28-32: Permission scope: ensure we also require 'receive-livechat' (or equivalent)

If lib/takeInquiry doesn’t enforce agent capabilities, gating only on view-l-room may be too permissive. Either rely solely on lib’s checks or strengthen this method’s guard to include the agent capability.

If you choose to harden here, one option:

-		if (!(await hasPermissionAsync(uid, 'view-l-room'))) {
+		const [canView, canReceive] = await Promise.all([
+			hasPermissionAsync(uid, 'view-l-room'),
+			hasPermissionAsync(uid, 'receive-livechat'),
+		]);
+		if (!canView || !canReceive) {
 			throw new Meteor.Error('error-not-allowed', 'Not allowed', {
 				method: 'livechat:takeInquiry',
 			});
 		}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e852e69 and b9db48f.

📒 Files selected for processing (1)
  • apps/meteor/app/livechat/server/methods/takeInquiry.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/meteor/app/livechat/server/methods/takeInquiry.ts (1)
apps/meteor/app/livechat/server/methods/getFirstRoomMessage.ts (1)
  • uid (17-35)
⏰ 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 comments (1)
apps/meteor/app/livechat/server/methods/takeInquiry.ts (1)

20-20: Deprecation log: present — confirm 8.0.0 removal target

  • methodDeprecationLogger.method('livechat:takeInquiry', '8.0.0', '/v1/livechat/inquiries.take') at apps/meteor/app/livechat/server/methods/takeInquiry.ts:20.
  • Repo shows mixed removal targets for other livechat methods (e.g., livechat:transfer uses '7.0.0'); confirm 8.0.0 is the intended target in changesets/docs.

Copy link
Member

@dougfabris dougfabris left a comment

Choose a reason for hiding this comment

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

On behalf of frontend, looks good to me

@lucas-a-pelegrino lucas-a-pelegrino added the stat: QA assured Means it has been tested and approved by a company insider label Sep 23, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Sep 23, 2025
@dougfabris dougfabris modified the milestones: 7.11.0, 7.12.0 Sep 24, 2025
@ggazzo ggazzo merged commit c15a47e into develop Sep 24, 2025
45 of 49 checks passed
@ggazzo ggazzo deleted the chore/v7/CTZ-70 branch September 24, 2025 21:09
@dougfabris dougfabris modified the milestones: 7.12.0, 7.11.0 Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants