NTP-26125 | removed unused code
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-nocheck
|
||||
|
||||
|
||||
import messagingType from "../../../types/MessagingType.ts";
|
||||
import {parse} from "path";
|
||||
import {extractAndProcessEvents} from "../../callStateManager.ts";
|
||||
|
||||
export enum MessagingType {
|
||||
@@ -41,158 +38,6 @@ const monitorPushTime = 60 * 1000;
|
||||
//call the above function to create the XMLHttpRequest object
|
||||
let http = createRequestObject();
|
||||
|
||||
enum pushResponseTypes {
|
||||
UserCallModelUpdatedPush = 'UserCallModelUpdatedPush',
|
||||
CustomerCallMemberUpdatedPush = 'CustomerCallMemberUpdatedPush',
|
||||
UserCallMemberUpdatedPush = 'UserCallMemberUpdatedPush',
|
||||
CRMCreateNotifyPush = 'CRMCreateNotifyPush',
|
||||
UserCCRuntimeUpdatedPush = 'UserCCRuntimeUpdatedPush',
|
||||
UserLoggedOffPush = 'UserLoggedOffPush'
|
||||
}
|
||||
|
||||
export function parseQuerystring(url: string): Record<string, any> {
|
||||
const foo = url?.split('?')?.[1]?.split('&') || [];
|
||||
const dict = {};
|
||||
let elem = [];
|
||||
for (let i = foo.length - 1; i >= 0; i--) {
|
||||
elem = foo[i].split('=');
|
||||
dict[elem[0]] = elem[1];
|
||||
}
|
||||
return dict || {};
|
||||
}
|
||||
|
||||
function extractUserCallModelUpdatedPush(rawResponse) {
|
||||
const parts = rawResponse
|
||||
.replaceAll(`Content-type: application/json ; charset: utf-8\r\n\r\n`, '')
|
||||
.split("--DON'T_PANIC!_more_will_follow\r\n")
|
||||
.map((part) => {
|
||||
try {
|
||||
return JSON.parse(part.trim());
|
||||
} catch {
|
||||
return null; // Ignore parsing errors
|
||||
}
|
||||
})
|
||||
.filter(Boolean); // Remove null values
|
||||
|
||||
// Prioritize CRMCreateNotifyPush and keep the rest
|
||||
const sortedParts = [
|
||||
...parts.filter(part => part?.pushType === pushResponseTypes.CRMCreateNotifyPush),
|
||||
...parts.filter(part => part?.pushType !== pushResponseTypes.CRMCreateNotifyPush),
|
||||
];
|
||||
|
||||
sortedParts.forEach(jsonData => {
|
||||
if (jsonData?.pushType === pushResponseTypes.CRMCreateNotifyPush) {
|
||||
const crtObjectId = jsonData?.data?.crtObjectId;
|
||||
const parsedObject = parseQuerystring(jsonData?.data?.crmURL);
|
||||
let userCRTObjectId = parsedObject?.userCrtObjectId?.replace('%40', '@');
|
||||
userCRTObjectId = userCRTObjectId.replace('%40', '@');
|
||||
const phoneNumber = parsedObject?.phone;
|
||||
const lan = parsedObject?.loanaccountnumber;
|
||||
const callId = parsedObject?.unique_id || parsedObject?.callid;
|
||||
localStorage.setItem(
|
||||
'revEngCustomerInfo',
|
||||
JSON.stringify({phoneNumber, lan, crtObjectId, userCRTObjectId, callId})
|
||||
);
|
||||
}
|
||||
if (jsonData?.pushType === pushResponseTypes.UserCallModelUpdatedPush) {
|
||||
sendCallStatusMessage(jsonData);
|
||||
}
|
||||
if (jsonData?.pushType === pushResponseTypes.CustomerCallMemberUpdatedPush) {
|
||||
const payload = jsonData?.data;
|
||||
// handle for transfer call
|
||||
if (payload?.isDisposing &&
|
||||
payload?.status === 'hungup')
|
||||
sendCallStatusMessage(jsonData);
|
||||
}
|
||||
if (jsonData?.pushType === pushResponseTypes.UserCallMemberUpdatedPush) {
|
||||
const payload = jsonData?.data;
|
||||
const validStatuses = ["ringing", "connected", "hungup"];
|
||||
// handle for transfer call
|
||||
if (payload?.associationType === 'transfer.association' && validStatuses.includes(payload?.status)) {
|
||||
window.postMessage({
|
||||
type: MessagingType.ON_AMEYO_CALL_TRANSFER,
|
||||
data: payload
|
||||
})
|
||||
}
|
||||
}
|
||||
if (jsonData?.pushType === pushResponseTypes.UserCCRuntimeUpdatedPush) {
|
||||
const payload = jsonData?.data;
|
||||
//handle ameyo erroronous condition
|
||||
if (payload?.isOnBreak) {
|
||||
window.postMessage({
|
||||
type: MessagingType.ON_AMEYO_AGENT_ON_BREAK,
|
||||
data: {
|
||||
reason: payload,
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (jsonData?.pushType == pushResponseTypes.UserLoggedOffPush) {
|
||||
const payload = jsonData?.data;
|
||||
window.postMessage({
|
||||
type: MessagingType.ON_AMEYO_FORCED_LOGOUT,
|
||||
data: {}
|
||||
})
|
||||
}
|
||||
} )
|
||||
}
|
||||
|
||||
const sendCallStatusMessage = (res) => {
|
||||
try {
|
||||
const status = res?.data?.status;
|
||||
|
||||
const getCustomerInfo = () =>
|
||||
JSON.parse(localStorage.getItem('revEngCustomerInfo') || '{}');
|
||||
|
||||
const sendConnectedMessage = (retryCount = 3) => {
|
||||
/* The callId is received after the call is connected.
|
||||
* Since callId is essential and cannot be null,
|
||||
* this retry mechanism ensures we wait until it becomes available. */
|
||||
const data = getCustomerInfo();
|
||||
if (data?.callId || data?.phoneNumber) {
|
||||
const message = {
|
||||
type: MessagingType.ON_AMEYO_CALL_ACCEPTED,
|
||||
data,
|
||||
};
|
||||
window.postMessage(message);
|
||||
} else if (retryCount > 0) {
|
||||
setTimeout(() => sendConnectedMessage(retryCount - 1), 100);
|
||||
} else {
|
||||
console.warn('Unable to send ON_AMEYO_CALL_ACCEPTED: callId not found.');
|
||||
}
|
||||
};
|
||||
|
||||
switch (status) {
|
||||
case 'ringing': {
|
||||
const data = getCustomerInfo();
|
||||
const message = {
|
||||
type: MessagingType.ON_AMEYO_CALL_INCOMING,
|
||||
data,
|
||||
};
|
||||
window.postMessage(message);
|
||||
break;
|
||||
}
|
||||
case 'connected': {
|
||||
sendConnectedMessage();
|
||||
break;
|
||||
}
|
||||
case 'hungup': {
|
||||
const data = getCustomerInfo();
|
||||
const message = {
|
||||
type: MessagingType.ON_AMEYO_CALL_DISCONNECTED,
|
||||
data,
|
||||
};
|
||||
window.postMessage(message);
|
||||
localStorage.removeItem('revEngCustomerInfo');
|
||||
break;
|
||||
}
|
||||
default:
|
||||
console.warn(`Unhandled call status: ${status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in sendCallStatusMessage:', error);
|
||||
}
|
||||
};
|
||||
|
||||
function createRequestObject() {
|
||||
let tmpXmlHttpObject;
|
||||
@@ -263,9 +108,7 @@ function processResponse() {
|
||||
}
|
||||
|
||||
function processPush(pushResponse) {
|
||||
// extractUserCallModelUpdatedPush(pushResponse);
|
||||
extractAndProcessEvents(pushResponse);
|
||||
//ajaxRequest.handleIntermediateResponse(pushResponse);
|
||||
}
|
||||
|
||||
function makePostRequest(url, session) {
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import {MessagingType, parseQuerystring} from "./assets/js/ajaxClient.ts";
|
||||
|
||||
import {MessagingType} from "./assets/js/ajaxClient.ts";
|
||||
import {CallStatus, PushType, CallState} from "./types.ts";
|
||||
|
||||
interface EventData {
|
||||
pushType: PushType;
|
||||
data: any; // We can make this more specific if needed
|
||||
}
|
||||
import {parseQuerystring} from "@universal-call-sdk/common/lib/utils/parsingUtils.ts";
|
||||
|
||||
class CallStateManager {
|
||||
private state: CallState = {
|
||||
@@ -213,14 +208,7 @@ export function extractAndProcessEvents(rawResponse: any) {
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
// Process events in order, prioritizing CRMCreateNotifyPush
|
||||
const sortedParts: EventData[] = [
|
||||
...parts.filter((part: EventData | null): part is EventData =>
|
||||
part?.pushType === PushType.CRMCreateNotify),
|
||||
...parts.filter((part: EventData | null): part is EventData =>
|
||||
part?.pushType !== PushType.CRMCreateNotify)
|
||||
];
|
||||
sortedParts.forEach(event => {
|
||||
parts.forEach(event => {
|
||||
try {
|
||||
callStateManager.handleEvent(event);
|
||||
} catch (error) {
|
||||
|
||||
10
packages/common/lib/utils/parsingUtils.ts
Normal file
10
packages/common/lib/utils/parsingUtils.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export function parseQuerystring(url: string): Record<string, any> {
|
||||
const foo = url?.split('?')?.[1]?.split('&') || [];
|
||||
const dict = {};
|
||||
let elem = [];
|
||||
for (let i = foo.length - 1; i >= 0; i--) {
|
||||
elem = foo[i].split('=');
|
||||
dict[elem[0]] = elem[1];
|
||||
}
|
||||
return dict || {};
|
||||
}
|
||||
Reference in New Issue
Block a user