Outbound calls

Now you set up functionality to reject an incoming call or, disconnect the accepted call.

Now let's look into how we can handle outbound calls in your CTI application. For example, when an agent clicks a Contact mobile number link from the Fusion application ON the Service Request Edit page, or the agent clicks a mobile link of a Contact from the Digital Sales Contact page. These actions trigger the OnOutgoingEvent and the CTI application gets the notification if the CTI application has a subscription for this event. It's a non controllable event and by adding the listener CTI can wire up the logic to start a call. For example, to call the UEF NewComm API, based on the information in the event response of this event. Once you complete this section, you can start outbound calls from Fusion applications

Overview of the tasks

Here's an overview of what you need to do:
  1. Add subscription to the onOutgoingEvent and add logic to fire the newComm event
  2. Add the below method in the integrationActionHandler.
  3. Update the makeOutboundCall method in the VendorHandler class.
  4. Add the triggerOutbound call method in appController.
  5. Call subscribeToOutboundCallsFromFusion from IntegrationEventsHandler in the makeAgentAvailable method
  6. Add more methods to support the user accept and decline event.

1. Add subscription to onOutgoingEvent and add logic to fire the newComm event

In the fusionHandler.ts file located at: src/ts/cti/fusion/fusionHandler.ts, add the following methods to subscribe to onOutgoingEvent

public static async acknowledgeOutBoundCallEvent(eventResponse: IMcaonOutgoingEventResponse): Promise<void> {
    const request: IMcaNewCommEventActionRequest = FusionHandler.frameworkProvider.requestHelper.createPublishRequest('newCommEvent') as IMcaNewCommEventActionRequest;
    const eventId: string = eventResponse.getResponseData().getOutData().SVCMCA_CALL_ID;
    request.setEventId(eventId);
    const indata: any = {
        ...eventResponse.getResponseData().getOutData(),
        'callData': {
            "phoneLineId": "1",
            "eventId": eventId,
        },
        'SVCMCA_COMMUNICATION_DIRECTION': 'ORA_SVC_OUTBOUND',
        'SVCMCA_WRAPUP_TIMEOUT': '',
        'appClassification': ''
        // you can add additional indata here
    };
    FusionHandler.publishNewCommEvent(eventId, indata);
}
 
public static async subscribeToOutboundCallsFromFusion(onOutboundCall: Function): Promise<void> {
    const requestObject: IMcaEventRequest = FusionHandler.frameworkProvider.requestHelper.createSubscriptionRequest('onOutgoingEvent') as IMcaEventRequest;
    requestObject.setAppClassification(FusionHandler.appClassification);
    FusionHandler.phoneContext.subscribe(requestObject, async (eventResponse: IEventResponse) => {
        await onOutboundCall((eventResponse as IMcaonOutgoingEventResponse).getResponseData().getOutData());
        await FusionHandler.acknowledgeOutBoundCallEvent(eventResponse as IMcaonOutgoingEventResponse);
    });
}

2. Add the method in integrationActionHandler

public makeCall(phoneNumber: string, eventId: string): Promise<void> {
    return this.vendor.makeOutboundCall(phoneNumber, eventId);
}

3. Update the makeOutboundCall method in VendorHandler class

public async makeOutboundCall(phoneNumber: string, eventId: string) {
    // TODO: call the vendor specific api to make the make an outbound call
}

4. Add the triggerOutbound call method in appController

public triggerOutboundCall = (outdata: IMcaOnOutgoingEventOutData) => {
    this.callContext({
        ...this.callContext(),
        direction: 'outbound',
        phonenumber: outdata.SVCMCA_ANI,
        callerName: outdata.SVCMCA_DISPLAY_NAME,
        eventId: outdata.SVCMCA_CALL_ID,
        state: 'RINGING'
    });
    this.integrationActionHandler.makeCall(outdata.SVCMCA_ANI, outdata.SVCMCA_CALL_ID);
}

5. Call the subscribeToOutboundCallsFromFusion from IntegrationEventsHandler in the makeAgentAvailable method

public async makeAgentAvailable(): Promise<void> {
    try {
        await FusionHandler.makeAgentAvailable();
        this.ctiAppViewModel.agentState(true);
        FusionHandler.subscribeToToolbarInteractionCommandsFromFusion((command: string) => { this.listenToToolbarInteractionCommandsFromFusion(command); });
        // code block starts
        FusionHandler.subscribeToOutboundCallsFromFusion((outdata: IMcaOnOutgoingEventOutData) => {
           this.ctiAppViewModel.triggerOutboundCall(outdata);
        });
        // code block ends
    } catch (err) {
        console.log("Error while making agent available", err)
    }
}

6. Add more methods to support the user accept, decline event

Add the following methods to the RootViewModel class:

public handleOutgoingCallAccepted = () => {
    this.callContext({
      ...this.callContext(),
      state: 'ACCEPTED'
    });
}
 
public handleOutgoingCallEnded = () => {
    this.callContext({
      ...this.callContext(),
      state: 'DISCONNECTED'
    });
}

Add the following methods to the IntegrationEventsHandler class:

public async outboundCallAcceptedHandler(eventId: string): Promise<void> {
    try {
        await FusionHandler.notifyCallAcceptedToFusion(eventId);
        this.ctiAppViewModel.handleOutgoingCallAccepted();
    } catch {
        console.log("Error: Unable to notify call accepted.")
    }
}
 
public async callHangupHandler(eventId: string): Promise<void> {
    try {
        await FusionHandler.notifyCallDisconnectedToFusion(eventId, "WRAPUP");
        this.ctiAppViewModel.handleOutgoingCallEnded();
    } catch {
        console.log("Error: Unable to notify Call disconnected.")
    }
}
 
public async callRejectedHandler(eventId: string): Promise<void> {
    try {
        await FusionHandler.notifyCallDisconnectedToFusion(eventId, "REJECT");
        this.ctiAppViewModel.handleOutgoingCallEnded();
    } catch {
        console.log("Error: Unable to notify Call disconnected.")
    }
}

Verify your progress

Once you complete these steps, use the OJET server to start your application and sign in to your Fusion application. Open the media toolbar and make your agent available for calls by clicking on the Agent Availability button. To start an outbound call, open the contact from your Fusion application and click the phone number.