I created a telegram-bot and I execute requests to the telegram bot API from Mathematica. You can find full API documentation here.
I have a problem with sending image from computer or RAM. I try send photo using this code:
$token = <token> (* string - bot token from @BotFather *)
$chat = <chat_id> (* string - allowed chat id *)
$api = StringTemplate["https://api.telegram.org/bot`token`"][<|"token" -> $token|>]
$url = URLBuild[{$api, "sendPhoto"}]
dataString = ExportString[Plot[Sin\[x\], {x, 1, 4}, ImageSize->Tiny], "JPEG"];
body = StringTemplate[
"
--WMAsrf456BGe4h
Content-Disposition: form-data; name=\"chat_id\"
`chat_id`
--WMAsrf456BGe4h
Content-Disposition: form-data; name=\"photo\";filename=\"photo.jpg\"
Content-Type: image/jpeg
`data`
--WMAsrf456BGe4h"
]; (* https://en.wikipedia.org/wiki/MIME#Multipart_messages *)
request\[\] :=
HTTPRequest[$url,
<|
Method -> "POST",
"ContentType" -> "multipart/form-data; boundary=WMAsrf456BGe4h",
"Headers" -> {
"Connection" -> "keep-alive"
},
"Body" -> body[<|"chat_id" -> $chat, "data" -> dataString|>]
|>
]
response = URLRead[request\[\]\]
(* Out[..] := HTTPResponse[<<504>>] *)
response["Body"]
(* Out[..] := "<html>
<head><title>504 Gateway Time-out</title></head>
<body bgcolor=\"white\">
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx/1.12.2</center>
</body>
</html>" *)
how to send an image?