Set PBX departments to in-office, out-of-office, break, or holiday with dial codes.

This script enforces specific hours for all departments in the PBX, replacing the deprecated office/out-of-office dial codes in Version 20. When you dial the assigned code, it sets all departments to in-office, out-of-office, break time, or holiday mode. Incoming external calls will route based on the enforced department hours.

System Owner/Admin can create a dial code using the script available from the store and set a dial code for each script.

How to Set Up the Script to Reset Department Routes to Default

  1. Go to Admin Console > Integrations > Call Scripts.
  2. Add from Store and select Reset Departments Routes to Default.
  3. Name the script.
  4. Run this script when a user dials a dial code.
  5. Add a dial code of your choice – for example 56.
  6. Select System Wide.

How to Set Up Other Scripts for In, Out, Holiday, Break

  1. Follow the same procedure as above.
  2. In step 3, use a unique name for each script (e.g., “setdepartmentinoffice”).
  3. In step 5, assign a unique dial code for each script – 57 for in-office, 58 for out-of-office etc.

Things to Know

  • This script replaces the deprecated office/out-of-office dial codes in Version 20.
  • Any user may dial the assigned code to force departments to in-office, out-of-office, holiday, or break mode.
  • The script demonstrates what can be done with Call Processing Scripts and may be modified for additional functionality.

Example Script

DISCLAIMER! This script is for reference purposes only. For the latest version, download from the store.

Script: Reset all departments to default hours operation


#nullable disable
using CallFlow;
using System;
using System.Threading.Tasks;
using TCX.Configuration;
using System.Linq;
using CallFlow.CFD;
using System.Collections.Generic;
namespace dummy
{
public class ForcePBXDefaultHours : ScriptBase
{
public override async Task StartAsync()
{
var ps = MyCall.PS as PhoneSystem;
if(MyCall.Caller.DN is Extension && MyCall.ReferredByDN is null)
{
//for all departments
ps.GetAll().Extract(x=>x.AllowCallService)
.Select(x=>
{
try
{
//remove overiides of current hours
x.OverrideExpiresAt = x.Now(out var utc, out var timezone, out var groupmode);
x.CurrentGroupHours = GroupHoursMode.Default;
MyCall.Info($"{x.Name} turn off office hours override");
return x;
}
catch
{
//just ignore it
return null;
}
}).OfType().OMSave();
try
{
var result = await MyCall.AssureMedia()
.ContinueWith(_ => MyCall.PlayPrompt(null, [ "OHOVERRIDE_OFF" ], PlayPromptOptions.Blocked), TaskContinuationOptions.OnlyOnRanToCompletion)
.Unwrap();
}
catch
{
//nothing to report. changes are applied
}
return true;
}
return false;
}
}
}

Script: Force all departments in office


#nullable disable
using CallFlow;
using System;
using System.Threading.Tasks;
using TCX.Configuration;
using System.Linq;
using CallFlow.CFD;
using System.Collections.Generic;
namespace dummy
{
public class ForceOpened : ScriptBase
{
public override async Task StartAsync()
{
var ps = MyCall.PS as PhoneSystem;
if(MyCall.Caller.DN is Extension && MyCall.ReferredByDN is null)
{
//for all departments
ps.GetAll().Extract(x=>x.AllowCallService)
.Select(x=>
{
try
{
//force office hours until midnight
var groupCurrentTime = x.Now(out var utc, out var timezone, out var groupmode);
x.OverrideExpiresAt = (groupCurrentTime+TimeSpan.FromDays(1)).Date;
x.CurrentGroupHours = GroupHoursMode.ForceOpened;
MyCall.Info($"{x.Name} set to '{x.CurrentGroupHours}' until {x.OverrideExpiresAt}, timezone={timezone}, groupmode={groupmode}");
return x;
}
catch
{
//just ignore it
return null;
}
}).OfType().OMSave();
try
{
var result = await MyCall.AssureMedia()
.ContinueWith(_ => MyCall.PlayPrompt(null, [ "OHOVERRIDE_IN" ], PlayPromptOptions.Blocked), TaskContinuationOptions.OnlyOnRanToCompletion)
.Unwrap();
}
catch
{
//nothing to report. changes are applied
}
return true;
}
return false;
}
}
}

Script: Force all departments out of office


#nullable disable
using CallFlow;
using System;
using System.Threading.Tasks;
using TCX.Configuration;
using System.Linq;
using CallFlow.CFD;
using System.Collections.Generic;
namespace dummy
{
public class ForceClosed : ScriptBase
{
public override async Task StartAsync()
{
var ps = MyCall.PS as PhoneSystem;
if(MyCall.Caller.DN is Extension && MyCall.ReferredByDN is null)
{
//for all departments
ps.GetAll().Extract(x=>x.AllowCallService)
.Select(x=>
{
try
{
//force out of office hours until midnight
var groupCurrentTime = x.Now(out var utc, out var timezone, out var groupmode);
x.OverrideExpiresAt = (groupCurrentTime+TimeSpan.FromDays(1)).Date;
x.CurrentGroupHours = GroupHoursMode.ForceClosed;
MyCall.Info($"{x.Name} set to '{x.CurrentGroupHours}' until {x.OverrideExpiresAt}, timezone={timezone}, groupmode={groupmode}");
return x;
}
catch
{
//just ignore it
return null;
}
}).OfType().OMSave();
try
{
var result = await MyCall.AssureMedia()
.ContinueWith(_ => MyCall.PlayPrompt(null, [ "OHOVERRIDE_OUT"], PlayPromptOptions.Blocked), TaskContinuationOptions.OnlyOnRanToCompletion)
.Unwrap();
}
catch
{
//nothing to report. changes are applied
}
return true;
}
return false;
}
}
}

Script: Force all departments break time


#nullable disable
using CallFlow;
using System;
using System.Threading.Tasks;
using TCX.Configuration;
using System.Linq;
using CallFlow.CFD;
using System.Collections.Generic;
namespace dummy
{
public class ForceBreak : ScriptBase
{
public override async Task StartAsync()
{
var ps = MyCall.PS as PhoneSystem;
if(MyCall.Caller.DN is Extension && MyCall.ReferredByDN is null)
{
//for all departments
ps.GetAll().Extract(x=>x.AllowCallService)
.Select(x=>
{
try
{
//force breaktime until midnight
var groupCurrentTime = x.Now(out var utc, out var timezone, out var groupmode);
x.OverrideExpiresAt = (groupCurrentTime+TimeSpan.FromDays(1)).Date;
x.CurrentGroupHours = GroupHoursMode.ForceBreak;
MyCall.Info($"{x.Name} set to '{x.CurrentGroupHours}' until {x.OverrideExpiresAt}, timezone={timezone}, groupmode={groupmode}");
return x;
}
catch
{
//just ignore it
return null;
}
}).OfType().OMSave();
try
{
var result = await MyCall.AssureMedia()
//this sample respnds with system prompt "Away status set".
.ContinueWith(_ => MyCall.PlayPrompt(null, [ "ST_AWAY_SET"], PlayPromptOptions.Blocked), TaskContinuationOptions.OnlyOnRanToCompletion)
.Unwrap();
}
catch
{
//nothing to report. changes are applied
}
return true;
}
return false;
}
}
}

Script: Force all departments holiday time


#nullable disable
using CallFlow;
using System;
using System.Threading.Tasks;
using TCX.Configuration;
using System.Linq;
using CallFlow.CFD;
using System.Collections.Generic;
namespace dummy
{
public class ForceHoliday : ScriptBase
{
public override async Task StartAsync()
{
var ps = MyCall.PS as PhoneSystem;
if(MyCall.Caller.DN is Extension && MyCall.ReferredByDN is null)
{
//for all departments
ps.GetAll().Extract(x=>x.AllowCallService)
.Select(x=>
{
try
{
//force hiliday until midnight
var groupCurrentTime = x.Now(out var utc, out var timezone, out var groupmode);
x.OverrideExpiresAt = (groupCurrentTime+TimeSpan.FromDays(1)).Date;
x.CurrentGroupHours = GroupHoursMode.ForceHoliday;
MyCall.Info($"{x.Name} set to '{x.CurrentGroupHours}' until {x.OverrideExpiresAt}, timezone={timezone}, groupmode={groupmode}");
return x;
}
catch
{
//just ignore it
return null;
}
}).OfType().OMSave();
try
{
var result = await MyCall.AssureMedia()
//this sample reuse "Out of office status set" system prompt. There is no system prompt specific for holiday override
.ContinueWith(_ => MyCall.PlayPrompt(null, [ "ST_OUTOFFICE_SET"], PlayPromptOptions.Blocked), TaskContinuationOptions.OnlyOnRanToCompletion)
.Unwrap();
}
catch
{
//nothing to report. changes are applied
}
return true;
}
return false;
}
}
}

 

Last Updated
This document was last updated 27 November 2024
https://www.3cx.com/blog/call-flow-scripts/force-pbx-hours/Â