Skip to content

Instantly share code, notes, and snippets.

@g3rhard
Last active June 17, 2020 14:46
Show Gist options
  • Save g3rhard/4f45b2aff95014c0c8713b73e055402e to your computer and use it in GitHub Desktop.
Save g3rhard/4f45b2aff95014c0c8713b73e055402e to your computer and use it in GitHub Desktop.
Send message with Telegram and Powershell
#Usage: sendmessage_telegram.ps1 -chat_id CHAT_ID -text 'TEXT' -markdown
param(
[string]$chat_id = $(Throw "'-chat_id' argument is mandatory"),
[string]$text = $(Throw "'-text' argument is mandatory"),
[switch]$markdown,
[switch]$nopreview
)
$token = "TOKEN"
if($nopreview) { $preview_mode = "True" }
if($markdown) { $markdown_mode = "Markdown" } else {$markdown_mode = ""}
$payload = @{
"chat_id" = $chat_id;
"text" = $text
"parse_mode" = $markdown_mode;
"disable_web_page_preview" = $preview_mode;
}
Invoke-WebRequest `
-Uri ("https://api.telegram.org/bot{0}/sendMessage" -f $token) `
-Method Post `
-ContentType "application/json;charset=utf-8" `
-Body (ConvertTo-Json -Compress -InputObject $payload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment