diff --git a/app/definitions/rest/v1/omnichannel.ts b/app/definitions/rest/v1/omnichannel.ts index 0f3162d195e..1f6915f2c39 100644 --- a/app/definitions/rest/v1/omnichannel.ts +++ b/app/definitions/rest/v1/omnichannel.ts @@ -136,11 +136,16 @@ export type OmnichannelEndpoints = { }; 'livechat/inquiries.take': { - POST: (params: { inquiryId: string }) => void; + POST: (params: { inquiryId: string; userId?: string }) => { + success: boolean; + }; }; 'livechat/inquiries.returnAsInquiry': { - POST: (params: { roomId: string; departmentId?: string }) => boolean; + POST: (params: { roomId: string; departmentId?: string }) => { + result: boolean; + success: boolean; + }; }; 'livechat/rooms': { @@ -251,4 +256,38 @@ export type OmnichannelEndpoints = { }; }) => void; }; + 'livechat/agent.status': { + POST: (params: { agentId?: string }) => { + status: string; + success: boolean; + }; + }; + 'livechat/room.closeByUser': { + POST: (params: { + rid: string; + comment?: string; + forceClose?: boolean; + tags?: string[]; + generateTranscriptPdf?: boolean; + transcriptEmail?: { sendToVisitor: boolean; requestData?: { email?: string; subject?: string } }; + }) => { + success: boolean; + }; + }; + 'livechat/room.forward': { + POST: (params: { roomId: string; userId?: string; departmentId?: string }) => { + success: boolean; + }; + }; + 'livechat/tags': { + GET: () => { + tags: ILivechatTag[]; + success: boolean; + }; + }; + 'livechat/room.resumeOnHold': { + POST: (params: { roomId: string }) => { + success: boolean; + }; + }; }; diff --git a/app/definitions/rest/v1/users.ts b/app/definitions/rest/v1/users.ts index 751cfbf83fb..23ab993504a 100644 --- a/app/definitions/rest/v1/users.ts +++ b/app/definitions/rest/v1/users.ts @@ -69,4 +69,7 @@ export type UsersEndpoints = { 'users.deleteOwnAccount': { POST: (params: { password: string; confirmRelinquish: boolean }) => { success: boolean }; }; + 'users.sendConfirmationEmail': { + POST: (params: { email: string }) => { success: boolean }; + }; }; diff --git a/app/ee/omnichannel/lib/index.ts b/app/ee/omnichannel/lib/index.ts index b3cfc4a852b..60308b3cb43 100644 --- a/app/ee/omnichannel/lib/index.ts +++ b/app/ee/omnichannel/lib/index.ts @@ -1,12 +1,20 @@ import sdk from '../../../lib/services/sdk'; import { compareServerVersion } from '../../../lib/methods/helpers'; import EventEmitter from '../../../lib/methods/helpers/events'; +import { store as reduxStore } from '../../../lib/store/auxStore'; import subscribeInquiry from './subscriptions/inquiry'; export const isOmnichannelStatusAvailable = (statusLivechat: string | undefined): boolean => statusLivechat === 'available'; // RC 0.26.0 -export const changeLivechatStatus = () => sdk.methodCallWrapper('livechat:changeLivechatStatus'); +export const changeLivechatStatus = () => { + const serverVersion = reduxStore.getState().server.version; + if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '8.0.0')) { + return sdk.post('livechat/agent.status'); + } + // Method removed in 8.0.0 + return sdk.methodCallWrapper('livechat:changeLivechatStatus'); +}; // RC 2.4.0 // @ts-ignore @@ -29,7 +37,14 @@ export const takeInquiry = (inquiryId: string, serverVersion: string) => { }; // RC 4.26 -export const takeResume = (roomId: string) => sdk.methodCallWrapper('livechat:resumeOnHold', roomId); +export const takeResume = (roomId: string) => { + const serverVersion = reduxStore.getState().server.version; + if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '8.0.0')) { + return sdk.post('livechat/room.resumeOnHold', { roomId }); + } + // Method removed in 8.0.0 + return sdk.methodCallWrapper('livechat:resumeOnHold', roomId); +}; class Omnichannel { private inquirySub: { stop: () => void } | null; diff --git a/app/lib/services/restApi.ts b/app/lib/services/restApi.ts index fae53447715..3b0d50e2a7b 100644 --- a/app/lib/services/restApi.ts +++ b/app/lib/services/restApi.ts @@ -106,8 +106,14 @@ export const forgotPassword = (email: string) => // RC 0.64.0 sdk.post('users.forgotPassword', { email }); -export const sendConfirmationEmail = (email: string): Promise<{ message: string; success: boolean }> => - sdk.methodCallWrapper('sendConfirmationEmail', email); +export const sendConfirmationEmail = (email: string): Promise<{ success: boolean }> => { + const serverVersion = reduxStore.getState().server.version; + if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '8.0.0')) { + return sdk.post('users.sendConfirmationEmail', { email }); + } + + return sdk.methodCallWrapper('sendConfirmationEmail', email); +}; export const spotlight = ( search: string, @@ -411,11 +417,15 @@ export const getTeamListRoom = ({ }; export const closeLivechat = (rid: string, comment?: string, tags?: string[]) => { + const serverVersion = reduxStore.getState().server.version; // RC 3.2.0 let params; if (tags && tags?.length) { params = { tags }; } + if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '8.0.0')) { + return sdk.post('livechat/room.closeByUser', { rid, comment, ...params }); + } // RC 0.29.0 return sdk.methodCallWrapper('livechat:closeRoom', rid, comment, { clientAction: true, ...params }); }; @@ -443,9 +453,14 @@ export const returnLivechat = (rid: string, departmentId?: string): Promise export const onHoldLivechat = (roomId: string) => sdk.post('livechat/room.onHold', { roomId }); -export const forwardLivechat = (transferData: any) => +export const forwardLivechat = (transferData: any) => { + const serverVersion = reduxStore.getState().server.version; + if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '8.0.0')) { + return sdk.post('livechat/room.forward', transferData); + } // RC 0.36.0 - sdk.methodCallWrapper('livechat:transfer', transferData); + return sdk.methodCallWrapper('livechat:transfer', transferData); +}; export const getDepartmentInfo = (departmentId: string) => // RC 2.2.0 @@ -489,9 +504,18 @@ export const getRoutingConfig = async (): Promise<{ return sdk.methodCallWrapper('livechat:getRoutingConfig'); }; -export const getTagsList = (): Promise => +export const getTagsList = async (): Promise => { + const serverVersion = reduxStore.getState().server.version; + if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '8.0.0')) { + const result = await sdk.get('livechat/tags'); + if (result.success) { + return result.tags || []; + } + return []; + } // RC 2.0.0 - sdk.methodCallWrapper('livechat:getTagsList'); + return sdk.methodCallWrapper('livechat:getTagsList'); +}; export const getAgentDepartments = (uid: string) => // RC 2.4.0