Files
call-sdk/packages/adapter-ameyo/lib/api.ts
2025-01-22 14:44:40 +05:30

249 lines
8.8 KiB
TypeScript

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/Request.ts";
import {v4 as uuid} from 'uuid';
export const loginInAmeyo = (userId: string, password: string) => {
console.log('loginInAmeyo', userId, password);
if(!userId || !password) {
return
}
return apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/userLogin/login`,
method: 'POST',
requestKey: RequestKeys.AMEYO_LOGIN,
requestType: RequestType.JSON,
data: {
domain: window.AMEYO_LOGIN_URL,
userId: userId,
token: password,
userDetails: null,
clientType: null,
clientVersion: null,
forceLogin: true,
properties: null,
captchaAuthenticationInputBean: null,
requestId: null, // This has to be null
}
});
};
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(() => apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyo40/service`,
method: 'POST',
requestKey: RequestKeys.AMEYO_HEARTBEAT,
requestType: RequestType.RAW,
data: HEART_BEAT_REQUEST_TEXT,
headers: {
'Content-Type': 'text/x-gwt-rpc; charset=UTF-8',
'X-GWT-Permutation': '11B39EE372921423BCA4DF11986A500D'
}
}), 20000); //20s
};
export const setAgentOnBreak = (sessionId: string) => {
return apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/cc/userBreak`,
method: 'POST',
requestKey: RequestKeys.AMEYO_ON_BREAK,
requestType: RequestType.JSON,
headers: {
sessionId: sessionId
},
data: {
breakReason: 'Lunch',
breakSubCause: null,
sessionId: sessionId
}
});
};
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 apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyoomniqueue/service`,
method: 'POST',
requestKey: RequestKeys.OMNIQUEUE_SERVICE,
requestType: RequestType.RAW,
data: OMNIQUEUE_TEXT,
headers: {
'Content-Type': 'text/x-gwt-rpc; charset=UTF-8',
'X-GWT-Permutation': '11B39EE372921423BCA4DF11986A500D'
}
});
};
export const setAgentActive = (sessionId: string) => {
return apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/cc/userReady`,
method: 'POST',
requestKey: RequestKeys.AMEYO_AVAILABLE,
requestType: RequestType.JSON,
headers: {
sessionId: sessionId
},
data: {
sessionId: sessionId,
status: 'Available'
}
});
};
export const getSipAccountInfo = (sessionId: string, userId: string) => {
return apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/sipAccountInfos/getSipAccountInfo?info=false`,
method: 'GET',
requestKey: RequestKeys.SIP_ACCOUNT_INFO,
requestType: RequestType.JSON,
data: {},
headers: {
sessionId: sessionId,
userId: userId
}
});
};
export const autoSelectExtension = (sessionId: string, userId: string) => {
return apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/autoSelectExtension`,
method: 'POST',
requestKey: RequestKeys.AUTO_SELECT_EXTENSION,
requestType: RequestType.JSON,
data: {
sessionId: sessionId,
params: {'user.id': userId}
},
headers: {
sessionId: sessionId
}
});
};
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 apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyoomniqueue/service`,
method: 'POST',
requestKey: RequestKeys.SELECT_CAMPAIGN,
requestType: RequestType.RAW,
data: SELECT_CAMPAIGN_TEXT,
headers: {
'Content-Type': 'text/x-gwt-rpc; charset=UTF-8',
'X-GWT-Permutation': '11B39EE372921423BCA4DF11986A500D'
}
});
};
export const setAutoStatus = (sessionId: string) => {
return apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/cc/setAutoStatusForUser`,
method: 'POST',
requestKey: RequestKeys.SET_AUTO_STATUS,
requestType: RequestType.JSON,
data: {userSessionId: sessionId, status: true},
headers: {
sessionId: sessionId
}
});
};
export const ameyoHangupUser = (sessionId: string, userCRTObjectId: string) => {
return apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/hangupUser`,
method: 'POST',
requestKey: RequestKeys.HANGUP_USER,
requestType: RequestType.JSON,
data: {sessionId, userCRTObjectId},
headers: {
sessionId
}
});
};
export const ameyoDisposeCall = (sessionId: string, campaignId: string, crtObjectId: string, userCRTObjectId: string) => {
return apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/disposeCall`,
method: 'POST',
requestKey: RequestKeys.DISPOSE_CALL,
requestType: RequestType.JSON,
data: {
sessionId,
campaignId,
crtObjectId,
userCRTObjectId,
dispositionCodeId: 21,
requestId: uuid(),
dispositionParams: {},
notes: ""
},
headers: {
sessionId
}
});
};
export const getCampaignId = (sessionId: string) => {
return apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/sessionData/getAllSessionData`,
method: 'GET',
requestKey: RequestKeys.GET_CAMPAIGN_ID,
requestType: RequestType.JSON,
data : {},
headers: {
sessionId
}
});
}
export const getAllAgentsForTransferCall = (sessionId: string) => {
return apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/getAllUserCampaignVoicePresencesByContactCenterId`,
method: 'GET',
requestKey: RequestKeys.GET_AGENTS_FOR_CALL_TRANSFER,
requestType: RequestType.JSON,
data: {},
headers: {
sessionId
}
});
}
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 apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyo40/service`,
method: 'POST',
requestKey: RequestKeys.LOGOUT_FROM_AMEYO,
requestType: RequestType.RAW,
data: LOGOUT_PAYLOAD_TEXT,
headers: {
'Content-Type': 'text/x-gwt-rpc; charset=UTF-8',
'X-GWT-Permutation': '11B39EE372921423BCA4DF11986A500D'
}
});
};
export const transferCallToAgent = (data: CallTransferData, sessionId: string, crtObjectId: string, userCRTObjectId: string, campaignId: string) => {
return apiHelper({
url: `${window.BASE_AMEYO_URL}/ameyorestapi/voice/transferToUserInDifferentCampaign`,
method: 'POST',
requestKey: RequestKeys.TRANSFER_CALL_TO_AGENT,
requestType: RequestType.JSON,
data: {
sourceCampaignId: campaignId,
sourceCRTObjectId: userCRTObjectId,
targetCampaignId: data?.campaignId,
targetCRTObjectId: data?.targetCRTObjectId,
transferredCRTObjectIds: [crtObjectId],
requestId: uuid()
},
headers: {
sessionId
}
});
}