π¨ Important Lab Dependency
This mission requires configuration created in the following missions:
- NO DEPENDENCY
Mission 6: The "Zen of Simplicity" (UI vs. Code). Using Functions to simplify flow logic.
Note
Current usecase was covered in Cisco Live 2026 and Partner Technical Summits 2026. Boosting Customer Experience with Flow Orchestration in Webex Contact Center - BRKCCT-2345 (login required)
Story
In this mission, you will use a Function node in Webex Contact Center to select a language based on caller's ANI. By analyzing ANI our function will return a country name that we can use further in script logic to either select language or redirect to a specific team. This approach allows you to collapse 10 messy nodes into one elegant script.
Call Flow Overview
- When call arrives, function node analyzes ANI and returns respective country name in the output.
- Play Message node plays the message with selected country name.
Mission Details
Your mission is to:
- Create a function that analyzes phone country code as part of ANI of the caller, processes it, and return a country name based on a country phone code.
- Create a new flow with the Function element.
- Play the country generated by the Function to the caller.
Building Function
-
Switch to Control Hub, then navigate to Functions, click on Create a function.
-
New Tab will be opened. Select Start Fresh and provide name CountryCase_Function_Your_Attendee_ID. Leave Function Language as JavaScript, then click Create Function.
-
Add following variable by clicking Add Input Variables on the right-hand side:
Name: ANI
Type: String -
Add output variable CountryName in Output Variable Definition field.
-
Clear the editor from the default code and paste the following JavaScript code into Function editor.
export const handle = async (request, response) => { let ani = request.inputs.ANI || ""; // Ensure it starts with "+" if (!ani.startsWith("+")) { ani = "+" + ani; } // Country code map const countryCodes = { "+380": "Ukraine", "+44": "United Kingdom", "+48": "Poland", "+1": "United States" }; // Check longest prefixes first const prefixes = Object.keys(countryCodes).sort((a, b) => b.length - a.length); let country = "Unknown"; for (let prefix of prefixes) { if (ani.startsWith(prefix)) { country = countryCodes[prefix]; break; } } response.data = { Country: country }; return response; };Note
You can add more country codes into // Country code map. Se the following example of how to add Spain country code
Good to know: Script Breakdown [Optional]
This function takes an incoming phone number (ANI) and determines the country based on its international dialing prefix.``` JSON export const handle = async (request, response) => { ```This is the entry point of the function:
-requestβ contains input data (like ANI) -responseβ where we store the result returned to the flow-
Read the ANI (Caller Number):
- Retrieves the callerβs phone number from the flow
- If ANI is missing β defaults to an empty string (prevents errors)
- Retrieves the callerβs phone number from the flow
-
Normalize the Number Format
- Ensures the number is in international format (E.164)
- Example:
447911123456β+447911123456 - This is critical because all comparisons rely on + prefixes
- Ensures the number is in international format (E.164)
-
Define Country Code Mapping:
const countryCodes = { "+380": "Ukraine", "+44": "United Kingdom", "+48": "Poland", "+1": "United States" };- A simple lookup table
- Keys = country dialing prefixes
- Values = country names
- Easy to extend (just add more entries)
- A simple lookup table
-
Sort Prefixes by Length:
- Sort prefixes from longest to shortest.
- Ensures most specific match wins
- Sort prefixes from longest to shortest.
-
Find Matching Country:
let country = "Unknown"; for (let prefix of prefixes) { if (ani.startsWith(prefix)) { country = countryCodes[prefix]; break; } }- Loop through all prefixes
- Check if ANI starts with a given prefix
- If match found:
-
- Assign country
- Assign country
-
- Stop loop (
break)
- Stop loop (
- Loop through all prefixes
-
Return Result:
- Stores the result in response object
Country
- Stores the result in response object
-
-
Perform a test to see how you script preforms by navigating to Test panel below the editor. Provide the following data into respective fields, then click Test button.
ANI: +48123211853 -
Click on Publish Function in the bottom right corner of the page. Then click Publish Function in pop up window.
Building Flow
-
Switch to Control Hub, then navigate to Flows, click on Manage Flows then select Create Flows from drop down list.
-
Select Start from scratch and click next
-
Enter flow name CountryCaseFlow_Your_Attendee_ID and click on Create Flow.
-
Add these flow variables:
- ANI variable:
Name: ANI
Type: String
Default Value: leave it empty
- Country Name variable:
Name: CountryName
Type: String
Default Value: leave it empty
-
Add Set Variable node
Activity Label: SetANI
Connect NewPhoneContact you added at the previous step to this node
We will connect this Set Variable node in next step
Variable:
ANISet Variable:
NewPhoneContact.ANI -
Add Play Message node
Connect the SetANI node edge to the Play Message node
We will connect this Play Message node in next step
Enable Text-To-Speech
Select the Connector: Cisco Cloud Text-to-Speech
Click Add Text-to-Speech Message button
Delete the selection for Audio File
Text-to-Speech Message: Welcome to Zen of Simplicity flow.
-
Switch to Functions tab at the panel on the left-hand side. Then drag CountryCase_Function_Your_Attendee_ID node to the canvas.
Connect SetANI node you added at the previous step to this node
We will connect this node in next step
Function Version Label: Latest
Function Input Variables should autopopulate
Output Settings
Output Variable:
CountryNamePath Expression
$.Country -
Switch to Activity tab in the left menu. Add Case node
-
Activity Label: Country_Case_Check
-
Connect the output node edge from the Function node to this node
-
Variable:
CountryName
In LINK DESCRIPTION - Change Case 0 to Ukraine
-
Change Case 1 to United Kingdom
-
Click Add New. Change Case 2 and to Poland
-
Click Add New. Change Case 3 and to United States
-
We will connect the all cases in future steps.
-
-
Switch to Activity tab in the left menu. Add Play Message and Disconnect Contact nodes
Connect all Case node edges except Undefined Errors to the Play Message node
Enable Text-To-Speech
Select the Connector: Cisco Cloud Text-to-Speech
Click Add Text-to-Speech Message button
Delete the selection for Audio File
Text-to-Speech Message: {{CountryName}} was selected based on your ANI.
Connect the Play Message node edge to this Disconnect Contact node
-
Validate and publish the flow:
Enable the Validation toggle in the bottom right corner of the flow designer window to check for any potential flow errors and recommendations.
If there are no Flow Errors after validation is complete, click on Publish Flow next to it.
In the pop-up window, ensure that the Latest label is selected in the Add Version Label(s) list, then click Publish Flow.
-
Map your flow to your inbound channel
Navigate to Control Hub > Contact Center > Channels
Locate your Inbound Channel (you can use the search): Your_Attendee_ID_Channel
Select the Routing Flow: FunctionFlow_Your_Attendee_ID
Select the Version Label: Latest
Click Save in the lower right corner of the screen
Testing
-
Open your Webex App and dial the Support Number provided to you, which is configured in your Your_Attendee_ID_Channel configuration.
-
Verify if you hear a message built inside your function.
-
Switch to Flow Designer and click Debug tab at the bottom and select last interaction (the first in the list).
-
Click on SetANI and on the right-hand side window scroll to the bottom. In Modified Variables check if ANI variable has your ANI assigned.
-
Click on CountryCase_Function_Your_Attendee_ID. Scroll down to see Activity Inputs, Activity Outputs and Modified Variables.
-
Click on Case step and check if selected path corresponds to your selected country name value.
Congratulations, you have succesfully completed Country Case mission! ππ














