我已经尽了一切努力,但我似乎无法解决这个问题。我有一个微软团队自动助理,并且分配了多个菜单选项。我可以加载主号码的菜单选项,但某些菜单选项有自己的呼叫流程菜单选项,而呼叫流程菜单选项又有自己的菜单选项。
它的布局是这样的:
Main number:
0 - Operator
1 - Department A:
0 - Operator
1 - Group A1
2 - Group A2
3 - Department B:
0 - Operator
1 - Group B1
2 - Group B2
3 - Department C:
0 - Operator
1 - Group C1
* - Repeat Menu
# - Previous Menu
* - Repeat Menu
# - Previous Menu
* - Repeat Menu
# - Previous Menu
2 - Department D
3 - Department E
* - Repeat Menu
# - Previous Menu
当然,真实的数据还有更多的嵌套菜单。每个菜单最多可以有 12 个选项,0-9 带 * 和 #。在不知道这些菜单有多深的情况下,有没有办法迭代选项和子选项?
以下代码是我必须获得主要调用流程选项的代码,我只是无法找出一种方法来获取每个选项并在不知道子级别总数的情况下展开子菜单选项。
function addMenuOption {
param(
[string]$Key,
[string]$Action,
[string]$VoiceResponse,
[string]$callTarget,
[string]$ID,
[string]$autoAttendant
)
process {
if ($Action -eq "TransferCallToOperator") {
$Key = 0
$VoiceResponse = "Operator"
$callTarget = "Operator"
$ID = "Operator"
}
$newMenuOption = [PSCustomObject]@{
Key = $Key
Action = $Action
VoiceResponses = $VoiceResponses
CallTarget = $callTarget
ID = $ID
AutoAttendant = $autoAttendant
}
return $newMenuOption
}
}
$allAttendants = Get-CsAutoAttendant
$callTree=@()
$rootAttendant = $allAttendants | Where-Object {$_.Name -like "*AA Georgian Top*"}
$menuOptions = @()
#$parent = $autoAttendant.Name
$rootAttendant.DefaultCallFlow.Menu.MenuOptions | ForEach-Object {
$AutoAttendant = $rootAttendant.Name
$targetID = $_.CallTarget.Id
$CallTarget = ($allAttendants | Where-Object {$_.ApplicationInstances -eq $targetID} | Select-Object -ExpandProperty Name)
$newOption = addMenuOption -key ($_.DtmfResponse).ToString().Substring(4) -Action ($_.Action) -VoiceResponses ($_.VoiceResponses) -callTarget $CallTarget -ID ($targetID) -autoAttendant $AutoAttendant
$menuOptions += $newOption
}
$callTree += $menuOptions
$callTree | ft
理想情况下,如果 CallTarget 和 AutoAttendant 相同,则脚本不会尝试查找子菜单。对于唯一的 CallTargets,我尝试迭代每个目标,然后迭代每个后续菜单。
我建议使用一个类,其中 $option 是菜单数组,$submenu 是子菜单。
class Menu {
[Menu[]] $options
[Menu] $submenu
}