skip to Main Content

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?.

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. You used sendMessage method, And this method isn’t accept photo parameter.

    And $url shouldn’t be concatenated with another link.

    To send photo use sendPhoto 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;
    }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search