// 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);
let phone = {{Phone}}.replace(/\D/g, ""); let countryCode; if (phone.startsWith("+")) { phone = phone.substring(1); } function determineCountry(phoneNumber) { let country; if (phoneNumber.startsWith("54")) { country = "Argentina"; } else if (phoneNumber.startsWith("59")) { country = "Uruguay"; } else if (phoneNumber.startsWith("52")) { country = "Mexico"; } else if (phoneNumber.startsWith("1")) { country = "USA"; } else { country = "UNKNOWN"; } return country; } return determineCountry(phone);
let phone = "{{Phone}}".replace(/\D/g, '');
let countryCode;
if (phone.startsWith("+")) {
phone = phone.substring(1);
}
function determineCountry(phoneNumber) {
let country;
if (phoneNumber.startsWith("54")) {
country = "Argentina";
} else if (phoneNumber.startsWith("59")) {
country = "Uruguay";
} else if (phoneNumber.startsWith("52")) {
country = "Mexico";
} else if (phoneNumber.startsWith("1")) {
country = "USA";
} else {
country = "UNKNOWN";
}
return country;
}
let countryfinal = determineCountry(phone);
setVariable('country', countryfinal);
// Obtener el número de teléfono de la variable Typebot y evitar valores nulos
let phone = "{{Phone}}" || ""; // Evita valores nulos
phone = phone.replace(/\D/g, ''); // Elimina todos los caracteres no numéricos
// Elimina prefijos como "+" o "00"
if (phone.startsWith("00")) {
phone = phone.substring(2); // Elimina "00" si está en formato internacional
} else if (phone.startsWith("+")) {
phone = phone.substring(1); // Elimina "+"
}
// Función para determinar el país basado en el prefijo
function determineCountry(phoneNumber) {
let country;
// Comprueba los códigos internacionales
if (phoneNumber.startsWith("54")) {
country = "Argentina";
} else if (phoneNumber.startsWith("598")) { // Uruguay tiene un prefijo de 3 dígitos
country = "Uruguay";
} else if (phoneNumber.startsWith("52")) {
country = "Mexico";
} else if (phoneNumber.startsWith("1")) { // USA y Canadá
country = "USA";
} else {
country = "UNKNOWN"; // Por defecto
}
return country;
}
// Determina el país y guarda el resultado
let countryfinal = determineCountry(phone);
// Establece la variable 'country' en Typebot
setVariable('country', countryfinal);
// Depuración para verificar los datos
console.log("Phone:", phone); // Muestra el número limpio
console.log("Country:", countryfinal); // Muestra el país detectado
let phone = {{Phone}}.replace(/\D/g, ""); let countryCode; if (phone.startsWith("+")) { phone = phone.substring(1); } function determineCountry(phoneNumber) { let country; if (phoneNumber.startsWith("54")) { country = "Argentina"; } else if (phoneNumber.startsWith("59")) { country = "Uruguay"; } else if (phoneNumber.startsWith("52")) { country = "Mexico"; } else if (phoneNumber.startsWith("1")) { country = "USA"; } else { country = "UNKNOWN"; } return country; } return determineCountry(phone);