|
|
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
|
|
selectCampaign,
|
|
|
|
|
setAgentActive, setAgentOnBreak,
|
|
|
|
|
setAutoStatus,
|
|
|
|
|
getCampaignId
|
|
|
|
|
getCampaignId, ameyoDisposeCall
|
|
|
|
|
} from "./api.ts";
|
|
|
|
|
import {
|
|
|
|
|
acceptSipCall,
|
|
|
|
|
@@ -28,9 +28,9 @@ class AmeyoAdapter implements IAdapter {
|
|
|
|
|
onCallConnected: (data: StateType) => void;
|
|
|
|
|
onCallDisconnected: (data: StateType) => void;
|
|
|
|
|
onCallIncoming: (data: StateType) => void,
|
|
|
|
|
onAdapterReady: ()=> void,
|
|
|
|
|
onAdapterReady: () => void,
|
|
|
|
|
onAgentAvailabilityChange: (isAgentAvailable: boolean) => void
|
|
|
|
|
onForcedLogout: ()=>void
|
|
|
|
|
onForcedLogout: () => void
|
|
|
|
|
};
|
|
|
|
|
private eventListenerUrl: string;
|
|
|
|
|
private baseUrl: string;
|
|
|
|
|
@@ -42,7 +42,7 @@ class AmeyoAdapter implements IAdapter {
|
|
|
|
|
private sipAccountInfo: GenericObject;
|
|
|
|
|
private isAgentAvailable: boolean;
|
|
|
|
|
|
|
|
|
|
constructor(options : AmeyoInitializationOptions) {
|
|
|
|
|
constructor(options: AmeyoInitializationOptions) {
|
|
|
|
|
console.log('AmeyoAdapter constructor');
|
|
|
|
|
const script = document.createElement('script');
|
|
|
|
|
script.src = 'https://public-assets.np.navi-gi.in/jarvis/sip5ml.js'; // Assuming it's placed in the public folder
|
|
|
|
|
@@ -51,24 +51,31 @@ class AmeyoAdapter implements IAdapter {
|
|
|
|
|
this.baseUrl = options.baseUrl;
|
|
|
|
|
this.eventListenerUrl = options.eventListenerUrl;
|
|
|
|
|
this.callbacks = {
|
|
|
|
|
onCallIncoming: ()=> {},
|
|
|
|
|
onCallConnected: ()=> {},
|
|
|
|
|
onCallDisconnected: ()=> {},
|
|
|
|
|
onAdapterReady: ()=> {},
|
|
|
|
|
onAgentAvailabilityChange: ()=> {},
|
|
|
|
|
onForcedLogout: ()=> {}
|
|
|
|
|
onCallIncoming: () => {
|
|
|
|
|
},
|
|
|
|
|
onCallConnected: () => {
|
|
|
|
|
},
|
|
|
|
|
onCallDisconnected: () => {
|
|
|
|
|
},
|
|
|
|
|
onAdapterReady: () => {
|
|
|
|
|
},
|
|
|
|
|
onAgentAvailabilityChange: () => {
|
|
|
|
|
},
|
|
|
|
|
onForcedLogout: () => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
this.sessionId = '';
|
|
|
|
|
this.userName = options.userName;
|
|
|
|
|
this.password = options.password;
|
|
|
|
|
this.campaignId = '';
|
|
|
|
|
this.sipAccountInfo = {};
|
|
|
|
|
this.currentCallMetadata= {};
|
|
|
|
|
this.isAgentAvailable= false;
|
|
|
|
|
this.currentCallMetadata = {};
|
|
|
|
|
this.isAgentAvailable = false;
|
|
|
|
|
window.BASE_AMEYO_URL = this.baseUrl;
|
|
|
|
|
window.AMEYO_LOGIN_URL = options.loginUrl
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init() {
|
|
|
|
|
console.log('initializing ameyo adapter');
|
|
|
|
|
window.addEventListener('message', this._registerMessageListener);
|
|
|
|
|
@@ -77,7 +84,7 @@ class AmeyoAdapter implements IAdapter {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_initializeSipStack = ({accountName, userName, domain, password}: SipAccountInfo) => {
|
|
|
|
|
_initializeSipStack = ({accountName, userName, domain, password}: SipAccountInfo) => {
|
|
|
|
|
console.log('initializing sip stack');
|
|
|
|
|
const domainOnly = domain.split(':')[0];
|
|
|
|
|
const port = domain.split(':')[1];
|
|
|
|
|
@@ -89,7 +96,7 @@ class AmeyoAdapter implements IAdapter {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_initializeAmeyo = () => {
|
|
|
|
|
loginInAmeyo(this.userName?.toLowerCase(), this.password);
|
|
|
|
|
loginInAmeyo(this.userName?.toLowerCase(), this.password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_onListenForCorsBypassResponse = (payload: GenericObject) => {
|
|
|
|
|
@@ -104,7 +111,7 @@ class AmeyoAdapter implements IAdapter {
|
|
|
|
|
if (payload?.data?.requestKey === RequestKeys.AMEYO_HEARTBEAT) {
|
|
|
|
|
console.log('heartbeat response', payload?.data?.response);
|
|
|
|
|
}
|
|
|
|
|
if(payload?.data?.requestKey === RequestKeys.SIP_ACCOUNT_INFO) {
|
|
|
|
|
if (payload?.data?.requestKey === RequestKeys.SIP_ACCOUNT_INFO) {
|
|
|
|
|
console.log('sip account info', payload?.data?.response);
|
|
|
|
|
const response = payload?.data?.response;
|
|
|
|
|
this._initializeSipStack({
|
|
|
|
|
@@ -118,74 +125,77 @@ class AmeyoAdapter implements IAdapter {
|
|
|
|
|
getCampaignId(this.sessionId);
|
|
|
|
|
setAutoStatus(this.sessionId);
|
|
|
|
|
}
|
|
|
|
|
if(payload?.data?.requestKey === RequestKeys.GET_CAMPAIGN_ID) {
|
|
|
|
|
if (payload?.data?.requestKey === RequestKeys.GET_CAMPAIGN_ID) {
|
|
|
|
|
this.campaignId = payload?.data?.response?.campaignInfos?.[0]?.campaignId;
|
|
|
|
|
attachOmniqueService(this.sessionId, this.userName.toLowerCase(), this.campaignId);
|
|
|
|
|
}
|
|
|
|
|
if(payload?.data?.requestKey === RequestKeys.AMEYO_AVAILABLE) {
|
|
|
|
|
setAutoStatus(this.sessionId);
|
|
|
|
|
this.isAgentAvailable = true;
|
|
|
|
|
window.postMessage({ type: 'onAmeyoAvailabiltyChange', data: true });
|
|
|
|
|
if (payload?.data?.requestKey === RequestKeys.AMEYO_AVAILABLE) {
|
|
|
|
|
setAutoStatus(this.sessionId);
|
|
|
|
|
this.isAgentAvailable = true;
|
|
|
|
|
window.postMessage({type: 'onAmeyoAvailabiltyChange', data: true});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (payload?.data?.requestKey === RequestKeys.OMNIQUEUE_SERVICE) {
|
|
|
|
|
selectCampaign(this.sessionId, this.userName.toLowerCase(), this.campaignId);
|
|
|
|
|
}
|
|
|
|
|
if(payload?.data?.requestKey === RequestKeys.SELECT_CAMPAIGN) {
|
|
|
|
|
if (payload?.data?.requestKey === RequestKeys.SELECT_CAMPAIGN) {
|
|
|
|
|
console.log('campaign selected', payload?.data?.response);
|
|
|
|
|
autoSelectExtension(this.sessionId, this.userName.toLowerCase());
|
|
|
|
|
this.callbacks.onAdapterReady();
|
|
|
|
|
this.callbacks.onAgentAvailabilityChange(true);
|
|
|
|
|
window.postMessage({ type: 'onAmeyoAvailabiltyChange', data: false }, );
|
|
|
|
|
window.postMessage({type: 'onAmeyoAvailabiltyChange', data: false},);
|
|
|
|
|
}
|
|
|
|
|
if(payload?.data?.requestKey === RequestKeys.AMEYO_ON_BREAK) {
|
|
|
|
|
if (payload?.data?.requestKey === RequestKeys.AMEYO_ON_BREAK) {
|
|
|
|
|
setAutoStatus(this.sessionId);
|
|
|
|
|
this.isAgentAvailable = false;
|
|
|
|
|
this.callbacks.onAgentAvailabilityChange(false);
|
|
|
|
|
window.postMessage({ type: 'onAmeyoAvailabiltyChange', data: false }, );
|
|
|
|
|
window.postMessage({type: 'onAmeyoAvailabiltyChange', data: false},);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_registerMessageListener = async ({ data }: GenericObject) => {
|
|
|
|
|
_registerMessageListener = async ({data}: GenericObject) => {
|
|
|
|
|
if (data?.type === MessagingType.SET_RESPONSE_WITHOUT_CORS) {
|
|
|
|
|
this._onListenForCorsBypassResponse(data);
|
|
|
|
|
}
|
|
|
|
|
if(data?.type === MessagingType.ON_AMEYO_CALL_INCOMING) {
|
|
|
|
|
if (data?.type === MessagingType.ON_AMEYO_CALL_INCOMING) {
|
|
|
|
|
this.callbacks.onCallIncoming(data?.data);
|
|
|
|
|
this.currentCallMetadata = {...this.currentCallMetadata, ...data?.data}
|
|
|
|
|
}
|
|
|
|
|
if(data?.type === MessagingType.ON_AMEYO_CALL_ACCEPTED) {
|
|
|
|
|
if (data?.type === MessagingType.ON_AMEYO_CALL_ACCEPTED) {
|
|
|
|
|
this.callbacks.onCallConnected(data?.data);
|
|
|
|
|
this.currentCallMetadata = {...this.currentCallMetadata, ...data?.data}
|
|
|
|
|
}
|
|
|
|
|
if(data?.type === MessagingType.ON_AMEYO_CALL_DISCONNECTED) {
|
|
|
|
|
if (data?.type === MessagingType.ON_AMEYO_CALL_DISCONNECTED) {
|
|
|
|
|
this.callbacks.onCallDisconnected(data?.data);
|
|
|
|
|
ameyoHangupUser(this.sessionId, this.currentCallMetadata?.crtObjectId);
|
|
|
|
|
this.currentCallMetadata = {...this.currentCallMetadata, ...data?.data}
|
|
|
|
|
}
|
|
|
|
|
if(data?.type === MessagingType.ON_AMEYO_AGENT_ON_BREAK) {
|
|
|
|
|
if (data?.type === MessagingType.ON_AMEYO_AGENT_ON_BREAK) {
|
|
|
|
|
console.log('on availability changedd')
|
|
|
|
|
this.isAgentAvailable = false;
|
|
|
|
|
this.callbacks.onAgentAvailabilityChange(false);
|
|
|
|
|
}
|
|
|
|
|
if(data?.type === MessagingType.ON_AMEYO_FORCED_LOGOUT){
|
|
|
|
|
if (data?.type === MessagingType.ON_AMEYO_FORCED_LOGOUT) {
|
|
|
|
|
this.callbacks.onForcedLogout()
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
registerOnCallIncoming(callback: (callState: StateType)=> void) {
|
|
|
|
|
|
|
|
|
|
registerOnCallIncoming(callback: (callState: StateType) => void) {
|
|
|
|
|
console.log('registerOnCallIncoming');
|
|
|
|
|
this.callbacks.onCallIncoming = callback;
|
|
|
|
|
}
|
|
|
|
|
registerOnCallConnected(callback: (callState: StateType)=> void) {
|
|
|
|
|
|
|
|
|
|
registerOnCallConnected(callback: (callState: StateType) => void) {
|
|
|
|
|
console.log('registerOnCallConnected');
|
|
|
|
|
this.callbacks.onCallConnected = callback;
|
|
|
|
|
}
|
|
|
|
|
registerOnCallDisconnected(callback: (callState: StateType)=> void) {
|
|
|
|
|
|
|
|
|
|
registerOnCallDisconnected(callback: (callState: StateType) => void) {
|
|
|
|
|
console.log('registerOnCallDisconnected');
|
|
|
|
|
this.callbacks.onCallDisconnected = callback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
registerOnAdapterReady(callback: ()=> void) {
|
|
|
|
|
registerOnAdapterReady(callback: () => void) {
|
|
|
|
|
console.log('registerOnAdapterReady');
|
|
|
|
|
this.callbacks.onAdapterReady = callback;
|
|
|
|
|
}
|
|
|
|
|
@@ -204,28 +214,36 @@ class AmeyoAdapter implements IAdapter {
|
|
|
|
|
console.log('acceptCall');
|
|
|
|
|
acceptSipCall();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rejectCall() {
|
|
|
|
|
console.log('rejectCall');
|
|
|
|
|
sipHangUp();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
disposeCall() {
|
|
|
|
|
console.log('disposeCall');
|
|
|
|
|
ameyoDisposeCall(this.sessionId, this.campaignId, this.currentCallMetadata?.crtObjectId, this.currentCallMetadata?.userCRTObjectId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setOnBreak() {
|
|
|
|
|
console.log('setAgentOnBreakk');
|
|
|
|
|
setAgentOnBreak(this.sessionId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setAvailable() {
|
|
|
|
|
setAgentActive(this.sessionId);
|
|
|
|
|
setAgentActive(this.sessionId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
muteCall() {
|
|
|
|
|
console.log('muteCall');
|
|
|
|
|
sipMuteCall();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unmuteCall() {
|
|
|
|
|
console.log('unmuteCall');
|
|
|
|
|
sipUnmuteCall();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getAgentAvailability() {
|
|
|
|
|
return this.isAgentAvailable;
|
|
|
|
|
}
|
|
|
|
|
|