import { Desktop } from '@wxcc-desktop/sdk'; // This is the logger initializer factory method for the headless widget export const logger = Desktop.logger.createLogger('headless-social-autoanswer-widget'); // Some sample data points let version = 1.00; customElements.define( 'headless-social-autoanswer-widget', class extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); } // Mounting the headless widget and initializing async connectedCallback() { logger.info('Log: Version: ' + version); this.init(); logger.info('Log: Webcomponent connectedCallback function'); } // Init Method - called to configure the WebexCC Desktop JS SDK inside the headless widget async init() { await Desktop.config.init(); logger.info('Log: init function'); this.registerEventListeners(); } // This method registers all the event listeners supported by the JS SDK. // The event listeners are asynchronous and require handlers within each of the listeners. // Sample handlers below are only console logs as examples async registerEventListeners() { // Listener for agent contact offered event - Customized by GOR Desktop.agentContact.addEventListener('eAgentOfferContact', async (agentContact) => { logger.info('Log: Agent Offered Contact'); //logger.info('Log: Agent Offered Contact: Details: '+ JSON.stringify(agentContact)); let callOfferedContactDirection = agentContact.data['interaction'].contactDirection.type; logger.info('Log: callOffered contactDirection: '+ callOfferedContactDirection); let callOfferedInteractionId = agentContact.data['interaction'].interactionId; logger.info('Log: callOfferedInteractionId: '+ callOfferedInteractionId); let callOfferedMediaType = agentContact.data['interaction'].mediaType; logger.info('Log: callOfferedMediaType: '+ callOfferedMediaType); if(callOfferedContactDirection.toLowerCase() === 'inbound' && callOfferedMediaType.toLowerCase() === 'social'){ logger.info('Log: Incoming Social Task Offered. Let\'s attempt to Auto Answer!'); let acceptContactResponse = await Desktop.agentContact.accept({interactionId: callOfferedInteractionId}); //logger.info('Log: acceptContactResponse: '+ JSON.stringify(acceptContactResponse)); try{ let acceptContactResponseInteractionState = acceptContactResponse.data['interaction'].state; //logger.info('Log: acceptResponseInteractionState: '+ acceptContactResponseInteractionState); if (acceptContactResponseInteractionState === "connected"){ logger.info('Log: Accepted Task Successfully. Now connected.'); }else{ logger.info('Log: Failed to Accept task? acceptResponseInteractionState: '+ acceptContactResponseInteractionState); } } catch(error){ logger.info('Log: acceptResponseInteractionState - error:'+ error); } } }); } disconnectedCallback() {;} });