Dirija las llamadas entrantes de forma dinámica en función del Identificador de Llamadas, el DID y la hora del día.
Este script permite redirigir las llamadas entrantes en función de criterios específicos como la hora del día, el Identificador de Llamada o el DID. Se activa cuando se recibe una llamada en una troncal y redirige la llamada a un destino configurado.
Cómo Configurar el Script de Enrutamiento de Llamadas Basado en el Tiempo
- Vaya a la Consola de Administración > Integraciones > Scripts de llamada.
- Agregue desde la Tienda y seleccione “Time Base Call Routing“.
- Asigne un nombre a la secuencia de comandos para facilitar su identificación.
- Ejecute este script al recibir una llamada en una troncal.
- Seleccione la troncal en la que se interceptarán las llamadas entrantes.
- Por defecto el script viene con horas predefinidas que pueden ser cambiadas por las suyas modificando / agregando / eliminando valores del horario.
- { DayOfWeek.Monday, new Schedule.PeriodOfDay(TimeSpan.FromHours(17.5), TimeSpan.FromHours(24))
- El script también acepta llamadas de todos los DIDs / Identificadores de Llamada ya que las variables DIDs / Identificadores de Llamada contienen el * donde pueden ser cambiadas para contener DIDs específicos e identificadores de llamada.
- Cambie 801 en la cadena constante DestinationDN = “801”; con su destino seleccionado.
Por qué Utilizar Este Script
- Enrutamiento en función del tiempo: Desvíe automáticamente las llamadas a destinos específicos en función de su horario laboral.
- Manejo específico de la llamada: Genere reglas de enrutamiento únicas para Identificadores de Llamada o DIDs importantes.
- Administración eficiente de las llamadas: Reduzca las intervenciones manuales automatizando el enrutamiento de llamadas para fuera de horario o por criterios específicos.
Script de Ejemplo
¡EXENCIÓN DE RESPONSABILIDAD! Este script es solo de referencia. Para obtener la última versión, descárguela de la tienda.
Script: Interceptar Llamadas Entrantes
/*
* Time Base Call Routing - Use code with caution!
* Calls will be intercepted and redirected to the specified DestinationDN during the following times:
* Monday to Sunday: 5:30 PM to 7:00 AM
* The current destination DN is set to "801" modify destination to any system extension or extension you want.
*
* INSTRUCTIONS
* - Configure Date & Time (Line 31)
* - Change the destination DN, and modify the value of the constant DestinationDN to any destination you want to route call (Line 26).
*/
#nullable disable
using CallFlow;
using System;
using System.Threading;
using System.Threading.Tasks;
using TCX.Configuration;
using TCX.PBXAPI;
using System.Collections.Generic;
using System.Linq;
using CallFlow.CFD;
namespace interceptcall
{
public class InterceptInboundCall : ScriptBase
{
// The destination DN to which the call will be redirected
const string DestinationDN = "801";
// Define a schedule for when calls should be intercepted
static readonly Schedule schedule = new Schedule(RuleHoursType.SpecificHours)
{
{ DayOfWeek.Monday, new Schedule.PeriodOfDay(TimeSpan.FromHours(17.5), TimeSpan.FromHours(24)) },
{ DayOfWeek.Monday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(7)) },
{ DayOfWeek.Tuesday, new Schedule.PeriodOfDay(TimeSpan.FromHours(17.5), TimeSpan.FromHours(24)) },
{ DayOfWeek.Tuesday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(7)) },
{ DayOfWeek.Wednesday, new Schedule.PeriodOfDay(TimeSpan.FromHours(17.5), TimeSpan.FromHours(24)) },
{ DayOfWeek.Wednesday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(7)) },
{ DayOfWeek.Thursday, new Schedule.PeriodOfDay(TimeSpan.FromHours(17.5), TimeSpan.FromHours(24)) },
{ DayOfWeek.Thursday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(7)) },
{ DayOfWeek.Friday, new Schedule.PeriodOfDay(TimeSpan.FromHours(17.5), TimeSpan.FromHours(24)) },
{ DayOfWeek.Friday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(7)) },
{ DayOfWeek.Saturday, new Schedule.PeriodOfDay(TimeSpan.FromHours(17.5), TimeSpan.FromHours(24)) },
{ DayOfWeek.Saturday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(7)) },
{ DayOfWeek.Sunday, new Schedule.PeriodOfDay(TimeSpan.FromHours(17.5), TimeSpan.FromHours(24)) },
{ DayOfWeek.Sunday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(7)) }
};
public override async void Start()
{
// Handle calls as a detached task, catching all exceptions.
try
{
await Task.Run(async () =>
{
try
{
MyCall.Debug($"Script start delay: {DateTime.UtcNow - MyCall.LastChangeStatus}");
MyCall.Debug($"Incoming connection {MyCall} from {MyCall.Caller}");
bool intercepted = false;
var ps = MyCall.PS as PhoneSystem;
if (MyCall.Caller.DN is ExternalLine externalLine)
{
var DIDNumber = MyCall.Caller["inbound_did"];
var CallerID = MyCall.Caller.CallerID;
var currentTime = externalLine.Now(out var utc, out var timezone, out var groupmode);
// Intercept calls during the specified schedule
if (schedule.IsActiveTime(currentTime))
{
string[] DIDs = { "*" }; // Allow all DIDs
string[] Callers = { "*" }; // Allow all Callers
var destination_struct = new DestinationStruct(ps.GetDNByNumber(DestinationDN));
// Check if the call's DID and CallerID match the interception criteria
if ((DIDs.Contains(DIDNumber) || DIDs.Contains("*")) &&
(Callers.Contains(CallerID) || Callers.Contains("*")))
{
try
{
var result = await MyCall.RouteToAsync(destination_struct);
MyCall.Info($"{CallerID} -> {DIDNumber} has been redirected to {DestinationDN} ({result})");
intercepted = true;
}
catch (Exception ex)
{
MyCall.Info($"{CallerID} -> {DIDNumber}: interception failed. '{DestinationDN}' is not reachable: {ex}");
}
}
else
{
MyCall.Info($"{CallerID} -> {DIDNumber}@{currentTime}: Default CallerID/DID based routing will be applied");
}
}
}
MyCall.Return(intercepted);
}
catch (Exception ex)
{
MyCall.Error($"Script execution failed: {ex}");
MyCall.Return(false);
}
});
}
catch (Exception ex)
{
MyCall.Error($"Task execution failed: {ex}");
MyCall.Return(false);
}
}
}
}
Manténgase Informado
No olvide participar en nuestro Foro y seguirnos en X y LinkedIn para estar al tanto de las novedades de 3CX.



