<# tg.ps1 — PowerShell helpers for tg_post.py (now with Topic support) Usage examples (after loading this file in $PROFILE): tg "Hello" # text to default target tg "Bold" -Html # HTML text tg -Text "*Bold*" -Md -NoPreview # Markdown, no link preview tgPhoto -Path "cover.jpg" -Caption "New" # photo with caption tgVideo -Path "clip.mp4" -Caption "Ep.1" # video with caption tgFile -Path "report.pdf" -Caption "Q3" # any document # Post into a forum topic (topic root message id) tg "In a topic" -To -1001234567890 -TopicId 54321 tgPhoto -Path x.jpg -To -1001234567890 -TopicId 54321 -Caption "Pic in topic" #> # ---- Config (edit these) ---- $DefaultTo = "@TrueDelta" # Default target (channel/group/user). Change if needed. $Python = "python" # Or full path to python.exe if not in PATH $ScriptPath = Join-Path $PSScriptRoot "tg_post.py" # Path to the Python script # ---- Internal helper ---- function Invoke-TgPost { param( [Parameter(Mandatory=$false)][string]$To = $DefaultTo, [Parameter(Mandatory=$false)][string]$Text, [switch]$Html, [switch]$Md, [switch]$NoPreview, [switch]$Silent, [switch]$Pin, [int]$Reply, [int]$TopicId, [string]$Photo, [string]$Video, [string]$File, [string]$Caption ) if (-not (Test-Path $ScriptPath)) { Write-Error "tg_post.py not found at '$ScriptPath'. Update `$ScriptPath in tg.ps1." return } $args = @($ScriptPath, "--to", $To) if ($Text) { $args += @("--text", $Text) } if ($Html) { $args += "--html" } if ($Md) { $args += "--md" } if ($NoPreview) { $args += "--no-preview" } if ($Silent) { $args += "--silent" } if ($Pin) { $args += "--pin" } if ($Reply) { $args += @("--reply", $Reply) } if ($TopicId) { $args += @("--topic-id", $TopicId) } if ($Photo) { $args += @("--photo", $Photo) } if ($Video) { $args += @("--video", $Video) } if ($File) { $args += @("--file", $File) } if ($Caption) { $args += @("--caption", $Caption) } & $Python $args } # ---- Public commands ---- function tg { <# .SYNOPSIS Send a text message quickly (supports forum topics with -TopicId). #> [CmdletBinding()] param( [Parameter(Position=0, Mandatory=$false)][string]$Text, [string]$To = $DefaultTo, [switch]$Html, [switch]$Md, [switch]$NoPreview, [switch]$Silent, [switch]$Pin, [int]$Reply, [int]$TopicId ) if (-not $Text) { Write-Error 'Provide message text, e.g. tg "Hello world"' return } Invoke-TgPost -To $To -Text $Text -Html:$Html -Md:$Md -NoPreview:$NoPreview -Silent:$Silent -Pin:$Pin -Reply:$Reply -TopicId:$TopicId } function tgPhoto { <# .SYNOPSIS Send a photo (optionally with caption). Supports -TopicId. #> [CmdletBinding()] param( [Parameter(Mandatory=$true)][Alias("File","Image")][string]$Path, [string]$Caption, [string]$To = $DefaultTo, [switch]$Silent, [switch]$Pin, [int]$Reply, [int]$TopicId ) if (-not (Test-Path $Path)) { Write-Error "Photo not found: $Path"; return } Invoke-TgPost -To $To -Photo $Path -Caption $Caption -Silent:$Silent -Pin:$Pin -Reply:$Reply -TopicId:$TopicId } function tgVideo { <# .SYNOPSIS Send a video (streamable) with optional caption. Supports -TopicId. #> [CmdletBinding()] param( [Parameter(Mandatory=$true)][Alias("File")][string]$Path, [string]$Caption, [string]$To = $DefaultTo, [switch]$Silent, [switch]$Pin, [int]$Reply, [int]$TopicId ) if (-not (Test-Path $Path)) { Write-Error "Video not found: $Path"; return } Invoke-TgPost -To $To -Video $Path -Caption $Caption -Silent:$Silent -Pin:$Pin -Reply:$Reply -TopicId:$TopicId } function tgFile { <# .SYNOPSIS Send any file/document with optional caption. Supports -TopicId. #> [CmdletBinding()] param( [Parameter(Mandatory=$true)][string]$Path, [string]$Caption, [string]$To = $DefaultTo, [switch]$Silent, [switch]$Pin, [int]$Reply, [int]$TopicId ) if (-not (Test-Path $Path)) { Write-Error "File not found: $Path"; return } Invoke-TgPost -To $To -File $Path -Caption $Caption -Silent:$Silent -Pin:$Pin -Reply:$Reply -TopicId:$TopicId } # Optional: quick aliases Set-Alias -Name tgtext -Value tg -Force Set-Alias -Name tgphoto -Value tgPhoto -Force Set-Alias -Name tgvideo -Value tgVideo -Force Set-Alias -Name tgfile -Value tgFile -Force