How to receive images with the Telegram API?

Is it possible to receive images (and store it on the server) which was sent by any user to the bot?

If a image was sent, I receive this JSON post. This is a link to the Telegram Bot-API description. I don't know if it's possible to receive the whole image or not:


Telegram support download file now with getFile:

You can see it in the api documentation:

Telegram Bot API, Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get� Telegram API. This API allows you to build your own customized Telegram clients. It is 100% open for all developers who wish to create Telegram applications on our platform. Feel free to study the open source code of existing Telegram applications for examples of how things work here

It's possible to download the image from Telegram server. Do this: 1. Get the file using the getFile api

//Telegram link
$telegram_link = '' . $this->tg_configs['api_key'] . '/getFile?file_id=' . $photo['file_id'];

2. Get the file path //Create guzzle client $guzzle_client = new GuzzleClient();

//Call telegram
$request = $guzzle_client->get($telegram_link);
//Decode json
$json_response = json_decode($request->getBody(), true);
if ($json_response['ok'] == 'true') {

    //Telegram file link
    $telegram_file_link = '' . $this->tg_configs['api_key'] . '/' . $json_response['result']['file_path'];

3. If using PHP use Intervention/Image to download the image and save it on your server.

//Build upload path
$upload_path = public_path() . \Config::get('media::media.uploadPath');
//Get image
$image = $thumbnail = InterventionImage::make($telegram_file_link);

//Get mime
$mime = $image->mime();

if ($mime == 'image/jpeg') {
    $extension = '.jpg';
} elseif ($mime == 'image/png') {
    $extension = '.png';
} elseif ($mime == 'image/gif') {
    $extension = '.gif';
} else {
    $extension = '';
}//E# if else statement
//Resize images
$image->resize(\Config::get('media::media.mainWidth'), \Config::get('media::media.mainHeight'));
$thumbnail->resize(\Config::get('media::media.thumbnailWidth'), \Config::get('media::media.thumbnailHeight'));

//Build media name
$media_name = \Str::random(\Config::get('media::media.mediaNameLength')) . $extension;

//Save images
$image->save($upload_path . '/' . $media_name);
$thumbnail->save($upload_path . '/thumbnails/' . $media_name);

sendPhoto: Send image files in Develop a, To register a bot, you need to talk with “TheBotfather” in the Telegram app. Image for post. You can� Next, lets call the Telegram API to get our chat_id. If you have curl installed, you can read the message you just sent via the terminal with the getUpdates method: curl

The accepted answer is fine. But here's an answer in more detail. There are three main steps involved before you can get an actual image file. 1) Request from Telegram the file_id. 2) Load a Guzzle client. 3) Request from Telegram the file_path. Pay close attention to the different URL paths below.

// get file id
$id = $update['message']['photo'][0]['file_id'];
$file_id = "" . 
 config('app.telegram_api_key') . "/getFile?file_id=" . $id;

// guzzle client
$guzzle_client = new GuzzleClient();
$request = $guzzle_client->get($file_id);
$response = json_decode($request->getBody(),true);

// get file path
$file_url = "" .
 config('app.telegram_api_key') . "/" . $response['result']['file_path'];

Available Methods & Examples, file = bot.api.get_file(file_id: file_id) file_path = file.dig('result', 'file_path') photo_url = "{token}/#{file_path}"� Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a local photo by passing a file path. caption. (Optional). Photo caption (may also be used when re-sending photos by file_id), 0-1024 characters.

Send and Receive Messages with the Telegram API, When it comes to user interaction some images always make a good impression. we'll discover which type of content the Telegram Bot API supports and how Use this method to get basic info about a file and prepare it for� Telegram is accessible both from mobile and desktop, and can be easily integrated within the communication channels of a company. In this article we will find out how to integrate Telegram on your website to allow visitors to directly contact your company or join your group with a single click.

How to receive image sent by users? � Issue #143 � atipugin , Learn how to create a Telegram Bot and get a bot token. Use your bot's token and chat ID Duration: 5:37 Posted: Jul 12, 2018 You mean Telegram API for create a telegram application using C#, not Telegram Bot API, right? to get API key. Please see the step by step below or for detail information you can see this link. Sign up for Telegram using any application. Log in to your Telegram core: Go to ‘API development tools’ and fill out the form.

Handling multimedia files via Telegram Bots API, List Administrators in a Chat. Use this modules to get a list of administrators in a chat. Telegram Bot. List Chats. Setting up WhatsApp Telegram Bridge using wat-bridge bot. WhatsApp as of now is not allowing user-bots at all. But a CLI library called Yowsup can do the tricks. It actually acts as a WhatsApp API.

  • Where is your PHP code?
  • At this time i have nothing, because i dont know what to do in this case. Now, only store the contents of the Telegram Webhook-Call to my script.
  • Assume we don't know the Telegram API, and walk us through what is happening. Is the JSON here a reply message from Telegram? It references some file_id codes - where are they stored? Is there an API call to fetch them?
  • Would you point us to the relevant part of the documentation that would help us to answer?
  • I originally linked the telegram api documentation, but it seems to be removed. The JSON Here is a reply from Telegram, which would be send via an Webhook to my script. I make a logfile for incoming JSON Data with file_get_contents('php://input'), and the whole content, is in the code-box in my first Post. There is no Api-Call to fetch them, but is it possible that Telegram sends the Pic in any other format in the Webhook ? I try to print_r($_POST) and $_GET and so on, but the arrays was empty everytime i tried, so it seems like this above is the only i receive. Sry for my bad eng