Configure Callbacks
To transfer a voice call to an Omni-Channel flow, pass the Flow ID as the routingTarget and optionally include flowInputParameters to pass input variables to the flow. To specify a fallback queue if the flow transfer fails, include fallbackQueue.
On success, returns the routing response. If required parameters are missing or the request fails, returns an error message. For example:
1/**
2 * Route a voice call to an Agent, Queue, or Flow.
3 * PATCH /telephony/v1/voiceCalls/{voiceCallId}/routeVoiceCall
4 */
5 routeVoiceCall(params) {
6 const voiceCallIdParam = params.voiceCallId || voiceCallId;
7 const { routingTarget, fallbackQueue, flowInputParameters } = params;
8 const telephonyProviderName = params.telephonyProviderName || 'demo-connector';
9
10 if (!voiceCallIdParam) {
11 return Promise.reject(new Error('voiceCallId is required for routeVoiceCall'));
12 }
13 if (!routingTarget) {
14 return Promise.reject(new Error('routingTarget is required for routeVoiceCall'));
15 }
16
17 const fieldValues = {
18 routingTarget,
19 ...(fallbackQueue != null && { fallbackQueue }),
20 ...(flowInputParameters != null && { flowInputParameters })
21 };
22 const headers = {
23 headers: {
24 'Authorization': `Bearer ${getToken()}`,
25 'Content-Type': 'application/json',
26 'Telephony-Provider-Name': telephonyProviderName
27 }
28 };
29
30 return getAxiosClient(tenantInfo).patch(`/voiceCalls/route/${voiceCallIdParam}`, fieldValues, headers).then((response) => {
31 console.log("Route voice call response: " + JSON.stringify(response.data));
32 return response;
33 });
34 },For example, see this sample addParticipant implementation for Transfer to Queue or Transfer to Agent scenarios. The function creates a transfer voice call, checks whether Unified Routing is enabled, and invokes routeVoiceCall with the transfer target as the routingTarget. On success, Salesforce routes the call to the specified agent or queue and assigns the work through Omni-Channel.
1async addParticipant(contact, call, isBlindTransfer) {
2....
3....
4 let transferCall = await this.createVoiceCall(parentCall.callId, Constants.CALL_TYPE.TRANSFER, parentCall.phoneNumber, additionalFields);
5....
6....
7....
8....
9if (this.state?.flowConfig?.isUnifiedRoutingEnabled) {
10
11
12 /* This block display integration of new Route voice call API for Transfer to Queue/Transfer to agent use case. */
13 if (flowConfig.useRouteFlowApi) {
14 const routePayload = { routingTarget: transferTo };
15 await this.routeVoiceCall(voiceCallIdOrVendorKey, routePayload);
16 } else {
17/* This block display integration of existing ExecuteOmniflow API for Transfer to Queue/Transfer to agent use case. */
18 const callInfoData = { transferTo, voiceCallId: voiceCallIdOrVendorKey };
19 const flowConfigData = { dialedNumber: flowConfig.dialedNumber };
20 await this.executeOmniFlowForUnifiedRouting(callInfoData, flowConfigData);
21 }
22
23}
24....
25....
26 /**
27 * Route a voice call to an Agent, Queue, or Flow.
28 * @param {string} voiceCallId - VoiceCall Identifier for which routing needs to be executed
29 * @param {Object} requestBody - Route request
30 * @param {string} requestBody.routingTarget - Agent ID, Queue ID, or Flow ID to route to
31 * @param {string} [requestBody.fallbackQueue] - Fallback queue ID
32 * @param {Object.<string, string>} [requestBody.flowInputParameters] - Input parameters for Flow
33 * @returns {Promise<{status: string}>} RouteVoiceCallResponse with status (success or exception message)
34 */
35 async routeVoiceCall(voiceCallId, requestBody) {
36 if (!voiceCallId) {
37 return Promise.reject(new Error('voiceCallId is required for routeVoiceCall'));
38 }
39 const { routingTarget, fallbackQueue, flowInputParameters } = requestBody || {};
40 if (!routingTarget) {
41 return Promise.reject(new Error('routingTarget is required for routeVoiceCall'));
42 }
43 const body = { routingTarget };
44 if (fallbackQueue != null) body.fallbackQueue = fallbackQueue;
45 if (flowInputParameters != null) body.flowInputParameters = flowInputParameters;
46
47 const response = await fetch('/api/voiceCalls/' + encodeURIComponent(voiceCallId) + '/route', {
48 method: 'PATCH',
49 headers: { 'Content-Type': 'application/json' },
50 body: JSON.stringify(body)
51 });
52 const data = await response.json().catch(() => ({}));
53 if (!response.ok) {
54 return Promise.reject(new Error(data.status || data.message || response.statusText));
55 }
56 return data;
57 }