Last active
June 17, 2020 14:46
-
-
Save g3rhard/4f45b2aff95014c0c8713b73e055402e to your computer and use it in GitHub Desktop.
Send message with Telegram and Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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