Got it.
Ich hab es jetzt selber hinbekommen, falls es einer brauchen sollte:
/*
* 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).
*/
/*
* Script Anpassung by OpIT GmbH
* Ausnahme Liste hinzugefügt
* static readonly string[] ExcludedDIDs = { "DID Nummer", "DID Nummer" };
* Dort die Externe und Interne Rufnummer angeben
*/
#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<InterceptInboundCall>
{
// The destination DN to which the call will be redirected
const string DestinationDN = "496";
// List of DIDs that should not be intercepted (add your DIDs here)
static readonly string[] ExcludedDIDs = { "+4312345492", "492" };
// 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.0), TimeSpan.FromHours(24)) },
{ DayOfWeek.Monday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(7.30)) },
{ DayOfWeek.Monday, new Schedule.PeriodOfDay(TimeSpan.FromHours(12), TimeSpan.FromHours(13)) },
{ DayOfWeek.Tuesday, new Schedule.PeriodOfDay(TimeSpan.FromHours(17.0), TimeSpan.FromHours(24)) },
{ DayOfWeek.Tuesday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(7.30)) },
{ DayOfWeek.Tuesday, new Schedule.PeriodOfDay(TimeSpan.FromHours(12), TimeSpan.FromHours(13)) },
{ DayOfWeek.Wednesday, new Schedule.PeriodOfDay(TimeSpan.FromHours(17.0), TimeSpan.FromHours(24)) },
{ DayOfWeek.Wednesday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(7.30)) },
{ DayOfWeek.Wednesday, new Schedule.PeriodOfDay(TimeSpan.FromHours(12), TimeSpan.FromHours(13)) },
{ DayOfWeek.Thursday, new Schedule.PeriodOfDay(TimeSpan.FromHours(17.0), TimeSpan.FromHours(24)) },
{ DayOfWeek.Thursday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(7.30)) },
{ DayOfWeek.Thursday, new Schedule.PeriodOfDay(TimeSpan.FromHours(12), TimeSpan.FromHours(13)) },
{ DayOfWeek.Friday, new Schedule.PeriodOfDay(TimeSpan.FromHours(12.0), TimeSpan.FromHours(24)) },
{ DayOfWeek.Friday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(8.0)) },
{ DayOfWeek.Saturday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(24)) },
{ DayOfWeek.Sunday, new Schedule.PeriodOfDay(TimeSpan.FromHours(0), TimeSpan.FromHours(24)) },
};
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);
// Check if the DID should be excluded
bool isExcludedDID = ExcludedDIDs.Contains(DIDNumber);
if (schedule.IsActiveTime(currentTime) && !isExcludedDID)
{
string[] AllowedCallers = { "*" }; // Allow all Callers
var destination_struct = new DestinationStruct(ps.GetDNByNumber(DestinationDN));
// Check if the call's DID and CallerID match the interception criteria
if (AllowedCallers.Contains(CallerID) || AllowedCallers.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);
}
}
}
}