Skip to content

Commit 00611ac

Browse files
chore: Adds deprecation warning on livechat:getRoutingConfig with new endpoint to replace it (RocketChat#36897)
1 parent a89f0e5 commit 00611ac

6 files changed

Lines changed: 106 additions & 28 deletions

File tree

.changeset/itchy-news-design.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
"@rocket.chat/rest-typings": patch
4+
---
5+
6+
Adds deprecation warning on `livechat:getRoutingConfig`, as well as it adds new endpoint to replace it; `livechat/config/routing`

apps/meteor/app/livechat/client/lib/stream/queueManager.ts

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useLivechatInquiryStore } from '../../../../../client/hooks/useLivechat
44
import { queryClient } from '../../../../../client/lib/queryClient';
55
import { roomsQueryKeys } from '../../../../../client/lib/queryKeys';
66
import { settings } from '../../../../../client/lib/settings';
7-
import { callWithErrorHandling } from '../../../../../client/lib/utils/callWithErrorHandling';
7+
import { dispatchToastMessage } from '../../../../../client/lib/toast';
88
import { mapMessageFromApi } from '../../../../../client/lib/utils/mapMessageFromApi';
99
import { sdk } from '../../../../utils/client/lib/SDKClient';
1010

@@ -120,33 +120,38 @@ const addAgentListener = (userId: IOmnichannelAgent['_id']) => {
120120
};
121121

122122
const subscribe = async (userId: IOmnichannelAgent['_id']) => {
123-
const config = await callWithErrorHandling('livechat:getRoutingConfig');
124-
if (config?.autoAssignAgent) {
125-
return;
126-
}
123+
try {
124+
const { config } = await sdk.rest.get('/v1/livechat/config/routing');
125+
if (config?.autoAssignAgent) {
126+
return;
127+
}
127128

128-
const agentDepartments = (await getAgentsDepartments(userId)).map((department) => department.departmentId);
129+
const agentDepartments = (await getAgentsDepartments(userId)).map((department) => department.departmentId);
129130

130-
// Register to agent-specific queue, all depts + public queue to match the inquiry list returned by backend
131-
const cleanAgentListener = addAgentListener(userId);
132-
const cleanDepartmentListeners = addListenerForeachDepartment(agentDepartments);
133-
const globalCleanup = addGlobalListener();
131+
// Register to agent-specific queue, all depts + public queue to match the inquiry list returned by backend
132+
const cleanAgentListener = addAgentListener(userId);
133+
const cleanDepartmentListeners = addListenerForeachDepartment(agentDepartments);
134+
const globalCleanup = addGlobalListener();
134135

135-
const computation = Tracker.autorun(async () => {
136-
const inquiriesFromAPI = await getInquiriesFromAPI();
136+
const computation = Tracker.autorun(async () => {
137+
const inquiriesFromAPI = await getInquiriesFromAPI();
137138

138-
await updateInquiries(inquiriesFromAPI);
139-
});
139+
await updateInquiries(inquiriesFromAPI);
140+
});
140141

141-
return () => {
142-
useLivechatInquiryStore.getState().discardAll();
143-
removeGlobalListener();
144-
cleanAgentListener?.();
145-
cleanDepartmentListeners?.();
146-
globalCleanup?.();
147-
departments.clear();
148-
computation.stop();
149-
};
142+
return () => {
143+
useLivechatInquiryStore.getState().discardAll();
144+
removeGlobalListener();
145+
cleanAgentListener?.();
146+
cleanDepartmentListeners?.();
147+
globalCleanup?.();
148+
departments.clear();
149+
computation.stop();
150+
};
151+
} catch (error) {
152+
dispatchToastMessage({ type: 'error', message: error });
153+
throw error;
154+
}
150155
};
151156

152157
export const initializeLivechatInquiryStream = (() => {

apps/meteor/app/livechat/server/api/v1/config.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { isGETLivechatConfigParams } from '@rocket.chat/rest-typings';
1+
import { GETLivechatConfigRouting, isGETLivechatConfigParams } from '@rocket.chat/rest-typings';
22
import mem from 'mem';
33

44
import { API } from '../../../../api/server';
5+
import type { ExtractRoutesFromAPI } from '../../../../api/server/ApiClass';
56
import { settings as serverSettings } from '../../../../settings/server';
7+
import { RoutingManager } from '../../lib/RoutingManager';
68
import { online } from '../../lib/service-status';
79
import { settings, findOpenRoom, getExtraConfigInfo, findAgent, findGuestWithoutActivity } from '../lib/livechat';
810

@@ -38,3 +40,25 @@ API.v1.addRoute(
3840
},
3941
},
4042
);
43+
44+
const livechatConfigEndpoints = API.v1.get(
45+
'livechat/config/routing',
46+
{
47+
response: {
48+
200: GETLivechatConfigRouting,
49+
},
50+
authRequired: true,
51+
},
52+
async function action() {
53+
const config = RoutingManager.getConfig();
54+
55+
return API.v1.success({ config });
56+
},
57+
);
58+
59+
type LivechatConfigEndpoints = ExtractRoutesFromAPI<typeof livechatConfigEndpoints>;
60+
61+
declare module '@rocket.chat/rest-typings' {
62+
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
63+
interface Endpoints extends LivechatConfigEndpoints {}
64+
}

apps/meteor/app/livechat/server/methods/getRoutingConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { OmichannelRoutingConfig } from '@rocket.chat/core-typings';
22
import type { ServerMethods } from '@rocket.chat/ddp-client';
33
import { Meteor } from 'meteor/meteor';
44

5+
import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';
56
import { RoutingManager } from '../lib/RoutingManager';
67

78
declare module '@rocket.chat/ddp-client' {
@@ -13,6 +14,7 @@ declare module '@rocket.chat/ddp-client' {
1314

1415
Meteor.methods<ServerMethods>({
1516
'livechat:getRoutingConfig'() {
17+
methodDeprecationLogger.method('livechat:getRoutingConfig', '8.0.0', 'v1/livechat/config/routing');
1618
return RoutingManager.getConfig();
1719
},
1820
});

apps/meteor/client/providers/OmnichannelProvider.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '@rocket.chat/core-typings';
77
import { useSafely } from '@rocket.chat/fuselage-hooks';
88
import { createComparatorFromSort } from '@rocket.chat/mongo-adapter';
9-
import { useUser, useSetting, usePermission, useMethod, useEndpoint, useStream, useCustomSound } from '@rocket.chat/ui-contexts';
9+
import { useUser, useSetting, usePermission, useEndpoint, useStream, useCustomSound } from '@rocket.chat/ui-contexts';
1010
import { useQuery, useQueryClient } from '@tanstack/react-query';
1111
import type { ReactNode } from 'react';
1212
import { useState, useEffect, useMemo, memo, useRef } from 'react';
@@ -61,7 +61,7 @@ const OmnichannelProvider = ({ children }: OmnichannelProviderProps) => {
6161
const agentAvailable = user?.statusLivechat === 'available';
6262
const voipCallAvailable = true; // TODO: use backend check;
6363

64-
const getRoutingConfig = useMethod('livechat:getRoutingConfig');
64+
const getRoutingConfig = useEndpoint('GET', '/v1/livechat/config/routing');
6565

6666
const [routeConfig, setRouteConfig] = useSafely(useState<OmichannelRoutingConfig | undefined>(undefined));
6767

@@ -109,8 +109,8 @@ const OmnichannelProvider = ({ children }: OmnichannelProviderProps) => {
109109

110110
const update = async (): Promise<void> => {
111111
try {
112-
const routeConfig = await getRoutingConfig();
113-
setRouteConfig(routeConfig);
112+
const { config } = await getRoutingConfig();
113+
setRouteConfig(config);
114114
} catch (error) {
115115
loggerRef.current.error(`update() error in routeConfig ${error}`);
116116
}

packages/rest-typings/src/v1/omnichannel.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type {
3131
ILivechatContact,
3232
ILivechatContactChannel,
3333
IUser,
34+
OmichannelRoutingConfig,
3435
} from '@rocket.chat/core-typings';
3536
import { ILivechatAgentStatus } from '@rocket.chat/core-typings';
3637
import type { WithId } from 'mongodb';
@@ -2134,6 +2135,46 @@ const GETLivechatConfigParamsSchema = {
21342135

21352136
export const isGETLivechatConfigParams = ajv.compile<GETLivechatConfigParams>(GETLivechatConfigParamsSchema);
21362137

2138+
export const GETLivechatConfigRoutingSchema = {
2139+
type: 'object',
2140+
properties: {
2141+
config: {
2142+
type: 'object',
2143+
nullable: true,
2144+
properties: {
2145+
previewRoom: {
2146+
type: 'boolean',
2147+
},
2148+
showConnecting: {
2149+
type: 'boolean',
2150+
},
2151+
showQueue: {
2152+
type: 'boolean',
2153+
},
2154+
showQueueLink: {
2155+
type: 'boolean',
2156+
},
2157+
returnQueue: {
2158+
type: 'boolean',
2159+
},
2160+
enableTriggerAction: {
2161+
type: 'boolean',
2162+
},
2163+
autoAssignAgent: {
2164+
type: 'boolean',
2165+
},
2166+
},
2167+
},
2168+
success: {
2169+
type: 'boolean',
2170+
enum: [true],
2171+
},
2172+
},
2173+
additionalProperties: false,
2174+
};
2175+
2176+
export const GETLivechatConfigRouting = ajv.compile<{ config: OmichannelRoutingConfig | undefined }>(GETLivechatConfigRoutingSchema);
2177+
21372178
type POSTLivechatCustomFieldParams = {
21382179
token: string;
21392180
key: string;

0 commit comments

Comments
 (0)