Answer the question
In order to leave comments, you need to log in
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})
Invoke-WebRequest : {"ok":false,"error_code":400,"description":"Bad Request: wrong HTTP URL specified"}
Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question