Using Service Cloud Voice LWC Toolkit API Events, we can perform actions using Lightning Web Component.
Sample Code:
HTML:
<template>
<lightning-service-cloud-voice-toolkit-api>
</lightning-service-cloud-voice-toolkit-api>
</template>
JavaScript:
import { LightningElement } from 'lwc';
export default class VoiceCallListener extends LightningElement {
callEndedListener;
callConnectedListener;
constructor() {
console.log( 'Inside the Constructor' );
super();
this.callConnectedListener = this.onCallConnected.bind( this );
this.callEndedListener = this.onCallEnded.bind( this );
}
renderedCallback() {
console.log( 'Inside Connected Callback' );
const toolkitApi = this.template.querySelector(
'lightning-service-cloud-voice-toolkit-api'
);
if( toolkitApi ) {
console.log( 'Inside Toolkit API' );
toolkitApi.addEventListener( 'callconnected', this.callConnectedListener );
toolkitApi.addEventListener( 'callended', this.callEndedListener );
}
}
onCallConnected( event ) {
console.log( 'Call Connected Voice Toolkit event detail is', JSON.stringify( event.detail ) );
}
onCallEnded( event ) {
console.log( 'Call Ended Voice Toolkit event detail is', JSON.stringify( event.detail ) );
}
}
js-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>55.0</apiVersion>
<isExposed>true</isExposed>
<capabilities>
<capability>lightning__ServiceCloudVoiceToolkitApi</capability>
</capabilities>
<targets>
<target>lightning__UtilityBar</target>
</targets>
</LightningComponentBundle>
Lightning App Configuration:
Output: