Skip to content

🚨 Important Lab Dependency

This mission requires configuration created in the following missions:

  1. 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.

Profiles

Call Flow Overview

  1. When call arrives, function node analyzes ANI and returns respective country name in the output.
  2. Play Message node plays the message with selected country name.

Mission Details

Your mission is to:

  1. 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.
  2. Create a new flow with the Function element.
  3. Play the country generated by the Function to the caller.

Building Function

  1. Switch to Control Hub, then navigate to Functions, click on Create a function.

  2. 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.

    Profiles

  3. Add following variable by clicking Add Input Variables on the right-hand side:

    Name: ANI
    Type: String

  4. Add output variable CountryName in Output Variable Definition field.

    Profiles

  5. 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

    const countryCodes = {
      "+380": "Ukraine",
      "+44": "United Kingdom",
      "+48": "Poland",
      "+1": "United States",
      "+34": "Spain"
      };
    

    Profiles

    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

    1. Read the ANI (Caller Number):

      let ani = request.inputs.ANI || "";
      
      • Retrieves the caller’s phone number from the flow
      • If ANI is missing β†’ defaults to an empty string (prevents errors)
    2. Normalize the Number Format

      if (!ani.startsWith("+")) {
      ani = "+" + ani;
      }
      

      • Ensures the number is in international format (E.164)
      • Example: 447911123456 β†’ +447911123456
      • This is critical because all comparisons rely on + prefixes
    3. 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)
    4. Sort Prefixes by Length:

      const prefixes = Object.keys(countryCodes).sort((a, b) => b.length - a.length);
      };
      

      • Sort prefixes from longest to shortest.
      • Ensures most specific match wins
    5. 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
        • Stop loop (break)
    6. Return Result:

      response.data = { Country: country };
      return response;
      
      • Stores the result in response object Country
  6. 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

    Profiles

  7. Click on Publish Function in the bottom right corner of the page. Then click Publish Function in pop up window.

    Profiles


Building Flow

  1. Switch to Control Hub, then navigate to Flows, click on Manage Flows then select Create Flows from drop down list.

  2. Select Start from scratch and click next

  3. Enter flow name CountryCaseFlow_Your_Attendee_ID and click on Create Flow.

    Profiles

  4. 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

  5. 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: ANI

    Set Variable: NewPhoneContact.ANI

    Profiles

  6. 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.

    Profiles

  7. 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: CountryName

    Path Expression $.Country

    Profiles

  8. 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.

    Profiles

  9. 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

  10. 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.

    Profiles

  11. 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

    Profiles

Testing

  1. Open your Webex App and dial the Support Number provided to you, which is configured in your Your_Attendee_ID_Channel configuration.

    profiles

  2. Verify if you hear a message built inside your function.

  3. Switch to Flow Designer and click Debug tab at the bottom and select last interaction (the first in the list).

  4. 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.

  5. Click on CountryCase_Function_Your_Attendee_ID. Scroll down to see Activity Inputs, Activity Outputs and Modified Variables.

  6. Click on Case step and check if selected path corresponds to your selected country name value.

    Profiles


Congratulations, you have succesfully completed Country Case mission! πŸŽ‰πŸŽ‰