NTP-27557 | Ameyo Extension Deprecation

This commit is contained in:
vivek bhadola
2025-01-20 15:26:30 +05:30
parent 91f1deede6
commit e3f6d7a513
7 changed files with 165 additions and 115 deletions

View File

@@ -1,6 +1,6 @@
import getResponseWithoutCors from "@universal-call-sdk/common/lib/utils/getResponseWithoutCors.ts";
import getResponse from "@universal-call-sdk/common/lib/utils/getResponse.ts";
import {CallTransferData, RequestKeys} from "./types";
import RequestType from "@universal-call-sdk/common/lib/types/RequestType.ts";
import { RequestType } from "@universal-call-sdk/common/lib/types/Request.ts";
import {v4 as uuid} from 'uuid';
@@ -9,7 +9,7 @@ export const loginInAmeyo = (userId: string, password: string) => {
if(!userId || !password) {
return
}
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/userLogin/login`,
method: 'POST',
requestKey: RequestKeys.AMEYO_LOGIN,
@@ -30,7 +30,7 @@ export const loginInAmeyo = (userId: string, password: string) => {
};
export const maintainHeartbeat = (sessionId: string, webcoreTimestamp: string, counter: number) => {
const HEART_BEAT_REQUEST_TEXT = `7|0|8|${window.BASE_AMEYO_URL}/app/application_ui/|93B024BCBAF3AE5EFEC49890FE64CF5F|com.drishti.ameyo.common.ui.rpc.CommonGwtRpcService|keepAliveWithPingPush|java.lang.String/2004016611|java.lang.Integer/3438268394|${sessionId}|${webcoreTimestamp}|1|2|3|4|3|5|5|6|7|8|6|${counter}|${sessionId}|`;
setInterval(() => getResponseWithoutCors({
setInterval(() => getResponse({
url: `${window.BASE_AMEYO_URL}/ameyo40/service`,
method: 'POST',
requestKey: RequestKeys.AMEYO_HEARTBEAT,
@@ -44,7 +44,7 @@ export const maintainHeartbeat = (sessionId: string, webcoreTimestamp: string, c
};
export const setAgentOnBreak = (sessionId: string) => {
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/cc/userBreak`,
method: 'POST',
requestKey: RequestKeys.AMEYO_ON_BREAK,
@@ -62,7 +62,7 @@ export const setAgentOnBreak = (sessionId: string) => {
export const attachOmniqueService = (sessionId: string, userId: string, campaignId: string) => {
const OMNIQUEUE_TEXT = `7|0|9|${window.BASE_AMEYO_URL}/app/application_ui/|5B1786BFF89E87DC6EAAACDE629A89E2|com.drishti.ameyo.omniqueue.shared.CommonGwtRpcService|selectCamapign|java.lang.String/2004016611|[Ljava.lang.Integer;/1574882222|${sessionId}|${userId}|java.lang.Integer/3438268394|1|2|3|4|3|5|5|6|7|8|6|1|9|${campaignId}|${sessionId}|`;
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyoomniqueue/service`,
method: 'POST',
requestKey: RequestKeys.OMNIQUEUE_SERVICE,
@@ -76,7 +76,7 @@ export const attachOmniqueService = (sessionId: string, userId: string, campaign
};
export const setAgentActive = (sessionId: string) => {
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/cc/userReady`,
method: 'POST',
requestKey: RequestKeys.AMEYO_AVAILABLE,
@@ -92,7 +92,7 @@ export const setAgentActive = (sessionId: string) => {
};
export const getSipAccountInfo = (sessionId: string, userId: string) => {
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/sipAccountInfos/getSipAccountInfo?info=false`,
method: 'GET',
requestKey: RequestKeys.SIP_ACCOUNT_INFO,
@@ -106,7 +106,7 @@ export const getSipAccountInfo = (sessionId: string, userId: string) => {
};
export const autoSelectExtension = (sessionId: string, userId: string) => {
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/autoSelectExtension`,
method: 'POST',
requestKey: RequestKeys.AUTO_SELECT_EXTENSION,
@@ -123,7 +123,7 @@ export const autoSelectExtension = (sessionId: string, userId: string) => {
export const selectCampaign = (sessionId: string, userId: string, campaignId: string) => {
const SELECT_CAMPAIGN_TEXT = `7|0|9|${window.BASE_AMEYO_URL}/app/application_ui/|5B1786BFF89E87DC6EAAACDE629A89E2|com.drishti.ameyo.omniqueue.shared.CommonGwtRpcService|selectCamapign|java.lang.String/2004016611|[Ljava.lang.Integer;/1574882222|${sessionId}|${userId}|java.lang.Integer/3438268394|1|2|3|4|3|5|5|6|7|8|6|1|9|${campaignId}|${sessionId}|`;
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyoomniqueue/service`,
method: 'POST',
requestKey: RequestKeys.SELECT_CAMPAIGN,
@@ -137,7 +137,7 @@ export const selectCampaign = (sessionId: string, userId: string, campaignId: st
};
export const setAutoStatus = (sessionId: string) => {
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/cc/setAutoStatusForUser`,
method: 'POST',
requestKey: RequestKeys.SET_AUTO_STATUS,
@@ -150,7 +150,7 @@ export const setAutoStatus = (sessionId: string) => {
};
export const ameyoHangupUser = (sessionId: string, userCRTObjectId: string) => {
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/hangupUser`,
method: 'POST',
requestKey: RequestKeys.HANGUP_USER,
@@ -163,7 +163,7 @@ export const ameyoHangupUser = (sessionId: string, userCRTObjectId: string) => {
};
export const ameyoDisposeCall = (sessionId: string, campaignId: string, crtObjectId: string, userCRTObjectId: string) => {
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/disposeCall`,
method: 'POST',
requestKey: RequestKeys.DISPOSE_CALL,
@@ -185,7 +185,7 @@ export const ameyoDisposeCall = (sessionId: string, campaignId: string, crtObjec
};
export const getCampaignId = (sessionId: string) => {
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/sessionData/getAllSessionData`,
method: 'GET',
requestKey: RequestKeys.GET_CAMPAIGN_ID,
@@ -198,7 +198,7 @@ export const getCampaignId = (sessionId: string) => {
}
export const getAllAgentsForTransferCall = (sessionId: string) => {
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/getAllUserCampaignVoicePresencesByContactCenterId`,
method: 'GET',
requestKey: RequestKeys.GET_AGENTS_FOR_CALL_TRANSFER,
@@ -212,7 +212,7 @@ export const getAllAgentsForTransferCall = (sessionId: string) => {
export const logoutFromAmeyo = (sessionId: string) => {
const LOGOUT_PAYLOAD_TEXT = `7|0|7|${window.BASE_AMEYO_URL}/app/application_ui/|C066834E4747CF348FD8D1A68865C24D|com.drishti.ameyo.common.ui.rpc.CommonGwtRpcService|doLogout|java.lang.String/2004016611|${sessionId}|Logout from UI|1|2|3|4|2|5|5|6|7|${sessionId}|`;
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyo40/service`,
method: 'POST',
requestKey: RequestKeys.LOGOUT_FROM_AMEYO,
@@ -227,7 +227,7 @@ export const logoutFromAmeyo = (sessionId: string) => {
export const transferCallToAgent = (data: CallTransferData, sessionId: string, crtObjectId: string, userCRTObjectId: string, campaignId: string) => {
return getResponseWithoutCors({
return getResponse({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/transferToUserInDifferentCampaign`,
method: 'POST',
requestKey: RequestKeys.TRANSFER_CALL_TO_AGENT,

View File

@@ -1,4 +1,5 @@
import IAdapter from "@universal-call-sdk/common/lib/Interfaces/IAdapter";
import GenericFunction from "@universal-call-sdk/common/lib/types/GenericFunction";
import GenericObject from "@universal-call-sdk/common/lib/types/GenericObject";
import {
AmeyoInitializationOptions,
@@ -143,8 +144,9 @@ class AmeyoAdapter implements IAdapter {
}
};
private initializeAmeyo = (): void => {
loginInAmeyo(this.userName.toLowerCase(), this.password);
private initializeAmeyo = async (): Promise<void> => {
const res = await loginInAmeyo(this.userName.toLowerCase(), this.password);
if (res) this.handleApiResponse(res, this.handleLoginResponse);
};
private handleMessage = async ({data}: MessageEvent): Promise<void> => {
@@ -154,9 +156,6 @@ class AmeyoAdapter implements IAdapter {
}
switch (data.type) {
case MessagingType.SET_RESPONSE_WITHOUT_CORS:
await this.handleCorsBypassResponse(data);
break;
case MessagingType.ON_AMEYO_CALL_INCOMING:
this.handleCallIncoming(data);
break;
@@ -207,36 +206,13 @@ class AmeyoAdapter implements IAdapter {
});
}
private async handleCorsBypassResponse(payload: GenericObject): Promise<void> {
private handleApiResponse = async (
payload: GenericObject,
apiHandler: GenericFunction
): Promise<void> => {
apiHandler(payload);
this.trackApiMetrics(payload);
switch (payload?.data?.requestKey) {
case RequestKeys.AMEYO_LOGIN:
await this.handleLoginResponse(payload);
break;
case RequestKeys.SIP_ACCOUNT_INFO:
await this.handleSipAccountInfo(payload);
break;
case RequestKeys.GET_CAMPAIGN_ID:
await this.handleCampaignId(payload);
break;
case RequestKeys.AMEYO_AVAILABLE:
this.handleAgentAvailable();
break;
case RequestKeys.OMNIQUEUE_SERVICE:
await this.handleOmniQueueService();
break;
case RequestKeys.SELECT_CAMPAIGN:
await this.handleCampaignSelection();
break;
case RequestKeys.AMEYO_ON_BREAK:
this.handleAgentBreak();
break;
case RequestKeys.GET_AGENTS_FOR_CALL_TRANSFER:
this.handleAgentsForTransfer(payload);
break;
}
}
};
private trackApiMetrics(payload: GenericObject): void {
if (payload?.data?.requestKey !== RequestKeys.AMEYO_HEARTBEAT && !payload?.data?.err) {
@@ -266,7 +242,7 @@ class AmeyoAdapter implements IAdapter {
}
}
private async handleLoginResponse(payload: GenericObject): Promise<void> {
private handleLoginResponse = async (payload: GenericObject): Promise<void> => {
if (payload?.data?.err) {
console.log('Login failed:', payload?.data?.err);
this.callbacks.onLoginFailed(payload?.err);
@@ -275,12 +251,13 @@ class AmeyoAdapter implements IAdapter {
const sessionId = payload?.data?.response?.userSessionInfo?.sessionId;
this.sessionId = sessionId;
await getSipAccountInfo(sessionId, this.userName?.toLowerCase());
const res = await getSipAccountInfo(sessionId, this.userName?.toLowerCase());
this.handleApiResponse(res, this.handleSipAccountInfo);
registerEventProcessor(this.eventListenerUrl, sessionId);
maintainHeartbeat(this.sessionId, window?.listenerName || '', 0);
}
private async handleSipAccountInfo(payload: GenericObject): Promise<void> {
private handleSipAccountInfo = async (payload: GenericObject): Promise<void> => {
const response = payload?.data?.response;
this.initializeSipStack({
accountName: response?.accountName,
@@ -290,28 +267,31 @@ class AmeyoAdapter implements IAdapter {
});
this.sipAccountInfo = payload?.data?.response;
console.log('sip account info', this.sipAccountInfo)
await getCampaignId(this.sessionId);
const res = await getCampaignId(this.sessionId);
this.handleApiResponse(res, this.handleCampaignId);
await setAutoStatus(this.sessionId);
}
private async handleCampaignId(payload: GenericObject): Promise<void> {
private handleCampaignId = async (payload: GenericObject): Promise<void> => {
this.campaignId = payload?.data?.response?.campaignInfos?.[0]?.campaignId;
await attachOmniqueService(this.sessionId, this.userName.toLowerCase(), this.campaignId);
const res = await attachOmniqueService(this.sessionId, this.userName.toLowerCase(), this.campaignId);
this.handleApiResponse(res, this.handleOmniQueueService);
}
private handleAgentAvailable(): void {
private handleAgentAvailable = (_: GenericObject): void => {
setAutoStatus(this.sessionId);
}
private handleAgentBreak(): void {
private handleAgentBreak = (_: GenericObject): void => {
setAutoStatus(this.sessionId);
}
private async handleOmniQueueService(): Promise<void> {
await selectCampaign(this.sessionId, this.userName.toLowerCase(), this.campaignId);
private handleOmniQueueService = async (_: GenericObject): Promise<void> => {
const res = await selectCampaign(this.sessionId, this.userName.toLowerCase(), this.campaignId);
this.handleApiResponse(res, this.handleCampaignSelection);
}
private async handleCampaignSelection(): Promise<void> {
private handleCampaignSelection = async (_: GenericObject): Promise<void> => {
await autoSelectExtension(this.sessionId, this.userName.toLowerCase());
this.callbacks.onAdapterReady();
this.currentCallState = CALL_STATES.IDLE;
@@ -324,7 +304,7 @@ class AmeyoAdapter implements IAdapter {
window.postMessage({type: 'onAmeyoAvailabiltyChange', data: this.isAgentAvailable,});
}
private handleAgentsForTransfer(payload: GenericObject): void {
private handleAgentsForTransfer = (payload: GenericObject): void => {
this.callbacks.onAgentsForCallTransfer(payload?.data?.response);
}
@@ -372,12 +352,14 @@ class AmeyoAdapter implements IAdapter {
);
}
public setOnBreak(): void {
setAgentOnBreak(this.sessionId);
public async setOnBreak(): Promise<void> {
const res = await setAgentOnBreak(this.sessionId);
this.handleApiResponse(res, this.handleAgentBreak);
}
public setAvailable(): void {
setAgentActive(this.sessionId);
public async setAvailable(): Promise<void> {
const res = await setAgentActive(this.sessionId);
this.handleApiResponse(res, this.handleAgentAvailable);
}
public muteCall(): void {
@@ -396,8 +378,9 @@ class AmeyoAdapter implements IAdapter {
return this.currentCallState;
}
public getAvailableAgentsForCallTransfer(): void {
getAllAgentsForTransferCall(this.sessionId);
public async getAvailableAgentsForCallTransfer(): Promise<void> {
const res = await getAllAgentsForTransferCall(this.sessionId);
this.handleApiResponse(res,this.handleAgentsForTransfer);
}
public transferCallToAgent(data: CallTransferData): void {

View File

@@ -0,0 +1,7 @@
import GenericObject from "./GenericObject";
type GenericFunction =
| ((payload: GenericObject) => void)
| ((payload: GenericObject) => Promise<void>);
export default GenericFunction;

View File

@@ -0,0 +1,21 @@
export type Request = {
url: string;
method: string;
data ?:Record<string, any> | string;
requestKey: string;
requestType ?: RequestType;
headers ?: Record<string, any> | null;
}
export enum RequestType {
JSON = 'JSON',
RAW = 'RAW'
}
export enum METHODS {
GET = "GET",
POST = "POST",
PUT = "PUT",
DELETE = "DELETE",
}

View File

@@ -1,8 +0,0 @@
enum RequestType {
JSON = 'JSON',
RAW = 'RAW'
}
export default RequestType;

View File

@@ -0,0 +1,85 @@
import { METHODS, Request, RequestType } from "../types/Request";
const getFetchResponse = async (
url: string,
method: string,
data: any,
requestType: RequestType,
headers: any
) => {
const fetchOptions = {
method,
headers: {
"Content-Type":
requestType === RequestType.JSON ? "application/json" : "text/plain",
...headers,
},
...(method !== METHODS.GET && { body: data }),
};
try {
const res = await fetch(url, fetchOptions);
if (!res.ok) {
return { error: res };
}
const contentType = res.headers.get("Content-Type") || "";
if (
requestType === RequestType.JSON &&
contentType.includes("application/json")
) {
return await res.json();
} else if (
contentType.includes("text/plain") ||
requestType !== RequestType.JSON
) {
return await res.text();
} else {
throw new Error(`Unsupported Content-Type: ${contentType}`);
}
} catch (err) {
console.error("Response is not a valid JSON or text", err);
return { error: "Failed to parse response" };
}
};
export const getResponse = async ({
url,
method,
requestKey,
requestType = RequestType.JSON,
headers = null,
data = {},
}: Request) => {
const requestPayload =
requestType === RequestType.RAW ? data : JSON.stringify(data);
try {
const response = await getFetchResponse(
url,
method,
requestPayload,
requestType,
headers || {}
);
if (response?.error) {
console.error(response.error);
return {
data: {
requestKey: requestKey,
response: response,
},
};
}
return {
data: {
requestKey: requestKey,
response: response,
},
};
} catch (error) {
console.error("Fetch error:", error);
throw error;
}
};
export default getResponse;

View File

@@ -1,38 +0,0 @@
import RequestType from "../types/RequestType.ts";
enum MessagingType {
GET_RESPONSE_WITHOUT_CORS = 'getResponseWithoutCors',
SET_RESPONSE_WITHOUT_CORS = 'setResponseWithoutCors',
}
type GetResponseWithoutCors = {
url: string;
method: string;
data ?:Record<string, any> | string;
requestKey: string;
requestType ?: RequestType;
headers ?: Record<string, any> | null;
}
export const getResponseWithoutCors = ({
url,
method,
data = {},
requestKey,
requestType = RequestType.JSON,
headers = null}: GetResponseWithoutCors) => {
window.postMessage({
type: MessagingType.GET_RESPONSE_WITHOUT_CORS,
data: {
url,
method,
data,
requestKey,
requestType,
headers
}
});
};
export default getResponseWithoutCors;