Managing InlineQueryResultPhoto in Telegram

telegram bot api inline query result photo
06 February 2025

Introduction


These days, we often use bots in Telegram for various relationships. One of the interesting capabilities that bots have is that they can provide inline responses to user requests. Now we want to discuss InlineQueryResultPhoto which is used for sending photos in response to an inline request.


Whenever you ask a bot a question or for example search for a photo, the bot can use defined parameters to provide you with information such as photos. InlineQueryResultPhoto gives you the ability to send photos that are clickable and viewable in the chat for the user.


To perform this task well, it is sufficient to provide a minimum amount of information such as photo_url, thumb_url, and title to the bot. In fact, the more detailed and accurate this information is, the better the result will be.


So let's review a sample code demonstrating how to use this feature. We need a table to display photos, and after that, we can easily send photos based on the searches that are performed, to the user.


Sample Code


{
"inline_query": {
"id": "12345",
"query": "cat",
"offset": ""
},
"result": [
{
"type": "photo",
"id": "1",
"photo_url": "https://example.com/photo.jpg",
"thumb_url": "https://example.com/photo_thumb.jpg",
"title": "Cat Photo"
}
]
}

Code Explanation


Let's analyze the code line by line:



Line 1: {

This line indicates the beginning of a JSON structure.



Line 2: "inline_query": {...}

Here we have a definition for an inline query. In this structure, we describe the various requests to be sent.



Line 3: "id": "12345",

Each request must have a unique identifier so that the response can be matched to it.



Line 4: "query": "cat",

Here we define the search term, in this example, we are looking for “cat”.



Line 5: "offset": ""

This part is for pagination management and displaying additional results if available.



Line 6: "result": [...]

Here we define the search results which will include a list of photos.



Line 7: {

This line indicates the beginning of a new result item.



Line 8: "type": "photo",

Here we specify the result type as a photo, indicating that we have a photo result.



Line 9: "id": "1",

Each photo must also have a unique identifier.



Line 10: "photo_url": "https://example.com/photo.jpg",

This is the URL of the original photo which must be accessible.



Line 11: "thumb_url": "https://example.com/photo_thumb.jpg",

This URL is for a thumbnail image that will be shown in the search results.



Line 12: "title": "Cat Photo"}

Here we assign a title to the photo which will be displayed to the user.



Line 13: }

This line indicates the photo object is complete and signifies the completion of this JSON block.



Line 14: }

This line also indicates the end of the overall JSON structure.



FAQ

?

What is InlineQueryResultPhoto and how does it work?

?

How can I add images to an inline result?

?

Can I add multiple images to one inline result?

?

How can I filter the returned images?