# tg.ps1 — PowerShell helpers for tg_post.py
Usage examples (after you load this file):
tg "Hello from anywhere" # text to default channel
tg -Text "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" -Pin
tgFile -Path "report.pdf" -Caption "Q3" -Reply 1234
#>
# ---- Config (edit these) ----
$DefaultTo = "@TrueDelta" # Default target (channel/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,
[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
}
# Build argument list robustly (handles quoting/escapes)
$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 ($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.
.EXAMPLE
tg "Hello from anywhere"
.EXAMPLE
tg -Text "Hi" -Html -NoPreview
#>
[CmdletBinding()]
param(
[Parameter(Position=0, Mandatory=$false)][string]$Text,
[string]$To = $DefaultTo,
[switch]$Html,
[switch]$Md,
[switch]$NoPreview,
[switch]$Silent,
[switch]$Pin,
[int]$Reply
)
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
}
function tgPhoto {
<#
.SYNOPSIS
Send a photo (optionally with caption).
.EXAMPLE
tgPhoto -Path cover.jpg -Caption "New cover"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][Alias("File","Image")][string]$Path,
[string]$Caption,
[string]$To = $DefaultTo,
[switch]$Silent,
[switch]$Pin,
[int]$Reply
)
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
}
function tgVideo {
<#
.SYNOPSIS
Send a video (streamable) with optional caption.
.EXAMPLE
tgVideo -Path clip.mp4 -Caption "Episode 1" -Pin
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][Alias("File")][string]$Path,
[string]$Caption,
[string]$To = $DefaultTo,
[switch]$Silent,
[switch]$Pin,
[int]$Reply
)
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
}
function tgFile {
<#
.SYNOPSIS
Send any file/document with optional caption.
.EXAMPLE
tgFile -Path report.pdf -Caption "Monthly report"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][string]$Path,
[string]$Caption,
[string]$To = $DefaultTo,
[switch]$Silent,
[switch]$Pin,
[int]$Reply
)
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
}
# 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