Direct incoming calls automatically based on the caller’s number to specific destinations.
This script allows you to direct incoming calls to specific destinations based on the caller’s phone number. It checks a list of numbers stored in a file, and routes matching calls accordingly. This is useful for prioritizing VIP customers, blocking spam, or ensuring important calls reach the right department.
How the Inbound Caller ID Routing Script Works
- Reads a file named contacts.csv containing caller phone numbers.
- Compares the incoming caller ID with the numbers in the file.
- If there’s a match, the call is forwarded to the predefined extension (e.g., Extension 114).
- If there’s no match, the call may be dropped depending on the configuration.
How to Setup the Inbound Caller ID Routing Script
- Go to Admin Console > Integrations > Call Scripts.
- Select Add from Store and choose Inbound Caller ID Routing.
- Assign a name for easy identification.
- Configure the script to run when receiving a call on a trunk or when a specific DID is called.
- Choose the trunk or DID where calls should be intercepted.
- Set the destination variable to define where calls should be routed.
- Upload a CSV or TXT file containing caller numbers separated by commas (e.g., +123456,+9827262)
How Your Agents Can Use The Script
- Update the contacts.csv file anytime to change routing rules.
- Ensure the destination is correctly configured to forward calls to the right place (e.g., voicemail, an extension, or a queue).
- If needed, change the CSV filename or destination variable within the script.
Why Use This Script?
- Automate Call Routing – Direct calls instantly based on caller ID.
- Flexible and Easy to Update – Modify routing by updating a simple file.
- Improve Call Management – Prioritize VIPs, block spam, or direct calls to the right team.
How It Works Behind the Scenes
This script processes incoming calls by:
- Checking if the call is inbound using the ExternalLine object and IsInbound property.
- Retrieving the stored caller ID list by using GetPropertyValue to locate the correct file path.
- Reading the file with ReadLines to access caller IDs.
- Matching the caller’s number using Regex.
- Routing the call to the appropriate destination using DestinationStruct and RouteToAsync.
Things to Know
If a Caller ID isn’t found in the list, the call may be dropped (depending on your setup).
Example Script
DISCLAIMER! To see this script v20 U5 is required. This script is for reference purposes only. For the latest version, download from the store.
Script: Available
[Script C#]
#nullable disable
using CallFlow;
using System.Threading.Tasks;
using TCX.Configuration;
using TCX.PBXAPI;
using System.IO;
using System.Text.RegularExpressions;
namespace dummy
{
public class InterceptInboundCall : ScriptBase
{
//Specify here your csv filename with callerid list that needs to be redirected
const string csvFileName = "contacts.csv";
//Change the value of the below variable to a destination of your choosing.
//I.e for Voicemail of extension 101 replace Extension.114. with VoiceMail.101.
const string destination = "Extension.114.";
public override async Task StartAsync()
{
if (MyCall.Caller.DN is ExternalLine externalLine && MyCall.IsInbound)
{
var DIDNumber = MyCall.Caller.CalledNumber;
var CallerID = MyCall.Caller.CallerID;
var matched = false;
var cfdAppName = MyCall.CallHandler.MyDN.GetPropertyValue("CF_APP_NAME");
string cfdPath;
if (!string.IsNullOrEmpty(cfdAppName))
cfdPath = cfdAppName.Split('.')[0];
else
cfdPath = MyCall.CallHandler.MyDN.Number.Split('.')[0];
var csvPath = System.IO.Path.Combine(MyCall.PS.GetParameterValue("IVRPROMPTPATH"), "Callflows", cfdPath, csvFileName);
var lines = File.ReadLines(csvPath);
foreach (var line in lines)
{
var matchCollection = new Regex("([\\+]?[0-9]+)").Matches(line);
if (matched == true)
{
break;
}
foreach (Match match in matchCollection)
{
if (CallerID == match.Value)
{
matched = true;
break;
}
}
}
var has_valid_destination = DestinationStruct.TryParse(destination, out var destination_struct);
if (has_valid_destination && matched)
{
var result = await MyCall.RouteToAsync(destination_struct);
MyCall.Info($"{CallerID}->{DIDNumber} has been redirected to {destination} ({result}");
return true;
}
}
return false;
}
}
}
More Call Flow Scripts Available
We have a collection of call flow scripts on our website. Check them out and see how you can automate 3CX to fit your needs.
No Comment! Be the first one.