0
0
0142015-09-24 14:42:59
PowerShell
014, 2015-09-24 14:42:59

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'

Error when executing:
Invoke-WebRequest : The request was aborted: Could not create SSL/TLS secure channel
Messages (sendMessage) are sent normally

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Nikitin, 2015-09-29
@padla2k

$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

in my opinion it's like that.

A
azarij, 2015-10-01
@azarij

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

As far as I understand, this will reduce the security of data transfer to the service.

N
Neri, 2015-12-08
@Neri

And how sendMessage to send through PS?

I
Ivan, 2016-03-30
@bordakovskiy

Neri
$botkey = "TOKEN"
$chat = "To whom we send"
$text = "What we send"
$sendText = " https://api.telegram.org/bot$botkey/sendMessage "
Invoke-WebRequest -Uri $sendText -Body @{chat_id=$chat; text=$text} | ConvertFrom-Json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question