sendDocument requires multipart/form-data.
$path = 'C:file.txt'
$userId = 12345
$token = "ABC123"
$url = "https://api.telegram.org/-/sendDocument?chat_id=+"
[net.servicepointmanager]::securityprotocol = 'ssl3,tls,tls11,tls12'
$url = $url.Replace("-",$token).Replace("+",$userId)
$Response = Iwr -Uri $url -Method Post -InFile $path -ContentType "multipart/form-data"
$Response.Content
But i got Error:400. How to properly send file?
2
Answers
I don’t know much about it, but I recently read a bit on Telegram and I know there’s a module called PoShGram that allows you to interact with it. You can find it here
At a glance looks like it may have the functionality you need. The read me says:
Sending a file with a Telegram bot via PowerShell requires some more work.
This is an example of how to send a text document:
Another option I found is to make use of the
Form
param in PowerShell v6.1 or higher (download it from GitHub if needed); I found this raw example here: