Answer the question
In order to leave comments, you need to log in
How to send a file to your bot in Telegram Bot API using Powershell?
I do it like this:
$file = "c:\temp\imp.txt"
Invoke-WebRequest -InFile $file -Method Post -ContentType 'multipart/form-data' 'https://api.telegram.org/botXXX/sendDocument?chat_id=1111111&document'
Answer the question
In order to leave comments, you need to log in
$file = Get-Content -Path "c:\temp\imp.txt"
$uri = "https://api.telegram.org/botXXX/sendDocument?chat_id=1111111&document"
Invoke-RestMethod -Method Post -Uri $uri -ContentType 'multipart/form-data' -Body [byte]$file
and if you insert this code at the very beginning of the script:
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question