/* /* Update on Sample Gadget provided by Aashish Berry (aaberry) - https://github.com/aashishberry/desktopWidgets/tree/main This version checks BEFORE attempting to make the agent available that the agent state is Idel with Idle Code of 'RONA' Only then will it allow the agent state to move back to available. This allows an agent to go Idle with different reason code (manually) and the widget will NOT pushed the agent back into available automatically It also not allow the gadget to attempt to move the agent into available again even if the agent is already available! */ import { Desktop } from '@wxcc-desktop/sdk'; const logger = Desktop.logger.createLogger('change-ronaV2'); logger.info('Change RONA Widget Loading...'); let initialized = false; class changeRona extends HTMLElement { constructor() { super(); this.attachShadow({ mode: "open" }); } connectedCallback() { if (initialized) return; // stop double initialization of Widget this.init(); initialized = true; } disconnectedCallback() { Desktop.agentContact.removeAllEventListeners(); Desktop.agentStateInfo.removeAllEventListeners(); } sleep = (delay) => new Promise(r => setTimeout(r, delay)); async init() { logger.info('init(): Waiting 15 Seconds, the agent needs to complete login within this time for this gadget to work. Otherwise RONA Event Listner does not trigger (I do not know why?)'); await this.sleep(15000); await Desktop.config.init({ widgetName: "change-ronaV2", widgetProvider: "GOR" }); if (this.delaySeconds) { logger.info('Delay read from layout: ' + this.delaySeconds + ' seconds.'); this.delaySeconds = this.delaySeconds * 1000; } else { this.delaySeconds = 10000; logger.info('Delay unavailable in layout. Default 10 seconds.'); } logger.info("Widget initialized"); this.agentInteractionEvents(); } async agentInteractionEvents() { //logger.info(Desktop.agentStateInfo.latestData); Desktop.agentContact.addEventListener("eAgentOfferContactRona", () => { logger.info('RONA triggered - lets sleep for ' + this.delaySeconds/1000 + ' seconds before we attempt to move the agent back into Available state'); this.triggerChange(); }); } async triggerChange() { await this.sleep(this.delaySeconds); logger.info("Our RONA sleep timer has completed."); if (Desktop.agentStateInfo.latestData.idleCode.name === 'RONA'){ logger.info("Agent is in an idle state with an idleCode name of 'RONA', hence we will attempt to move back to Available..."); try { await Desktop.agentStateInfo.stateChange({ state: 'Available', auxCodeIdArray: '0', }); logger.info("Agent State changed to Available!"); } catch (e) { logger.error(e); } }else{ logger.info("Agent is no longer in an idle state so we will NOT attempt to move back to Available..."); } } } window.customElements.define("change-rona", changeRona);