param( [Parameter(Mandatory = $true)] [string]$Message, [string]$BotToken = $env:TELEGRAM_BOT_TOKEN, [string]$ChatId = $env:TELEGRAM_CHAT_ID, [string]$ConfigPath = (Join-Path $PSScriptRoot "telegram.local.json") ) $ErrorActionPreference = "Stop" if (([string]::IsNullOrWhiteSpace($BotToken) -or [string]::IsNullOrWhiteSpace($ChatId)) -and (Test-Path -LiteralPath $ConfigPath)) { $config = Get-Content -LiteralPath $ConfigPath -Raw | ConvertFrom-Json if ([string]::IsNullOrWhiteSpace($BotToken)) { $BotToken = $config.bot_token } if ([string]::IsNullOrWhiteSpace($ChatId)) { $ChatId = $config.chat_id } } if ([string]::IsNullOrWhiteSpace($BotToken) -or [string]::IsNullOrWhiteSpace($ChatId)) { exit 0 } $uri = "https://api.telegram.org/bot$BotToken/sendMessage" $body = @{ chat_id = $ChatId text = $Message disable_web_page_preview = $true } Invoke-RestMethod -Uri $uri -Method Post -Body $body | Out-Null