Inline mode in Telegram
What is inline mode in Telegram?
In addition to the fact that the bot can respond to any requests directly in a personal chat or group, using the online mode, you can globally access the bot in a chat, group or channel.
To contact a bot that has online mode enabled, just enter @*bot name* in the Message field.
The most striking and popular example of a bot working online is @gif, with which you can select and send gif images:

The @gif bot will work in any chat.
How to enable inline mode?
In order for the bot to work in offline mode, you need to enable this option in the bot settings in BotFather.
Select the desired bot and go to the Bot Settings.

Then choose Inline Mode

Here you need to enable the offline mode if it is not enabled.

How to change placeholder?
If desired, you can change the placeholder that is displayed before entering the search query. By default, it is Search…

To change it, click the Edit Inline Placeholder button:

Define the exact placeholder content.

How to configure the output results
After clicking on an option from the list in inline mode, a message will be sent that is indicated in the header of the selected option, and you can adjust the reaction in the funnel to this value.
To specify the data to output in inline mode, you need to set the inline_bot variable. In the inline mode, the search for values in the inline_bot variable takes place almost in real time.
The data in the variable can be specified in three ways. Let's look from the simplest to the maximum settings.
An array with text data
For example, the search will take place across an array of products.

The inline_bot variable is specified in the project settings. The search matches any array variant that contains the entered phrase.


When you enter the '@name__of your__bot' and the initial letters of the commands, a menu opens with the values that you specified in the project variable.
After clicking on the desired item, a message from the user will be sent to the bot, to which you can configure the reaction in the bot.
The block configuration looks like this:

Sample data:
["Milk", "Bread", "Pasta", "Chocolate", "Eggs", "Butter", "Bun", "Tea", "Vegetables", "Fruit"]
Output in the absence of filtering
You can set an empty key and assign it an array of lowercase values or an array of dictionaries. The bot will access the dictionary using an empty key and output buttons with values from the assigned array.
An inline button with the specified search value
Please note!
Inline buttons in Telegram are not callbacks.
If you need to receive callbacks, then read about callback buttons in Telegram.
The button only works in Telegram.
To set a search phrase, add the inline_query parameter to the inline button with a value that is automatically inserted into the query.
It is recommended to use this option for the offline mode, as it will avoid mistakes and work faster.
For example, add three buttons that match the example from the previous chapter.
[{"line":0,"index_in_line":0,"text":"Show the menu","type":"inline","inline_query":"menu"},{"line":0,"index_in_line":1,"text":"Статьи","type":"inline","inline_query":"posts"},{"line":2,"index_in_line":0,"text":"List of products","type":"inline","inline_query":"products"}]

When you click on a button, for example, an Article, the found list of buttons will be displayed (when adding, you specified "inline_query":"posts" for this button):

The options are taken from a given variable, as described above in the "Dictionary with a list" section:

Notes
The inline_bot variable can be set not only in general variables, but also as a simple variable, but in this case its value must be enclosed in single quotes.
Example in the calculator field:
inline_bot = '["Milk", "Bread", "Pasta", "Chocolate", "Eggs", "Butter", "Puff Pastry", "Tea", "Vegetables", "Fruits", "#{aa}"]'
You can also pass any value as a variable for more flexible configuration.
For example, a simple option in an array:

Last updated