blog.icewolf.ch

Let's talk about IT!
posts - 2204, comments - 295, trackbacks - 0

My Links

Archives

Post Categories

icewolf

Microsoft Teams routing calls to unassigned Numbers

Hi All,

In my M365 Tenant i use Direct Routing from Sunrise, a Telco Provider here in Switzerland.
I own a Numberrange with 10 Number +41 21 555 39 70-79.

If i call with my Mobilephone to a Number, that is not assignet to a User, Callflow or Autoattendant, i get an Anouncement from the Provider (Sunrise) that the Number is not active. This is because the Session Border Controller at the Provider receives a SIP 404 Not Found.

If i call the same number in my own Tenant, Teams is ringing and ringing. Now here comes the handling of unasigned numbers into the Game.

Routing calls to unassigned numbers


There are two possibilities for handling unassigned Numbers:
  • Announcement Service
  • Route to Auto Attendand or Callqueue

Variant 1) Announcement Service

######################################################################
# Variant 1) Announcement Service
######################################################################
Get-CsTeamsUnassignedNumberTreatment
$Content = Get-Content "E:\Temp\ss-noservice.mp3" -Encoding byte -ReadCount 0
$AudioFile = Import-CsOnlineAudioFile -FileName "E:\Temp\ss-noservice.mp3" -Content $Content
$fid = [System.Guid]::Parse($AudioFile.Id)
New-CsTeamsUnassignedNumberTreatment -Identity IcewolfUnasignedNumbers -Pattern "^\+4121555397\d{1}$" -TargetType Announcement -Target $fid.Guid -TreatmentPriority 1


Note:
The custom audio file supported formats are WAV (uncompressed, linear PCM with 8/16/32-bit depth in mono or stereo), WMA (mono only), and MP3.
The audio file content cannot be more than 5 MB.

For the Audio File i used one of the License Free Files from the Website below

Recordings for use in Voicemail, Queues, or Auto Attendants


It takes some time until the Configuration is working. Usually less than 5 Minutes.

If you now call an unasigned Number, the call is forwarded to the Announcement Playback Service, that plays your uploaded Audio File twice. But the Call is then not ended. The Caller has to hang up.

If you call from External you now also hear this Announcement instead of the Anouncement from the Provider.


 Variant 2) Auto Attendand

First i remove the Settings from Variant 1

Get-CsTeamsUnassignedNumberTreatment
Remove-CsTeamsUnassignedNumberTreatment -Identity IcewolfUnasignedNumbers
Get-CsTeamsUnassignedNumberTreatment



######################################################################
# Variant 2) Auto Attendand
######################################################################
######################################################################
# Create Resource Account
######################################################################
#ApplicationID
#Auto Attendant: ce933385-9390-45d1-9512-c8d228074e07
#Call Queue: 11cd3e2e-fccb-42ad-ad00-878b93575e07
#New-CsOnlineApplicationInstance
#https://docs.microsoft.com/en-us/powershell/module/skype/new-csonlineapplicationinstance?view=skype-ps

$UPN = "AAUnasignedNumber@icewolf.ch"
$DisplayName = $UPN.Split("@")[0]
New-CsOnlineApplicationInstance -UserPrincipalName $UPN -DisplayName $DisplayName -ApplicationId "ce933385-9390-45d1-9512-c8d228074e07"



Then i set the Location of the Account and add the Phone System Virtual License to it. Note that i use the Microsoft Graph PowerShell here.

######################################################################
# Assign PhoneSystem Virtual Licence and Location
######################################################################
#Configure Microsoft 365 user account properties with PowerShell
#https://docs.microsoft.com/en-us/microsoft-365/enterprise/configure-user-account-properties-with-microsoft-365-powershell?view=o365-worldwide

#Assign PhoneSystem Virtual Licence and Location
Connect-MgGraph -Scopes User.ReadWrite.All, Directory.ReadWrite.All
Update-MgUser -UserId $UPN -UsageLocation "CH"
Set-MgUserLicense -UserId $UPN -AddLicenses @{SkuId = '440eaaa8-b3e0-484b-a8be-62870b9ba70a'} -RemoveLicenses @()


After assigning the License you have to wait until Teams notices and you can set the Phone Number (4-5 Minutes worked in my case - you might adapt to your environement).

######################################################################
# Assign Number to Resource Account
######################################################################
$Error.Clear()
Write-Host "Waiting 240 Seconds"
Start-Sleep -Seconds 240
Set-CsOnlineApplicationInstance -Identity $UPN -OnpremPhoneNumber +41215553979

If ($Error -ne $null)
{
    Write-Host "Waiting 60 Seconds"
    Start-Sleep -Seconds 60
    Set-CsOnlineApplicationInstance -Identity $UPN -OnpremPhoneNumber +41215553979
}


Now it's time to create the actual Autoattendant

######################################################################
# Upload AudioFile
######################################################################
#Upload Audio File Import-CsOnlineAudioFile
$Content = Get-Content "E:\Temp\ss-noservice.mp3" -Encoding byte -ReadCount 0
$AudioFile = Import-CsOnlineAudioFile -ApplicationId "HuntGroup" -FileName "ss-noservice.mp3" -Content $content
$AudioFile

######################################################################
#Default Call Flow
######################################################################
#New-CsAutoAttendantCallFlow
#https://docs.microsoft.com/en-us/powershell/module/skype/new-csautoattendantcallflow?view=skype-ps

#Menu Disconnect Call
$menuOption = New-CsAutoAttendantMenuOption -Action DisconnectCall -DtmfResponse Automatic

#Default Call Flow
$AAMenu = New-CsAutoAttendantMenu -Name "Default Menu" -MenuOptions @($menuOption) -DirectorySearchMethod None
$WelcomePrompt = New-CsAutoAttendantPrompt -AudioFilePrompt $AudioFile
$DefaultCallFlow = New-CsAutoAttendantCallFlow -Name "AAUnasignedNumber Default call flow" -Menu $AAMenu -Greetings @($WelcomePrompt)

######################################################################
#Auto Attendant
######################################################################
#New-CsAutoAttendant
#https://docs.microsoft.com/en-us/powershell/module/skype/new-csautoattendant?view=skype-ps

$aaName = "AAUnasignedNumber"
$language = "de-DE"
$TimeZone = "W. Europe Standard Time"
New-CsAutoAttendant -Name $aaName -LanguageId $language -TimeZoneId $TimeZone -DefaultCallFlow $DefaultCallFlow



######################################################################
#Assign ResourceAccount to AutoAttendant
######################################################################
$applicationInstanceId = (Get-CsOnlineApplicationInstance -Identities $upn).ObjectId
$AutoAttendantID = (Get-CsAutoAttendant -NameFilter $DisplayName).Identity
New-CsOnlineApplicationInstanceAssociation -Identities @($applicationInstanceId) -ConfigurationId $AutoAttendantID -ConfigurationType AutoAttendant



Now we finnally set the Unassigned Number Configuration

######################################################################
# UnassignedNumbers
######################################################################
Get-CsTeamsUnassignedNumberTreatment

#Route to Autoattendand or CallQueue
$RAObjectId = (Get-CsOnlineApplicationInstance -Identity $upn).ObjectId
New-CsTeamsUnassignedNumberTreatment -Identity UnassignedNumbers -Pattern "^\+4121555397\d{1}$" -TargetType ResourceAccount -Target $RAObjectId -TreatmentPriority 1



Let's look at the Resource Account


Let's check out the AutoAttendant


Default Call Flow: Play the Audio File  and then disconnect






It takes some time until the configuration is working. Usually less than 5 Minutes.

If i now call an unassigned Number from Teams Client, the Call is redirected to the Autoattendant that plays the Audio File and then Disconnects.

If you call from External you now also hear this Announcement from the Autoattendant instead of the Anouncement from the Provider.




Regards
Andres Bohren


Print | posted on Friday, January 28, 2022 7:53 AM | Filed Under [ PowerShell MicrosoftTeams ]

Powered by:
Powered By Subtext Powered By ASP.NET