T
T
TechNOIR2017-12-28 13:29:05
PowerShell
TechNOIR, 2017-12-28 13:29:05

Powershell+Telegram API. How to send an image?

Good afternoon. How to send a picture using Powershell? There is a SendPhoto method. I seem to be doing everything right but it doesn't work.
The code:

$id = "0000000000"
$photo = "E:\slow.jpg"
$bot_token = "0000000000000000000000000000000000000000000000"
$uri = "https://api.telegram.org/bot$bot_token/sendPhoto"

Invoke-WebRequest -Method Post -Uri $uri -ContentType "application/json;charset=utf-8" -Body (ConvertTo-Json -Compress -InputObject @{chat_id=$id; photo=$photo})

And the result:
Invoke-WebRequest : {"ok":false,"error_code":400,"description":"Bad Request: wrong HTTP URL specified"}

Any ideas comrades? thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Korotaev, 2017-12-28
@aavezel

sendPhoto in the photo parameter accepts either the public url of the photo or the content (but then only with multipart/form-data encoding). Invoke-WebRequest on database with multipart/form-data doesn't work.
E:\slow.jpg - is not a public link.
Solution:
1. Use a third party utility to query. For example, cUrl can do this
2. Upload an image as a post to a public server and pass the url of the image (I don’t know such free ones.Yandex.Disk???)
3. Attach multipart/form-data to Invoke-WebRequest: https://gist. github.com/weipah/19bfdb14aab253e3f109

S
soondook, 2018-02-25
@soondook

powerTelegram implementation example via NetTelegramBotApi

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question