Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Param(
[Parameter (Mandatory= $true)]
[String] $autoAttendantName,
[Parameter (Mandatory= $false)]
[String] $HolidayName,
[Parameter (Mandatory= $false)]
[String] $StartDate,
[Parameter (Mandatory= $false)]
[String] $EndDate,
[Parameter (Mandatory= $false)]
[String] $GreetingText,
[Parameter (Mandatory= $false)]
[String] $GreetingFileID,
[Parameter (Mandatory= $false)]
[String] $Choice
)
### Teams AA Administration ###
### Version 1.0 ###
### Author: Alexander Holmeset ###
### Email: alexander.holmeset@gmail.com ###
### Twitter: twitter.com/alexholmeset ###
### Blog: alexholmeset.blog ###
$TenantId = 'xxxxxxxxxxxxx'
$ClientID = 'xxxxxxx'
$ClientSecret = Get-AutomationVariable -Name 'secret'
$Credentials = Get-AutomationPSCredential -Name 'admin'
connect-microsoftteams -Credential $Credentials
function Get-MSGraphAppToken{
<# .SYNOPSIS
Get an app based authentication token required for interacting with Microsoft Graph API
.PARAMETER TenantID
A tenant ID should be provided.
.PARAMETER ClientID
Application ID for an Azure AD application. Uses by default the Microsoft Intune PowerShell application ID.
.PARAMETER ClientSecret
Web application client secret.
.EXAMPLE
# Manually specify username and password to acquire an authentication token:
Get-MSGraphAppToken -TenantID $TenantID -ClientID $ClientID -ClientSecert = $ClientSecret
.NOTES
Author: Jan Ketil Skanke
Contact: @JankeSkanke
Created: 2020-15-03
Updated: 2020-15-03
Version history:
1.0.0 - (2020-03-15) Function created
#>
[CmdletBinding()]
param (
[parameter(Mandatory = $true, HelpMessage = "Your Azure AD Directory ID should be provided")]
[ValidateNotNullOrEmpty()]
[string]$TenantID,
[parameter(Mandatory = $true, HelpMessage = "Application ID for an Azure AD application")]
[ValidateNotNullOrEmpty()]
[string]$ClientID,
[parameter(Mandatory = $true, HelpMessage = "Azure AD Application Client Secret.")]
[ValidateNotNullOrEmpty()]
[string]$ClientSecret
)
Process {
$ErrorActionPreference = "Stop"
# Construct URI
$uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
# Construct Body
$body = @{
client_id = $clientId
scope = "https://graph.microsoft.com/.default"
client_secret = $clientSecret
grant_type = "client_credentials"
}
try {
$MyTokenRequest = Invoke-WebRequest -Method Post -Uri $uri -ContentType "application/x-www-form-urlencoded" -Body $body -UseBasicParsing
$MyToken =($MyTokenRequest.Content | ConvertFrom-Json).access_token
If(!$MyToken){
Write-Warning "Failed to get Graph API access token!"
Exit 1
}
$MyHeader = @{"Authorization" = "Bearer $MyToken" }
}
catch [System.Exception] {
Write-Warning "Failed to get Access Token, Error message: $($_.Exception.Message)"; break
}
return $MyHeader
}
}
$global:Header = Get-MSGraphAppToken -TenantID $TenantId -ClientID $ClientID -ClientSecret $ClientSecret
$AutoAttendantID = (Get-CsAutoAttendant | Where-Object{$_.Name -like "$AutoAttendantName"}).Identity
$autoAttendant = Get-CsAutoAttendant -Identity "$AutoAttendantID"
If($Choice -like "Audio"){
$uri = "https://graph.microsoft.com/v1.0/users/$($credentials.username)/drive/items/$GreetingFileID/content"
$content = Invoke-RestMethod -Method GET -Headers $global:Header -uri $uri -OutFile c:\temp\greeting.wav
$content = Get-Content "C:\temp\greeting.wav" -asbytestream
$audioFile = Import-CsOnlineAudioFile -ApplicationId "OrgAutoAttendant" -FileName "greeting.wav" -Content $content
$GreetingPrompt = New-CsAutoAttendantPrompt -AudioFilePrompt $audioFile
}
if($Choice -like "Text"){
$GreetingPrompt = New-CsAutoAttendantPrompt -TextToSpeechPrompt $GreetingText
}
$StartDate = Get-Date $StartDate -Format "dd/MM/yyyy"
$EndDate = Get-Date $EndDate -Format "dd/MM/yyyy"
$MenuOption = New-CsAutoAttendantMenuOption -Action DisconnectCall -DtmfResponse Automatic
$Menu = New-CsAutoAttendantMenu -Name "$HolidayName Menu" -MenuOptions @($MenuOption)
$CallFlow = New-CsAutoAttendantCallFlow -Name "$HolidayName" -Greetings @($GreetingPrompt) -Menu $Menu
$dtr = New-CsOnlineDateTimeRange -Start $StartDate -End $EndDate
$Schedule = New-CsOnlineSchedule -Name "$HolidayName" -FixedSchedule -DateTimeRanges @($dtr)
$CallHandlingAssociation = New-CsAutoAttendantCallHandlingAssociation -Type Holiday -ScheduleId $Schedule.Id -CallFlowId $CallFlow.Id
$autoAttendant.CallFlows += @($CallFlow)
$autoAttendant.CallHandlingAssociations += @($CallHandlingAssociation)
Set-CsAutoAttendant -Instance $autoAttendant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment