Business / TCO365 / Technical

Using Teams Phone System and Shifts

One of the scenarios which I came across last week was meeting the requirements of enabling automatic on-call scenario for a customer. This was focused around nurses and therefore the on-call system needed to use the mobile phone number of the user due to the potential of rural areas where data calls aren’t suitable.

The great thing was the customer was using Microsoft Shifts and with their transition to the Microsoft Teams phone system wanted to implement a on-call capability.

Enter Microsoft Flow and Azure Automation two tools which can enable this automation.

The below diagram outlines how this achieved. A simple flow runs every 6 hours. This flow has two variables, one is an empty phone number which gets populated based upon the user’s azure active directory mobile number. The other is the ID of the call queue which is setup to automatically forward calls to an external PSTN number. Azure automation leverages the Microsoft Teams PowerShell script to programmatically update this call queue when sent the parameters from the flow.

So why use Flow? Well, the benefit of this flow is, it can be used as a building block for multiple on call scenarios, say you have on-call requirements for each site or potential geo-zones. Cloning this flow and injecting different variables would enable this functionality, without having to change the Azure Automation build. Flow also provides error logging by waiting for the automation job to run and reporting back on the success or failure and this could be posted as an email, API or posted to a teams channel for visibility.

One of the important parts of Teams PowerShell is it only accepts numbers done in E.123 format, which means numbers need to be cleaned of both whitespaces and in the case of Australian mobiles drop the leading 0 and add +61. This is where PowerShell shines, by using a simple IF statement, you can update and clean the number to meet the correct format, the cleaning solution could be further improved, but this will get the solution working.

         [Parameter (Mandatory= $true)]
         [String] $CallQueue = "",
         [Parameter (Mandatory = $true)]
         [String] $usernumber = ""
#Static Variables
$credname = "PowerAutomate"

#Clean Number and remove white spaces and drop leading Zero, if number is either 04 or +61 fix number.
If($usernumber -contains "+"){
    $NumberCleaned = $usernumber -replace ' ', ''
    #write-host "Removed White spaces on +61" $NumberCleaned
} else {
    $clean = $usernumber -replace '^0+', '+61'
    #write-host "Added +61" $clean
    $NumberCleaned = $clean -replace ' ', ''
    #write-host "white spaces removed" $NumberCleaned

#Variable constructed for correct teams format which is tel:+61 universal number
$tel = "tel:"
$number = $tel + $NumberCleaned

# Authenication to Teams
$Cred = Get-AutomationPSCredential -Name $credname
Connect-MicrosoftTeams -Credential $Cred

#Set Queue Number Redirection
Set-CsCallQueue -identity $CallQueue -TimeOutActionTarget $number

This solution enables a very critical functions for business which have on-call requirements and advertise direct numbers for customers. The good news is Microsoft can achieve this from almost any system by using Flow and Azure Automation. It could be a 3rd party using JSON or even a Microsoft Bot enabling end users to update then number on the fly.

A Solution architect who focuses on designing solutions leveraging telecommunication networks and Microsoft technologies. A strong focus on automating solutions to help businesses focus on their business instead of technology. Enjoys working in the start-up world where business environments are dynamic and skills in developing new business units such as managed services from design, implementation and lifecycle.
Total post: 14

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: