Merge pull request #35 from navi-commons/NTP-27557-ext-deprec
NTP-27557 | Ameyo Extension Deprecation
This commit is contained in:
@@ -3,6 +3,22 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## 2.0.3 (2025-02-19)
|
||||
|
||||
**Note:** Version bump only for package @universal-call-sdk/adapter-ameyo
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 2.0.2 (2025-02-05)
|
||||
|
||||
**Note:** Version bump only for package @universal-call-sdk/adapter-ameyo
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 1.3.3 (2025-02-06)
|
||||
|
||||
**Note:** Version bump only for package @universal-call-sdk/adapter-ameyo
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import getResponseWithoutCors from "@universal-call-sdk/common/lib/utils/getResponseWithoutCors.ts";
|
||||
import apiHelper from "@universal-call-sdk/common/lib/utils/apiHelper.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 apiHelper({
|
||||
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(() => apiHelper({
|
||||
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 apiHelper({
|
||||
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 apiHelper({
|
||||
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 apiHelper({
|
||||
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 apiHelper({
|
||||
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 apiHelper({
|
||||
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 apiHelper({
|
||||
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 apiHelper({
|
||||
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 apiHelper({
|
||||
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 apiHelper({
|
||||
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 apiHelper({
|
||||
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 apiHelper({
|
||||
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 apiHelper({
|
||||
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 apiHelper({
|
||||
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/transferToUserInDifferentCampaign`,
|
||||
method: 'POST',
|
||||
requestKey: RequestKeys.TRANSFER_CALL_TO_AGENT,
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
AmeyoInitializationOptions,
|
||||
CALL_STATES, CallbackFunctions,
|
||||
CallTransferData,
|
||||
RequestKeys,
|
||||
ErrorType,
|
||||
SipAccountInfo,
|
||||
StateType
|
||||
} from "./types";
|
||||
@@ -84,8 +84,6 @@ class AmeyoAdapter implements IAdapter {
|
||||
},
|
||||
onLoginFailed: () => {
|
||||
},
|
||||
onAgentsForCallTransfer: () => {
|
||||
},
|
||||
onCallTransferStatus: () => {
|
||||
}
|
||||
};
|
||||
@@ -138,24 +136,38 @@ class AmeyoAdapter implements IAdapter {
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error initializing SIP stack:', error);
|
||||
this.handleError('SIP_INIT_ERROR', error);
|
||||
this.handleError(ErrorType.SIP_INIT_ERROR, error);
|
||||
}
|
||||
};
|
||||
|
||||
private initializeAmeyo = (): void => {
|
||||
loginInAmeyo(this.userName.toLowerCase(), this.password);
|
||||
private initializeAmeyo = async (): Promise<void> => {
|
||||
try {
|
||||
const loginResponse: GenericObject = await loginInAmeyo(this.userName.toLowerCase(), this.password);
|
||||
if (!loginResponse) {
|
||||
console.error("Invalid username or password");
|
||||
return;
|
||||
}
|
||||
this.trackApiMetrics(loginResponse);
|
||||
const sipInfoResponse: GenericObject | undefined = await this.handleLoginResponse(loginResponse);
|
||||
if (!sipInfoResponse) {
|
||||
console.error("Login failed: Invalid response");
|
||||
return;
|
||||
}
|
||||
const campaignIdResponse: GenericObject = await this.handleSipAccountInfo(sipInfoResponse);
|
||||
await this.handleCampaignId(campaignIdResponse);
|
||||
await this.handleOmniQueueService();
|
||||
await this.handleCampaignSelection();
|
||||
} catch (error) {
|
||||
console.error("Error during Ameyo initialization:", error);
|
||||
this.handleError(ErrorType.INITIALIZATION_ERROR, error);
|
||||
}
|
||||
};
|
||||
|
||||
private handleMessage = async ({data}: MessageEvent): Promise<void> => {
|
||||
try {
|
||||
if (this.shouldTrackMetrics(data.type)) {
|
||||
this.trackEventMetrics(data.type);
|
||||
}
|
||||
this.trackEventMetrics(data.type);
|
||||
|
||||
switch (data.type) {
|
||||
case MessagingType.SET_RESPONSE_WITHOUT_CORS:
|
||||
await this.handleCorsBypassResponse(data);
|
||||
break;
|
||||
case MessagingType.ON_AMEYO_CALL_INCOMING:
|
||||
this.handleCallIncoming(data);
|
||||
break;
|
||||
@@ -178,15 +190,10 @@ class AmeyoAdapter implements IAdapter {
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error handling message:', error);
|
||||
this.handleError('MESSAGE_HANDLING_ERROR', error);
|
||||
this.handleError(ErrorType.MESSAGE_HANDLING_ERROR, error);
|
||||
}
|
||||
};
|
||||
|
||||
private shouldTrackMetrics(messageType: string): boolean {
|
||||
return messageType !== MessagingType.SET_RESPONSE_WITHOUT_CORS &&
|
||||
messageType !== MessagingType.GET_RESPONSE_WITHOUT_CORS;
|
||||
}
|
||||
|
||||
private trackEventMetrics(messageType: string): void {
|
||||
this.metricProcessor?.pushCounterMetric({
|
||||
metricName: `ameyo-events-count`,
|
||||
@@ -207,39 +214,8 @@ class AmeyoAdapter implements IAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
private async handleCorsBypassResponse(payload: GenericObject): Promise<void> {
|
||||
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) {
|
||||
if (!payload?.data?.err) {
|
||||
this.metricProcessor?.pushCounterMetric({
|
||||
metricName: 'ameyo-api-call-count',
|
||||
flow: 'api-call-count',
|
||||
@@ -251,9 +227,7 @@ class AmeyoAdapter implements IAdapter {
|
||||
subFlow: payload?.data?.requestKey,
|
||||
value: payload?.data?.time / 1000 || 0
|
||||
});
|
||||
}
|
||||
|
||||
if (payload?.data?.err) {
|
||||
} else {
|
||||
this.metricProcessor?.pushCounterMetric({
|
||||
metricName: 'ameyo-api-err-count',
|
||||
flow: 'api-error-count',
|
||||
@@ -263,10 +237,11 @@ class AmeyoAdapter implements IAdapter {
|
||||
type: 'api-error',
|
||||
err: payload
|
||||
});
|
||||
this.handleError(payload?.data?.requestKey, payload?.data?.err);
|
||||
}
|
||||
}
|
||||
|
||||
private async handleLoginResponse(payload: GenericObject): Promise<void> {
|
||||
private handleLoginResponse = async (payload: GenericObject): Promise<GenericObject | undefined> => {
|
||||
if (payload?.data?.err) {
|
||||
console.log('Login failed:', payload?.data?.err);
|
||||
this.callbacks.onLoginFailed(payload?.err);
|
||||
@@ -275,12 +250,14 @@ 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.trackApiMetrics(res);
|
||||
registerEventProcessor(this.eventListenerUrl, sessionId);
|
||||
maintainHeartbeat(this.sessionId, window?.listenerName || '', 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
private async handleSipAccountInfo(payload: GenericObject): Promise<void> {
|
||||
private handleSipAccountInfo = async (payload: GenericObject): Promise<GenericObject> => {
|
||||
const response = payload?.data?.response;
|
||||
this.initializeSipStack({
|
||||
accountName: response?.accountName,
|
||||
@@ -290,29 +267,34 @@ 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.trackApiMetrics(res);
|
||||
await setAutoStatus(this.sessionId);
|
||||
return res;
|
||||
}
|
||||
|
||||
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.trackApiMetrics(res);
|
||||
}
|
||||
|
||||
private handleAgentAvailable(): void {
|
||||
private handleAgentAvailable = (): void => {
|
||||
setAutoStatus(this.sessionId);
|
||||
}
|
||||
|
||||
private handleAgentBreak(): void {
|
||||
private handleAgentBreak = (): void => {
|
||||
setAutoStatus(this.sessionId);
|
||||
}
|
||||
|
||||
private async handleOmniQueueService(): Promise<void> {
|
||||
await selectCampaign(this.sessionId, this.userName.toLowerCase(), this.campaignId);
|
||||
private handleOmniQueueService = async (): Promise<void> => {
|
||||
const res = await selectCampaign(this.sessionId, this.userName.toLowerCase(), this.campaignId);
|
||||
this.trackApiMetrics(res);
|
||||
}
|
||||
|
||||
private async handleCampaignSelection(): Promise<void> {
|
||||
await autoSelectExtension(this.sessionId, this.userName.toLowerCase());
|
||||
private handleCampaignSelection = async (): Promise<void> => {
|
||||
const res = await autoSelectExtension(this.sessionId, this.userName.toLowerCase());
|
||||
this.trackApiMetrics(res);
|
||||
this.callbacks.onAdapterReady();
|
||||
this.currentCallState = CALL_STATES.IDLE;
|
||||
window.postMessage({type: 'onAmeyoAvailabiltyChange', data: false});
|
||||
@@ -324,10 +306,6 @@ class AmeyoAdapter implements IAdapter {
|
||||
window.postMessage({type: 'onAmeyoAvailabiltyChange', data: this.isAgentAvailable,});
|
||||
}
|
||||
|
||||
private handleAgentsForTransfer(payload: GenericObject): void {
|
||||
this.callbacks.onAgentsForCallTransfer(payload?.data?.response);
|
||||
}
|
||||
|
||||
private handleCallIncoming(data: GenericObject): void {
|
||||
this.callbacks.onCallIncoming(data?.data);
|
||||
this.currentCallState = CALL_STATES.CALL_INCOMING;
|
||||
@@ -371,12 +349,16 @@ class AmeyoAdapter implements IAdapter {
|
||||
);
|
||||
}
|
||||
|
||||
public setOnBreak(): void {
|
||||
setAgentOnBreak(this.sessionId);
|
||||
public async setOnBreak(): Promise<void> {
|
||||
const res = await setAgentOnBreak(this.sessionId);
|
||||
this.trackApiMetrics(res);
|
||||
this.handleAgentBreak();
|
||||
}
|
||||
|
||||
public setAvailable(): void {
|
||||
setAgentActive(this.sessionId);
|
||||
public async setAvailable(): Promise<void> {
|
||||
const res = await setAgentActive(this.sessionId);
|
||||
this.trackApiMetrics(res);
|
||||
this.handleAgentAvailable();
|
||||
}
|
||||
|
||||
public muteCall(): void {
|
||||
@@ -395,8 +377,8 @@ class AmeyoAdapter implements IAdapter {
|
||||
return this.currentCallState;
|
||||
}
|
||||
|
||||
public getAvailableAgentsForCallTransfer(): void {
|
||||
getAllAgentsForTransferCall(this.sessionId);
|
||||
public async getAvailableAgentsForCallTransfer(): Promise<Response> {
|
||||
return getAllAgentsForTransferCall(this.sessionId);
|
||||
}
|
||||
|
||||
public transferCallToAgent(data: CallTransferData): void {
|
||||
@@ -437,11 +419,6 @@ class AmeyoAdapter implements IAdapter {
|
||||
public registerOnLoginFailedListener(callback: () => void): void {
|
||||
this.callbacks.onLoginFailed = callback;
|
||||
}
|
||||
|
||||
public registerOnAgentsForCallTransfer(callback: (data: GenericObject) => void): void {
|
||||
this.callbacks.onAgentsForCallTransfer = callback;
|
||||
}
|
||||
|
||||
public registerOnCallTransferStatus(callback: (data: GenericObject) => void): void {
|
||||
this.callbacks.onCallTransferStatus = callback;
|
||||
}
|
||||
|
||||
@@ -51,13 +51,6 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export enum MessagingType {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
export type SipAccountInfo = {
|
||||
accountName: string,
|
||||
userName: string,
|
||||
@@ -73,7 +66,6 @@ export type CallbackFunctions = {
|
||||
onAgentAvailabilityChange: (isAgentAvailable: boolean, reason: string) => void;
|
||||
onForcedLogout: () => void;
|
||||
onLoginFailed: (err: GenericObject) => void;
|
||||
onAgentsForCallTransfer: (data: GenericObject) => void;
|
||||
onCallTransferStatus: (data: GenericObject) => void;
|
||||
};
|
||||
|
||||
@@ -121,3 +113,9 @@ export interface EventData {
|
||||
pushType: PushType;
|
||||
data: any;
|
||||
}
|
||||
|
||||
export enum ErrorType {
|
||||
SIP_INIT_ERROR = 'SIP_INIT_ERROR',
|
||||
MESSAGE_HANDLING_ERROR = 'MESSAGE_HANDLING_ERROR',
|
||||
INITIALIZATION_ERROR = 'INITIALIZATION_ERROR',
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@universal-call-sdk/adapter-ameyo",
|
||||
"version": "1.3.3",
|
||||
"version": "2.0.3",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -9,7 +9,7 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@universal-call-sdk/common": "^1.3.3",
|
||||
"@universal-call-sdk/common": "^2.0.3",
|
||||
"uuid": "^11.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## 2.0.3 (2025-02-19)
|
||||
|
||||
**Note:** Version bump only for package @universal-call-sdk/common
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 2.0.2 (2025-02-05)
|
||||
|
||||
**Note:** Version bump only for package @universal-call-sdk/common
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 1.3.3 (2025-02-06)
|
||||
|
||||
**Note:** Version bump only for package @universal-call-sdk/common
|
||||
|
||||
@@ -11,7 +11,6 @@ class IAdapter {
|
||||
registerOnAgentAvailabilityChange(callback: (isAgentAvailable: boolean, reason: string) => void) {callback(false, '')}
|
||||
registerOnForcedLogoutListener(callback:()=>void) {callback()}
|
||||
registerOnLoginFailedListener(callback:()=>void) {callback()}
|
||||
registerOnAgentsForCallTransfer(callback: (data : GenericObject) => void) {callback({})}
|
||||
registerOnCallTransferStatus(callback: (data: GenericObject) => void) {callback({})}
|
||||
acceptCall() {}
|
||||
rejectCall() {}
|
||||
@@ -30,7 +29,9 @@ class IAdapter {
|
||||
getAgentAvailability(): boolean {return false}
|
||||
|
||||
getLatestCallState(): CALL_STATES {return CALL_STATES.IDLE}
|
||||
getAvailableAgentsForCallTransfer() {}
|
||||
getAvailableAgentsForCallTransfer(): Promise<any> {
|
||||
return Promise.resolve(new Response());
|
||||
}
|
||||
transferCallToAgent(data: GenericObject) {console.log("transfer call", data)}
|
||||
checkAllPermissions():Promise<boolean> {return Promise.resolve(true)}
|
||||
}
|
||||
|
||||
28
packages/common/lib/types/Request.ts
Normal file
28
packages/common/lib/types/Request.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { RequestKeys } from "@universal-call-sdk/adapter-ameyo/lib/types";
|
||||
|
||||
export type Request = {
|
||||
url: string;
|
||||
method: string;
|
||||
data ?:Record<string, any> | string;
|
||||
requestKey: RequestKeys;
|
||||
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",
|
||||
}
|
||||
|
||||
export enum ContentType {
|
||||
JSON = "application/json",
|
||||
TEXT = "text/plain",
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
enum RequestType {
|
||||
JSON = 'JSON',
|
||||
RAW = 'RAW'
|
||||
}
|
||||
|
||||
|
||||
export default RequestType;
|
||||
|
||||
103
packages/common/lib/utils/apiHelper.ts
Normal file
103
packages/common/lib/utils/apiHelper.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import { RequestKeys } from "@universal-call-sdk/adapter-ameyo/lib/types";
|
||||
import { ContentType, METHODS, Request, RequestType } from "../types/Request";
|
||||
|
||||
const getFetchResponse = async(
|
||||
url: string,
|
||||
method: string,
|
||||
data: any,
|
||||
requestType: RequestType,
|
||||
headers: Record<string, string>
|
||||
): Promise<any> => {
|
||||
const fetchOptions: RequestInit = {
|
||||
method,
|
||||
headers: {
|
||||
"Content-Type":
|
||||
requestType === RequestType.JSON ? ContentType.JSON : ContentType.TEXT,
|
||||
...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 (contentType.includes(ContentType.JSON)) {
|
||||
return await res.json();
|
||||
} else if (contentType.includes(ContentType.TEXT)) {
|
||||
return await res.text();
|
||||
} else {
|
||||
throw new Error(`Unsupported Content-Type: ${contentType}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Fetch error:", err);
|
||||
return {
|
||||
error: err,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const apiHelper = async({
|
||||
url,
|
||||
method,
|
||||
requestKey,
|
||||
requestType = RequestType.JSON,
|
||||
headers = {},
|
||||
data = {},
|
||||
}: Request) => {
|
||||
const requestPayload =
|
||||
requestType === RequestType.RAW ? data : JSON.stringify(data);
|
||||
|
||||
try {
|
||||
if (requestKey === RequestKeys.GET_AGENTS_FOR_CALL_TRANSFER) {
|
||||
return getFetchResponse(
|
||||
url,
|
||||
method,
|
||||
requestPayload,
|
||||
requestType,
|
||||
headers || {}
|
||||
);
|
||||
}
|
||||
|
||||
const response = await getFetchResponse(
|
||||
url,
|
||||
method,
|
||||
requestPayload,
|
||||
requestType,
|
||||
headers || {}
|
||||
);
|
||||
|
||||
if (response?.error) {
|
||||
return {
|
||||
data: {
|
||||
requestKey,
|
||||
err: response,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
data: {
|
||||
requestKey,
|
||||
response,
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Response error:", error);
|
||||
return {
|
||||
data: {
|
||||
requestKey,
|
||||
err: error,
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default apiHelper;
|
||||
@@ -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;
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@universal-call-sdk/common",
|
||||
"version": "1.3.3",
|
||||
"version": "2.0.3",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -3,6 +3,23 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## 2.0.3 (2025-02-19)
|
||||
|
||||
**Note:** Version bump only for package @universal-call-sdk/core
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 2.0.2 (2025-02-05)
|
||||
|
||||
**Note:** Version bump only for package @universal-call-sdk/core
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 1.3.2 (2025-02-04)
|
||||
## 1.3.3 (2025-02-06)
|
||||
|
||||
**Note:** Version bump only for package @universal-call-sdk/core
|
||||
|
||||
@@ -8,4 +8,22 @@ export type StateType = {
|
||||
isCallConnected: boolean,
|
||||
isCallDisconnected: boolean,
|
||||
callStartTime: number,
|
||||
}
|
||||
|
||||
interface Campaign {
|
||||
campaignId: number;
|
||||
campaignName: string;
|
||||
campaignType: string;
|
||||
}
|
||||
export interface Agent {
|
||||
userId: string;
|
||||
userName: string;
|
||||
userType: string;
|
||||
sessionId: string;
|
||||
crtObjectId: string;
|
||||
isOnBreak: boolean;
|
||||
isOnAutoCall: boolean;
|
||||
isPresent: boolean;
|
||||
statusDescription: string;
|
||||
campaignList: Campaign[];
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import {useEffect, useReducer} from 'react';
|
||||
import {GenericObject, StateType} from "./types.ts";
|
||||
import {Agent, GenericObject, StateType} from "./types.ts";
|
||||
import IAdapter from "@universal-call-sdk/common/lib/Interfaces/IAdapter.ts";
|
||||
import MetricsProcessor from "@universal-call-sdk/common/lib/utils/metricsProcessor.ts";
|
||||
import ClickStreamProcessor from "@universal-call-sdk/common/lib/utils/clickStreamProcessor.ts";
|
||||
@@ -93,7 +93,7 @@ function UseCallSdk({AdapterClass, adapterOptions, metricsConfig, clickStreamCon
|
||||
if(adapterOptions) {
|
||||
adapter = new AdapterClass(adapterOptions);
|
||||
}
|
||||
}, []);
|
||||
}, [adapterOptions]);
|
||||
// @ts-expect-error sdfsf
|
||||
const [callState] = useReducer<any>(reducer, initialState,()=> initialState);
|
||||
|
||||
@@ -123,10 +123,6 @@ function UseCallSdk({AdapterClass, adapterOptions, metricsConfig, clickStreamCon
|
||||
adapter?.registerOnForcedLogoutListener(callback);
|
||||
}
|
||||
|
||||
function registerOnAgentsForCallTransfer(callback: (data: GenericObject) => void) {
|
||||
adapter?.registerOnAgentsForCallTransfer(callback);
|
||||
}
|
||||
|
||||
function registerOnCallTransferStatus(callback: (data: GenericObject) => void) {
|
||||
adapter?.registerOnCallTransferStatus(callback);
|
||||
}
|
||||
@@ -189,8 +185,8 @@ function UseCallSdk({AdapterClass, adapterOptions, metricsConfig, clickStreamCon
|
||||
return adapter.getLatestCallState();
|
||||
}
|
||||
|
||||
function getAvailableAgentsForCallTransfer() {
|
||||
adapter.getAvailableAgentsForCallTransfer();
|
||||
function getAvailableAgentsForCallTransfer(): Promise<Agent[]> {
|
||||
return adapter.getAvailableAgentsForCallTransfer();
|
||||
}
|
||||
|
||||
function transferCallToAgent(data: GenericObject) {
|
||||
@@ -208,7 +204,6 @@ function UseCallSdk({AdapterClass, adapterOptions, metricsConfig, clickStreamCon
|
||||
registerOnCallDisconnected,
|
||||
registerOnAgentAvailabilityChange,
|
||||
registerOnForcedLogoutListener,
|
||||
registerOnAgentsForCallTransfer,
|
||||
registerOnCallTransferStatus,
|
||||
registerOnLoginFailedListener,
|
||||
acceptCall,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@universal-call-sdk/core",
|
||||
"version": "1.3.3",
|
||||
"version": "2.0.3",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
Reference in New Issue
Block a user