Script to determinate Country from phone number

If Phone has the number of visitor, how can save in variable Country the country , based on phone number?

I tried this code but it does not work

// Obtener el número de teléfono de la variable Typebot let phone = "{{Phone}}"; // Función para determinar el país basado en los dos primeros dígitos del número de teléfono function determineCountry(phoneNumber) { let countryCode = phoneNumber.substring(0, 2); let country; switch (countryCode) { case "54": country = "Argentina"; break; case "59": country = "Uruguay"; break; case "52": country = "Mexico"; break; case "1": country = "Usa"; break; default: country = "UNKKNOWN"; break; } return country; } // Determinar el país y guardarlo en la variable countryfinal let countryfinal = determineCountry(phone); // Establecer la variable country en Typebot setVariable('country', countryfinal);



Because The country is {{Country}} , always shows UNKNOWN
Was this page helpful?