You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
connect.agent(function(agent){varconfig=agent.getConfiguration();console.log("here is your configuration: "+JSON.stringify(config));});
Get agent states
connect.agent(function(agent){varstates=agent.getAgentStates();console.log("here are your states: "+JSON.stringify(states));});
Change agent state
connect.agent(function(agent){vartargetState=agent.getAgentStates()[0];agent.setState(targetState,{success: function(){console.log("Set agent status via Streams")},failure: function(){console.log("Failed to set agent status via Streams")}});});
Change agent state to OFFLINE
connect.agent(function(agent){varofflineState=agent.getAgentStates().filter(function(state){returnstate.type===connect.AgentStateType.OFFLINE;})[0];agent.setState(offlineState,{success: function(){console.log("Set agent status to Offline via Streams")},failure: function(){console.log("Failed to set agent status to Offline via Streams")}});});
Change agent state to AVAILABLE
connect.agent(function(agent){varavail=agent.getAgentStates().filter(function(state){returnstate.type===connect.AgentStateType.ROUTABLE;})[0];agent.setState(avail,{success: function(){console.log("Set agent status to Available via Streams")},failure: function(){console.log("Failed to set agent status to Available via Streams")}});});
Hang up calls, set status to Offline and redirect to logout URL
varc;varccpInstance="yourInstanceAlias";connect.contact(function(contact){c=contact;connect.agent(function(agent){if(c){varinitialConnection=c.getInitialConnection();varthirdParty=c.getSingleActiveThirdPartyConnection();if(initialConnection){initialConnection.destroy();awaitsleep(1000);}if(thirdParty){thirdParty.destroy();awaitsleep(1000);}}});varofflineState=agent.getAgentStates().filter(function(state){returnstate.type===connect.AgentStateType.OFFLINE;})[0];agent.setState(offlineState,{success: function(){console.log("Set agent status to Offline via Streams")},failure: function(){console.log("Failed to set agent status to Offline via Streams")}});window.location.replace('https://<your-instance-domain>/connect/logout');// or fetch("https://<your-instance-domain>/connect/logout", { credentials: 'include'})});
varagent=newlily.Agent();agent.getEndpoints(agent.getAllQueueARNs(),{success: function(data){console.log("valid_queue_phone_agent_endpoints",data.endpoints,"You can transfer the call to any of these endpoints");},failure:function(){console.log("failed")}});
Transfer to a quick connect
varagent=newlily.Agent();agent.getEndpoints(agent.getAllQueueARNs(),{success: function(data){console.log("valid_queue_phone_agent_endpoints",data.endpoints,"You can transfer the call to any of these endpoints");agent.getContacts(lily.ContactType.VOICE)[0].addConnection(data.endpoints[6],{success: function(data){alert("transfer success");},failure: function(data){alert("transfer failed");}});},failure:function(){console.log("failed")}});
connect.agent(asyncfunction(agent){a=agent;varconfig=a.getConfiguration();//config.value = whatYouWantconfig.softphoneEnabled=true;a.setConfiguration(config,{success: function(){console.log("set softphone successfully");},failure: function(){console.log("Could not set softphone....");}});});
Get contact attributes
varc;connect.contact(function(contact){c=contact;c.onConnecting(function(c){varattr=c.getAttributes();varc1=c.getConnections()[1];varc2=c.getStatus();document.getElementById("contactID").value=c.contactId;document.getElementById("phoneNumber").value=c1.getAddress()['phoneNumber'];if(attr.firstName){console.log(Here's your value for firstName " + attr.firstName.value);
}if(attr.lastName){console.log(Here's your value for lastName " + attr.lastName.value);
}});});
Add a log message to agent logs
connect.getLog().warn("yar, I'm a pirate")
Download agent logs
connect.getLog().download()
Media Controller API for chat - New,ChatJS Required
connect.contact(function(contact){contact.getAgentConnections().forEach(function(connection){// chat usersif(connection.getMediaType()===connect.MediaType.CHAT){contact.getConnection().getMediaController().then(function(controller){controller.onMessage(function(response){console.log("data",response)})controller.sendMessage({message: "so and so",contentType: "text/plain"}).then(function(res,req){console.log(res.status)});controller.onDisconnect(function(){console.log("on disconnect");})});}});
ViewContact API
connect.core.viewContact("contactID")
onAuthFail Event Handler
connect.core.onAuthFail(function(){// agent logged out or session expired. needs login// show button for login or popup a login screen. });
onSoftphoneSessionInit Event Handler
connect.core.onSoftphoneSessionInit(function({ connectionId }){varsoftphoneManager=connect.core.getSoftphoneManager();if(softphoneManager){// access sessionvarsession=softphoneManager.getSession(connectionId);// YOu can use this rtc session for stats analysis }});
functionmuteAgent(){constagent=newconnect.Agent();constcontact=agent.getContacts(connect.ContactType.VOICE)?.[0]// Get all open active connectionsconstactiveConnections=contact?.getConnections().filter((conn)=>conn.isActive())||[];if(activeConnections.length===0){console.log("No Active Connections to mute");return;}// Check if we are using multiparty and see if there more than 2 active connectionsif(contact.isMultiPartyConferenceEnabled()&&activeConnections.length>2){// if any of those are in connecting modeconstconnectingConnections=contact?.getConnections().filter((conn)=>conn.isConnecting())||[];if(connectingConnections.length===0){console.log("Agent Connection is muted at the server side");contact.getAgentConnection().muteParticipant();}else{console.log("Agent Connection cannot be muted while multi party participant is connecting")}}else{console.log("Agent connection muted at the client side");agent.mute();}}
Check if connected contact has ScreenRecording Enabled