NN.Zisson.psm1
#Region './Private/Get-ZIAccessToken.ps1' 0 function Get-ZiAccessToken { param ( [string]$accessTokenPath = "$env:USERPROFILE\.creds\Zisson\zissonAccessToken.xml" ) if (!(Test-Path $accessTokenPath)) { New-ZiAccessToken } Import-Clixml $accessTokenPath | ConvertFrom-SecureString -AsPlainText } #EndRegion './Private/Get-ZIAccessToken.ps1' 12 #Region './Private/Get-ZiEndpoint.ps1' 0 function Get-ZiEndpoint { [CmdletBinding()] param ( [string]$EndpointPath = "$env:USERPROFILE\.creds\Zisson\zissonEndpoint.xml" ) process { if (!(Test-Path $EndpointPath)) { New-ZiEndpoint } Import-Clixml $EndpointPath } } #EndRegion './Private/Get-ZiEndpoint.ps1' 15 #Region './Public/Get-ZIQueueCalls.ps1' 0 function Get-ZiQueueCalls { param ( [Parameter(Mandatory)][datetime]$startDate, [Parameter(Mandatory)][datetime]$endDate, [int]$queueList ) $splat = @{ "Method" = "GET" "Uri" = "$(Get-ZiEndpoint)/api/simple/QueueCallsAll" "Headers" = @{ "Authorization" = "Basic $(Get-ZiAccessToken)" } "Body" = @{ "start_date" = $startDate "end_date" = $endDate "queue_list" = $queueList } } $result = Invoke-RestMethod @splat $result.QueueCallsAll } #EndRegion './Public/Get-ZIQueueCalls.ps1' 23 #Region './Public/Get-ZIQueueChats.ps1' 0 function Get-ZiQueueChats { param ( [Parameter(Mandatory)][datetime]$startDate, [Parameter(Mandatory)][datetime]$endDate ) $splat = @{ "Method" = "GET" "Uri" = "$(Get-ZiEndpoint)/api/simple/QueueChats" "Headers" = @{ "Authorization" = "Basic $(Get-ZiAccessToken)" } "Body" = @{ "start_date" = $startDate "end_date" = $endDate } } $result = Invoke-RestMethod @splat $result.QueueChats } #EndRegion './Public/Get-ZIQueueChats.ps1' 21 #Region './Public/New-ZiAccessToken.ps1' 0 function New-ZiAccessToken { param ( [string]$accessTokenPath = "$env:USERPROFILE\.creds\Zisson\zissonAccessToken.xml" ) $username = Read-Host "Enter Zisson API username" if (!$username) { Write-Error "Please provide a Zisson API username." -ErrorAction Stop } $passwd = Read-Host "Enter Zisson API password" if (!$passwd) { Write-Error "Please provide a Zisson API password." -ErrorAction Stop } $accessTokenDir = $accessTokenPath.Substring(0, $accessTokenPath.lastIndexOf('\')) if (!(Test-Path $accessTokenDir)) { #Create parent folders of the access token file $null = New-Item -ItemType Directory $accessTokenDir } #Encode credentials to Base64 $text = "$($username):$($passwd)" $bytes = [Text.Encoding]::UTF8.GetBytes($text) $accessToken = [Convert]::ToBase64String($bytes) #Create access token file $accessToken | ConvertTo-SecureString -AsPlainText | Export-Clixml $accessTokenPath } #EndRegion './Public/New-ZiAccessToken.ps1' 31 #Region './Public/New-ZiEndpoint.ps1' 0 function New-ZiEndpoint { [CmdletBinding()] param ( [Parameter(Mandatory,HelpMessage="Enter your Zisson domain suffix (no/com)")][ValidateSet("com","no")][string]$DomainSuffix, [string]$EndpointPath = "$env:USERPROFILE\.creds\Zisson\zissonEndpoint.xml" ) process { switch ($DomainSuffix) { no { $Endpoint = "https://api.zisson.no" } com { $Endpoint = "https://api.zisson.com" } } #Create parent folders of the access token file $EndpointDir = $EndpointPath.Substring(0, $EndpointPath.lastIndexOf('\')) if (!(Test-Path $EndpointDir)) { $null = New-Item -ItemType Directory $EndpointDir } $Endpoint | Export-Clixml $EndpointPath } } #EndRegion './Public/New-ZiEndpoint.ps1' 27 #Region './Public/Send-ZISMS.ps1' 0 function Send-ZiSMS { param ( [Parameter(Mandatory)][string]$message, [Parameter(Mandatory)][string]$recipients, [Parameter(Mandatory)][string]$senderNumber, [Parameter(Mandatory)][string]$senderName ) $splat = @{ "Method" = "POST" "Uri" = "$(Get-ZiEndpoint)/api/simple/SendSms" "Headers" = @{ "Authorization" = "Basic $(Get-ZiAccessToken)" } "Body" = @{ "sender_number" = $senderNumber "sender_name" = $senderName "recipients" = $recipients "msg" = $message } } Invoke-RestMethod @splat } #EndRegion './Public/Send-ZISMS.ps1' 24 |