function Ensure-CommDirs { $base = 'D:\_CareTV-Communications' @( $base, (Join-Path $base 'sms'), (Join-Path $base 'sms\outbox'), (Join-Path $base 'sms\sent'), (Join-Path $base 'sms\failed'), (Join-Path $base 'fax'), (Join-Path $base 'fax\outbox'), (Join-Path $base 'fax\sent'), (Join-Path $base 'fax\failed'), (Join-Path $base 'fax\inbox') ) | ForEach-Object { New-Item -ItemType Directory -Force -Path $_ | Out-Null } } function Queue-Sms { param([string]$To,[string]$Message) Ensure-CommDirs if([string]::IsNullOrWhiteSpace($To)){ throw 'SMS destination is required.' } if([string]::IsNullOrWhiteSpace($Message)){ throw 'SMS message is required.' } $item = [ordered]@{ id=[guid]::NewGuid().ToString(); type='sms'; to=$To; message=$Message; created=(Get-Date).ToString('o'); status='queued' } $path = "D:\_CareTV-Communications\sms\outbox\$($item.id).json" $item | ConvertTo-Json -Depth 6 | Set-Content -Encoding UTF8 $path return $item } function Queue-Fax { param([string]$To,[string]$DocumentPath) Ensure-CommDirs if([string]::IsNullOrWhiteSpace($To)){ throw 'Fax destination is required.' } $doc=[IO.Path]::GetFullPath($DocumentPath) if(-not (Test-Path $doc -PathType Leaf)){ throw 'Fax document does not exist.' } $item = [ordered]@{ id=[guid]::NewGuid().ToString(); type='fax'; to=$To; document=$doc; created=(Get-Date).ToString('o'); status='queued' } $path = "D:\_CareTV-Communications\fax\outbox\$($item.id).json" $item | ConvertTo-Json -Depth 6 | Set-Content -Encoding UTF8 $path return $item }