Monday 13 April 2020

Microsoft Teams basic Call Centre dashboard

      As of today, the Microsoft Calling API is not yet available meaning a call centre dashboard is not possible, making it a roadblock for any small and medium businesses. In the wake of the Corona virus a business found itself in a delicate situation where working from home was a necessity but it's call centre was stuck on an old on-prem queue system. Business however placed workers health above dashboards and went ahead with Microsoft Teams, at least temporarily to allow working from home.

It's super easy to setup a call centre with Microsoft phone number or an SBC provider 



How to do it? 

Using PowerShell Universal dashboard (https://universaldashboard.io/) we can use the existing Skype Online commandlets and build a dashboard.

First you will need to create a script to pull the data for each queue.


[Create a secure string to host your password - this is the easy way to get around storing the credentials. How to: https://www.pdq.com/blog/secure-password-with-powershell-encrypting-credentials-part-1/]

$pass = cat C:\temp\Password.txt | ConvertTo-SecureString -Force
$mycred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "teams.dashboard@XXXXX.XXXX",$pass

[Now let's connect to "Cloud"]
$sfbsession = New-CsOnlineSession -Credential $mycred
Import-PSSession $sfbsession -AllowClobber -verbose:$false | Out-Null
            $custservice = Get-CsCallQueue -Identity xxxIDENTITY ID OF QUEUExxx | Select-Object -ExpandProperty Statistics | Select-Object -ExpandProperty StatValue
            $commercial= Get-CsCallQueue -Identity xxxIDENTITY ID OF QUEUExxx | Select-Object -ExpandProperty Statistics | Select-Object -ExpandProperty StatValue
            $sales = Get-CsCallQueue -Identity xxxIDENTITY ID OF QUEUExxx | Select-Object -ExpandProperty Statistics | Select-Object -ExpandProperty StatValue
            


[Store all the above information in a temporary TXT file]
            $data = {
            "Customer service queue size:"
            Write-Output -InputObject $custservice
            "Commercial queue size:"
            Write-Output -InputObject $commercial
            "Sales queue size:"
            Write-Output -InputObject $sales
            } 

            & $data | Out-File c:\temp\data.txt


[This part is optional. This is to display in the dashboard which agent is Opt In or Opt out of taking calls]
            
            (get-CsCallQueue -Identity xxxIDENTITY ID OF QUEUExxx).agents | select @{name="Agent";Expression={Get-CsOnlineUser -Identity $_.objectid | select -expandproperty displayname}}, optin | Export-Csv c:\temp\csagents.csv
            
            (get-CsCallQueue -Identity xxxIDENTITY ID OF QUEUExxx).agents | select @{name="Agent";Expression={Get-CsOnlineUser -Identity $_.objectid | select -expandproperty displayname}}, optin | Export-Csv c:\temp\coagents.csv
            
            (get-CsCallQueue -Identity xxxIDENTITY ID OF QUEUExxx).agents | select @{name="Agent";Expression={Get-CsOnlineUser -Identity $_.objectid | select -expandproperty displayname}}, optin | Export-Csv c:\temp\saagents.csv



[This is also optional. I set this up to make sure the queue is refreshing for moments when there are 0 calls in queue for a long time. To ensure dash is not hung]


            $debugnumber = Get-Random  -Minimum 1 -Maximum 20 
            $debugfile = {
            "Random debug number:"
            Write-Output -InputObject $debugnumber
            }
            & $debugfile | Out-File c:\temp\debug.txt

[This is needed because this being a repetitive task it will error out for too many sessions per user]
            Remove-PSSession $sfbsession


Set up the above to run as a start-up triggered Scheduled Task in Windows with a repetition interval of 2 minutes. Don't set it to lower as the above pull takes apx.1.5 minutes to complete.


To create the dashboard is super easy and to make it even easier here is the code to make it happen for you (there are three queues in this. You can add or remove as you please). Make sure you install the Universal Dashboard component first:


$theme = Get-UDTheme -Name 'Azure'


New-UDDashboard -Title "Teams Call Centre Statistics" -Theme $theme -Content{
New-UDRow -Columns{


New-UDColumn -Size 4 {

New-UdMonitor -Title "Customer Service Waiting Calls" -Type Line -DataPointHistory 30 -RefreshInterval 90 -ChartBackgroundColor '#2E8B57' -ChartBorderColor '#FFFF6B63'  -Endpoint {
            try {
                $text = Get-Content -Path C:\temp\data.txt
                [int]$text[1] | Out-UDMonitorData
            }
            catch {
                0 | Out-UDMonitorData
            }
        }
}

New-UDColumn -Size 4 {

New-UdMonitor -Title "Commercial Waiting Calls" -Type Line -DataPointHistory 30 -RefreshInterval 90 -ChartBackgroundColor '#ffffff' -ChartBorderColor '#FFFF6B63'  -Endpoint {
            try {
                $text = Get-Content -Path C:\temp\data.txt
                [int]$text[3] | Out-UDMonitorData
            }
            catch {
                0 | Out-UDMonitorData
            }
        }

}

New-UDColumn -Size 4 {

New-UdMonitor -Title "Sales Waiting Calls" -Type Line -DataPointHistory 30 -RefreshInterval 90 -ChartBackgroundColor '#FF8C00' -ChartBorderColor '#FFFF6B63'  -Endpoint {
            try {
                $text = Get-Content -Path C:\temp\data.txt
                [int]$text[5] | Out-UDMonitorData
            }
            catch {
                0 | Out-UDMonitorData
            }
        }
}
}



New-UDRow {
            
            New-UDColumn -size 4 {
                New-UDGrid -Title "Customer Service" -RefreshInterval 90 -Endpoint {
                   Import-Csv -Path C:\temp\csagents.csv | Out-UDGridData
                }
            }

            New-UDColumn -size 4 {
                New-UDGrid -Title "Commercial Service" -RefreshInterval 90 -Endpoint {
                   Import-Csv -Path C:\temp\coagents.csv | Out-UDGridData
                }
            }

            New-UDColumn -size 4 {
                New-UDGrid -Title "Sales Service" -RefreshInterval 90 -Endpoint {
                   Import-Csv -Path C:\temp\saagents.csv | Out-UDGridData
                }
            }

}


New-UDRow -Columns{


New-UDColumn -Size 4 {

New-UdMonitor -Title "Debug Graph" -Type Line -DataPointHistory 30 -RefreshInterval 90 -ChartBackgroundColor '#2E8B57' -ChartBorderColor '#FFFF6B63'  -Endpoint {
            try {
                $text = Get-Content -Path C:\temp\debug.txt
                [int]$text[1] | Out-UDMonitorData
            }
            catch {
                0 | Out-UDMonitorData
            }
        }


}

}
}


 To start the dashboard you need to create a third script:

Import-Module UniversalDashboard
Start-UDDashboard -Port 1000 -FilePath "C:\temp\dash.ps1" -AutoReload




I have setup the above also as a start-up task in Windows. All the above should result in this:




This should keep any small business happy. Enjoy!