Sending Image via Telegram-Bot API with PHP
Get the solution ↓↓↓I have this function
function suspendido($chat_id,$foo)
{
$TOKEN = "blablalbal";
$TELEGRAM = "https://api.telegram.org:443/bot$TOKEN";
$url. = "https://zrabogados-pruebas.xyz/bot/404.png";
$query = http_build_query(array(
'chat_id'=> $chat_id,
'photo'=> $url,
'text'=> $foo,
'parse_mode'=> "HTML", // Optional: Markdown | HTML
));
$response = file_get_contents("$TELEGRAM/sendMessage?$query");
return $response;
}
I try to sending an Image without using curl, tried to use file_get_contents but nothing works. Is something missing?.
Answer
Solution:
You usedsendMessage
method, And this method isn't acceptphoto
parameter.
And$url
shouldn't be concatenated with another link.
To send photo usesendPhoto
method like this:
<?php
function suspendido($chat_id, $url, $foo)
{
$TOKEN = "<bot_token>";
$TELEGRAM = "https://api.telegram.org:443/bot$TOKEN";
$url = "https://zrabogados-pruebas.xyz/bot/404.png";
$query = http_build_query(array(
'chat_id'=> $chat_id,
'photo'=> $url,
'text'=> $foo,
'parse_mode'=> 'HTML' // Optional: Markdown | HTML
));
# Use sendPhoto here, Not sendMessage
$response = file_get_contents("$TELEGRAM/sendPhoto?$query");
return $response;
}
Answer
Solution:
Apparently, there is some problem with telegram servers.
If you put some image attributes into url it works.
function suspendido($chat_id,$foo)
{
$TOKEN = "blablalbla";
$TELEGRAM = "https://api.telegram.org:443/bot$TOKEN";
$url = "https://zrabogados-pruebas.xyz/bot/404.png?center=140.50,36.15&width=1024&height=576";
$query = http_build_query(array(
'chat_id'=> $chat_id,
'photo'=> $url,
'text'=> $foo,
'parse_mode'=> "HTML", // Optional: Markdown | HTML
));
$response = file_get_contents("$TELEGRAM/sendMessage?$query");
return $response;
}
I know its just silly but it works that way if you send the image url without this then you will receive a 400 error.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to a member function format() on string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.