Answer the question
In order to leave comments, you need to log in
Why is the document not sent via telegram api?
Hello, my bot should be able to send files to the chat, I put together the code to send the file:
$document = new CURLFile('test.txt');
$url = "https://api.telegram.org/bot$token/sendDocument?chat_id=$chat_id";
echo $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ["document" => $document]);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type:multipart/form-data"]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$out = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
var_dump($out);
var_dump($err);
Answer the question
In order to leave comments, you need to log in
most likely something with $document, trynew CURLFile(realpath("/path/to/test.txt"))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question