Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Agent-Req-From-Agentx' into SetA…
Browse files Browse the repository at this point in the history
…gentStatus
  • Loading branch information
rsarika committed Nov 11, 2024
2 parents b3895ac + 010d4d9 commit 35b6e15
Show file tree
Hide file tree
Showing 29 changed files with 593 additions and 1,003 deletions.
30 changes: 28 additions & 2 deletions docs/samples/contact-center/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const dialNumber = document.querySelector('#dialNumber');
const registerStatus = document.querySelector('#ws-connection-status');
const idleCodesDropdown = document.querySelector('#idleCodesDropdown')
const setAgentStatusButton = document.querySelector('#setAgentStatus');
const logoutAgentElm = document.querySelector('#logoutAgent');

// Store and Grab `access-token` from sessionStorage
if (sessionStorage.getItem('date') > new Date().getTime()) {
Expand Down Expand Up @@ -103,7 +104,7 @@ function initWebex(e) {
console.log('Authentication#initWebex() :: Webex Ready');

authStatusElm.innerText = 'Saved access token!';
registerStatus.innerHTML = 'Not Registered';
registerStatus.innerHTML = 'Not Subscribed';
registerBtn.disabled = false;
});

Expand All @@ -115,7 +116,7 @@ credentialsFormElm.addEventListener('submit', initWebex);

function register() {
webex.cc.register(true).then((agentProfile) => {
registerStatus.innerHTML = 'Registered';
registerStatus.innerHTML = 'Subscribed';
console.log('Event subscription successful: ', agentProfile);
teamsDropdown.innerHTML = ''; // Clear previously selected option on teamsDropdown
const listTeams = agentProfile.teams;
Expand Down Expand Up @@ -171,6 +172,17 @@ async function handleAgentLogin(e) {
function doAgentLogin() {
webex.cc.stationLogin({teamId: teamsDropdown.value, loginOption: agentDeviceType, dialNumber: dialNumber.value}).then((response) => {
console.log('Agent Logged in successfully', response);
logoutAgentElm.classList.remove('hidden');
// Re-Login Agent after 5 seconds for testing purpose
setTimeout(async () => {
try {
const response = await webex.cc.stationReLogin();

console.log('Agent Re-Login successful', response);
} catch (error) {
console.log('Agent Re-Login failed', error);
}
}, 5000);
}
).catch((error) => {
console.error('Agent Login failed', error);
Expand All @@ -193,6 +205,20 @@ function setAgentStatus() {
});
}


function logoutAgent() {
webex.cc.stationLogout({logoutReason: 'logout'}).then((response) => {
console.log('Agent logged out successfully', response);

setTimeout(() => {
logoutAgentElm.classList.add('hidden');
}, 1000);
}
).catch((error) => {
console.log('Agent logout failed', error);
});
}

const allCollapsibleElements = document.querySelectorAll('.collapsible');
allCollapsibleElements.forEach((el) => {
el.addEventListener('click', (event) => {
Expand Down
5 changes: 3 additions & 2 deletions docs/samples/contact-center/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h2 class="collapsible">
<div class="u-mv">
<button id="webexcc-register" type="button" onclick="register()" disabled=""
class="btn-code">webex.cc.register()</button>
<p id="ws-connection-status" class="status-par">Not Registered</p>
<p id="ws-connection-status" class="status-par">Not Subscribed</p>
</div>
</fieldset>
</form>
Expand All @@ -88,7 +88,7 @@ <h2 class="collapsible">
<div class="box">
<section class="section-box">
<h2 class="collapsible">
Agent Desktop Using Webex CC SDK
Agent Station Login/Logout
<i class="arrow fa fa-angle-down" aria-hidden="true"></i>
</h2>

Expand All @@ -112,6 +112,7 @@ <h2 class="collapsible">
<input id="dialNumber" name="dialNumber" placeholder="Dial Number" value="" type="text">
<button id="loginAgent" disabled class="btn btn-primary my-3" onclick="doAgentLogin()">Login With
Selected Team</button>
<button id="logoutAgent" class="btn btn-primary my-3 ml-2 hidden" onclick="logoutAgent()">Logout Agent</button>
</fieldset>
<fieldset>
<legend>Agent status</legend>
Expand Down
2 changes: 1 addition & 1 deletion packages/@webex/plugin-cc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"build:src": "webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts && yarn build",
"build": " yarn workspace @webex/calling run build:src && yarn run -T tsc --declaration true --declarationDir ./dist/types",
"build": "yarn run -T tsc --declaration true --declarationDir ./dist/types",
"docs": "typedoc --emit none",
"fix:lint": "eslint 'src/**/*.ts' --fix",
"fix:prettier": "prettier \"src/**/*.ts\" --write",
Expand Down
71 changes: 56 additions & 15 deletions packages/@webex/plugin-cc/src/cc.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import {WebexPlugin} from '@webex/webex-core';
import AgentConfig from './features/Agentconfig';
import {IAgentProfile, SetStateResponse, StationLoginResponse} from './features/types';
import {SetStateResponse} from './features/types';
import {
CCPluginConfig,
IContactCenter,
WebexSDK,
SubscribeRequest,
LoginOption,
WelcomeEvent,
IAgentProfile,
AgentLogin,
StationLoginResponse,
StationLogoutResponse,
StationReLoginResponse,
} from './types';
import {READY, CC_FILE} from './constants';
import {READY, CC_FILE, EMPTY_STRING} from './constants';
import HttpRequest from './services/core/HttpRequest';
import WebCallingService from './WebCallingService';
import {AgentLogin} from './services/config/types';
import WebCallingService from './services/WebCallingService';
import {AGENT, WEB_RTC_PREFIX} from './services/constants';
import Services from './services';
import LoggerProxy from './logger-proxy';
import {StateChange} from './services/agent/types';
import {StateChange, Logout} from './services/agent/types';
import {getErrorDetails} from './services/core/Utils';

export default class ContactCenter extends WebexPlugin implements IContactCenter {
namespace = 'cc';
Expand Down Expand Up @@ -62,7 +66,7 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
} catch (error) {
this.$webex.logger.error(`file: ${CC_FILE}: Error during register: ${error}`);

return Promise.reject(new Error('Error while performing register`', error));
throw error;
}
}

Expand All @@ -73,7 +77,7 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
* @private
*/
private async connectWebsocket() {
const connectionConfig: SubscribeRequest = {
const connectionConfig = {
force: this.$config?.force ?? true,
isKeepAliveEnabled: this.$config?.isKeepAliveEnabled ?? false,
clientType: this.$config?.clientType ?? 'WebexCCSDK',
Expand Down Expand Up @@ -106,7 +110,7 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
/**
* This is used for agent login.
* @param data
* @returns Promise<StationLoginSuccess>
* @returns Promise<StationLoginResponse>
* @throws Error
*/
public async stationLogin(data: AgentLogin): Promise<StationLoginResponse> {
Expand All @@ -119,10 +123,11 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
isExtension: data.loginOption === LoginOption.EXTENSION,
deviceId: this.getDeviceId(data.loginOption, data.dialNumber),
roles: [AGENT],
teamName: '',
siteId: '',
// TODO: The public API should not have the following properties so filling them with empty values for now. If needed, we can add them in the future.
teamName: EMPTY_STRING,
siteId: EMPTY_STRING,
usesOtherDN: false,
auxCodeId: '',
auxCodeId: EMPTY_STRING,
},
});

Expand All @@ -133,9 +138,45 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
await loginResponse;

return loginResponse;
} catch (error: any) {
this.$webex.logger.log(`file: ${CC_FILE}: Station Login FAILED: ${error.id}`);
throw new Error(error.details?.data?.reason ?? 'Error while performing station login');
} catch (error) {
throw getErrorDetails(error, 'stationLogin');
}
}

/** This is used for agent logout.
* @param data
* @returns Promise<StationLogoutResponse>
* @throws Error
*/
public async stationLogout(data: Logout): Promise<StationLogoutResponse> {
try {
const logoutResponse = this.services.agent.logout({
data,
});

await logoutResponse;

if (this.webCallingService) {
this.webCallingService.deregisterWebCallingLine();
}

return logoutResponse;
} catch (error) {
throw getErrorDetails(error, 'stationLogout');
}
}

/* This is used for agent relogin.
* @returns Promise<StationReLoginResponse>
* @throws Error
*/
public async stationReLogin(): Promise<StationReLoginResponse> {
try {
const reLoginResponse = await this.services.agent.reload();

return reLoginResponse;
} catch (error) {
throw getErrorDetails(error, 'stationReLogin');
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/@webex/plugin-cc/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default {
},
serviceData: {
indicator: 'contactcenter',
// TODO: This should be dynamic based on the environment
domain: 'rtw.prod-us1.rtmsprod.net',
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/@webex/plugin-cc/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export const EVENT = 'event';
export const READY = 'ready';
export const CC_FILE = 'cc';
export const TIMEOUT_DURATION = 20000; // 20 seconds timeout duration for webrtc registration
export const EMPTY_STRING = '';
5 changes: 2 additions & 3 deletions packages/@webex/plugin-cc/src/features/Agentconfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {IAgentProfile, WORK_TYPE_CODE} from './types';
import {WORK_TYPE_CODE} from './types';
import AgentConfigService from '../services/config';
import {Team, AuxCode} from '../services/config/types';
import {WebexSDK} from '../types';
import {WebexSDK, IAgentProfile, Team, AuxCode} from '../types';
import {
AGENT_STATE_AVAILABLE,
AGENT_STATE_AVAILABLE_DESCRIPTION,
Expand Down
52 changes: 0 additions & 52 deletions packages/@webex/plugin-cc/src/features/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {WebexSDK} from '../types';
import {AuxCode, Team} from '../services/config/types';
import * as Agent from '../services/agent/types';

type Enum<T extends Record<string, unknown>> = T[keyof T];
Expand Down Expand Up @@ -36,57 +35,6 @@ export type AgentConfigRequest = {
orgId: string;
};

/**
* Represents the response from AgentConfig.
*
* @public
*/
export type IAgentProfile = {
/**
* The id of the agent.
*/

agentId: string;

/**
* The name of the agent.
*/
agentName: string;

/**
* Identifier for a Desktop Profile.
*/
agentProfileId: string;

/**
* The email address of the agent.
*/

agentMailId: string;

/**
* Represents list of teams of an agent.
*/
teams: Team[];

/**
* Represents the voice options of an agent.
*/

loginVoiceOptions: string[];

/**
* Represents the Idle codes list that the agents can select in Agent Desktop.t.
*/

idleCodes: AuxCode[];

/**
* Represents the wrap-up codes list that the agents can select when they wrap up a contact.
*/
wrapUpCodes: AuxCode[];
};

/**
* Represents the response from setAgentStatus.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import {createClient, ICall, ICallingClient, ILine, LINE_EVENTS} from '@webex/calling';
import {CallingClientConfig} from '@webex/calling/dist/types/CallingClient/types';
import {WebexSDK} from './types';
import {TIMEOUT_DURATION} from './constants';
import {
createClient,
ICall,
ICallingClient,
ILine,
LINE_EVENTS,
CallingClientConfig,
} from '@webex/calling';
import {WebexSDK} from '../types';
import {TIMEOUT_DURATION} from '../constants';

export default class WebCallingService {
private callingClient: ICallingClient;
Expand Down Expand Up @@ -52,6 +58,6 @@ export default class WebCallingService {
}

public async deregisterWebCallingLine() {
this.line.deregister();
this.line?.deregister();
}
}
Loading

0 comments on commit 35b6e15

Please sign in to comment.