Null-DRM-Official/scripts/notify-telegram.ps1
404errordeveloper 2e43e6c3fa
All checks were successful
release / build-and-upload (push) Successful in 6m21s
Add ITVX module, transparent mitm_hosts, and DM Telegram announces.
Wire module mitm_hosts into StartTransparent for ITVX capture, ship the
itv provider stub with Live-list autoplay, refresh the README, and send
Forgejo release announces to private chat 7314901602.
2026-10-09 17:35:53 +02:00

113 lines
3.6 KiB
PowerShell

# Post a release announce to Telegram.
#
# Required env:
# TELEGRAM_BOT_TOKEN BotFather token (never commit)
# TELEGRAM_CHAT_ID e.g. 7314901602 (private DM) or -100… (group)
#
# Optional:
# TELEGRAM_MESSAGE_THREAD_ID forum topic / "tab" id (groups only)
#
# Usage:
# $env:TELEGRAM_BOT_TOKEN="..."; $env:TELEGRAM_CHAT_ID="7314901602"
# .\scripts\notify-telegram.ps1 -Tag v0.1.2
# .\scripts\notify-telegram.ps1 -Tag v0.1.2 -ThreadId 16
# .\scripts\notify-telegram.ps1 -Tag modules-v0.1.2 -DryRun
param(
[string]$Tag = "",
[string]$Kind = "auto", # auto | host | modules
[string]$Title = "",
[string]$Body = "",
[string]$ReleaseUrl = "",
[string]$RepoUrl = "https://git.nulldrm.com/nulldrm/Null-DRM-Official",
[string]$ThreadId = "",
[switch]$DryRun
)
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
if (-not $Tag) { $Tag = $env:RELEASE_TAG }
if (-not $Tag) {
try { $Tag = (git -C $Root describe --tags --exact-match 2>$null) } catch { }
}
if (-not $Tag) {
try { $Tag = (git -C $Root describe --tags --always 2>$null) } catch { }
}
if (-not $Tag) { throw "usage: notify-telegram.ps1 -Tag v0.1.2" }
$Token = $env:TELEGRAM_BOT_TOKEN
$Chat = $env:TELEGRAM_CHAT_ID
if (-not $ThreadId) { $ThreadId = $env:TELEGRAM_MESSAGE_THREAD_ID }
if (-not $DryRun -and (-not $Token -or -not $Chat)) {
throw "TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID are required"
}
if ($DryRun -and (-not $Token -or -not $Chat)) {
Write-Host "[!] DryRun: TELEGRAM_BOT_TOKEN / TELEGRAM_CHAT_ID not set - showing payload only"
if (-not $Chat) { $Chat = "(unset)" }
}
if ($Kind -eq "auto") {
if ($Tag -like "modules-v*") { $Kind = "modules" } else { $Kind = "host" }
}
if (-not $ReleaseUrl) {
if ($env:RELEASE_URL) { $ReleaseUrl = $env:RELEASE_URL }
else { $ReleaseUrl = "$RepoUrl/releases/tag/$Tag" }
}
if (-not $Title) {
if ($env:RELEASE_TITLE) { $Title = $env:RELEASE_TITLE }
else { $Title = "Null DRM $Tag" }
}
function New-TelegramBody {
param([string]$Kind, [string]$Title, [string]$Tag, [string]$ReleaseUrl)
$code = { param($t) "<code>$t</code>" }
$nl = "`n"
if ($Kind -eq "modules") {
return (
"<b>$Title</b>" + $nl +
"Provider module zips: $( & $code 'bbc.zip' ), $( & $code 'rte.zip' ), $( & $code 'tg4.zip' ), $( & $code 'itv.zip' )" + $nl + $nl +
"Unpack each into $( & $code 'modules/<name>/' ) and edit $( & $code 'module.yaml' ) for secrets." + $nl + $nl +
"<a href=`"$ReleaseUrl`">Download $Tag</a>"
)
}
return (
"<b>$Title</b>" + $nl +
"Host CLI ($( & $code 'drm' )) + on-device MITM ($( & $code 'proxy-android-arm64' ))." + $nl + $nl +
"<a href=`"$ReleaseUrl`">Download $Tag</a>"
)
}
if (-not $Body) {
if ($env:RELEASE_BODY) {
$Body = $env:RELEASE_BODY
} else {
$Body = New-TelegramBody -Kind $Kind -Title $Title -Tag $Tag -ReleaseUrl $ReleaseUrl
}
}
if ($DryRun) {
Write-Host "DRY_RUN chat=$Chat thread=$ThreadId tag=$Tag kind=$Kind"
Write-Host "----"
Write-Host $Body
return
}
$threadNote = if ($ThreadId) { " topic/thread $ThreadId" } else { "" }
Write-Host "[*] Telegram notify -> chat $Chat$threadNote ($Tag)"
$uri = "https://api.telegram.org/bot$Token/sendMessage"
$form = @{
chat_id = $Chat
text = $Body
parse_mode = "HTML"
disable_web_page_preview = "false"
}
if ($ThreadId) {
$form.message_thread_id = $ThreadId
}
$resp = Invoke-RestMethod -Method Post -Uri $uri -Body $form
if (-not $resp.ok) {
throw "Telegram API error: $($resp | ConvertTo-Json -Compress)"
}
Write-Host "[+] Telegram announce sent for $Tag (message_id=$($resp.result.message_id))"