Proxying
This method is outdated. We recommend using MtProto or API instead, as they are more flexible and reliable.
The Telegram Bot API operates on two work schemes:
webhook: when a user writes to the bot, the Telegram server automatically sends a HTTPS request to your bot's address
getUpdates (long polling): your bot independently requests updates from the Telegram server

To make connecting to the platform simple and fast, we have developed a special proxy server that is installed between the Telegram server and your bot.

If your bot operates via Webhook
You can manually connect your bot (without entering a token), for this when adding a bot you need to select the appropriate item and follow the instructions. You will need to replace your webhook with ours.
If your bot operates via getUpdates
There are two ways to connect a bot working through the getUpdate method, via the API (see the section "Connecting a bot via the API") or by replacing the host with api.telegram.org .
Bots of this type independently request updates from Telegram using HTTPS requests using the getUpdate method. To connect the bot to analytics, you need to change the host api.telegram.org to the host that the system will give you when you connect.
After changing the host, our platform will proxy all requests to the host api.telegram.org and collect statistics for you. Not only getUpdate requests can be sent to this address, but also all other types of requests (sending messages, files, etc.). All requests are proxied to the Telegram servers unchanged.
How to change the host connection in the bot?
Changing the host api.telegram.org provided by the Telegram Bot API, most libraries have the ability to change this address.
If you have not found the instructions for your library or you have problems connecting, please contact our technical support or fill out the form at the end of this page.
Important. The examples use the address "https://tgrasp.co ", you can use this address only if the bot token was specified in your personal account. In other cases, use only the address that you received in your personal account at the stage of setting up the bot.
If you have set a token for the bot in your personal account, the system will give you the address "https://tgrasp.co " otherwise the address will be "https://{code} .tgrasp.co"
Connection instructions for specific libraries
Select the library you are using
If you have not found the instructions you need, write to us in the chat on the website or fill out the form at the end of this page
Python
Aiogram
Repositroy - https://github.com/aiogram/aiogram
Information on how to change the host in the documentation https://docs.aiogram.dev/en/dev-3.x/api/session/custom_server.html
Полный листинг кода
Pay attention to lines 11 and 12, objects are imported into them. Lines 51-53 specify the address. An attribute is added to line 56 , session=session
eternnoir/pyTelegramBotAPI
Repository - https://github.com/eternnoir/pyTelegramBotAPI
To change the host, you need to import apihelper and set the API_URL parameter. You can read about how to change the host in the official documentation
Full code listing
For a full-fledged example, we used an example from the official repository at https://github.com/eternnoir/pyTelegramBotAPI/blob/master/examples/echo_bot.py
Pay attention to lines 7 and 11. An object is imported into them and the address is changed
python-telegram-bot/python-telegram-bot
Repository - https://github.com/python-telegram-bot/python-telegram-bot
Information on how to change the host in the documentation https://github.com/python-telegram-bot/python-telegram-bot/wiki/Local-Bot-API-Server
You can change the host using the base_url method. For clarity, we used the basic example from the documentation. Pay attention to line 14 where the address changes .base_url('https://tgrasp.co/bot')
PHP
telegram-bot-sdk/telegram-bot-sdk
Repository - https://github.com/telegram-bot-sdk/telegram-bot-sdk
The library supports working with multiple bots, so there are two connection options below
If you have one bot
If you have multiple bots
php-telegram-bot/core
Repository - https://github.com/php-telegram-bot/core
Information on how to change the host in the documentation https://github.com/php-telegram-bot/core#using-a-custom-bot-api-server
TelegramBot/Api
Repository - https://github.com/TelegramBot/Api
Information on how to change the host in the documentation https://github.com/TelegramBot/Api?tab=readme-ov-file#local-bot-api-server
At the time of writing this documentation, the ability to change the address is present only in dev version 2.6. By default, version 2.5 is installed
To update your library version to version 2.6
Change it in composer.json on"^2.6" and add the parameters "minimum-stability": "dev", "prefer-stable": true
Changing the address
When creating a BotApi object, pass our address as the fourth parameter
defstudio/telegraph
Repository - https://github.com/defstudio/telegraph
You can change the connection URL in the defstudio/telegraph configuration. Replace the value of the telegram_api_url parameter with the desired address (e.g., https://tgrasp.co).
For more details about the configuration file, refer to the documentation
JavaScript
yagop/node-telegram-bot-api
Repository - https://github.com/yagop/node-telegram-bot-api
In order to change the host, you need to pass the parameter baseApiUrl: 'https://tgrasp.co' in attribute options when creating object a new TelegramBot(token, [options])
Full code listing
For a full-fledged example, we used an example from the official repository at https://github.com/yagop/node-telegram-bot-api/blob/master/examples/polling.js
Pay attention to line 12, the address changes in it
grammyjs/grammY
Instructions on how to change the address in the official documentation - https://grammy.dev/guide/api#configuring-grammy-to-use-the-local-bot-api-server
To connect the address, change the creation of the Bot object
Example
As an example, we used a basic example from the official documentation. Pay attention to the 4-7 lines in which the address changes.
telegraf/telegraf
Repository — https://github.com/telegraf/telegraf
To connect, change the creation of the Telegraf object. Below is an example of a simple bot with a changed address. Pay attention to lines 5-8, the address changes in them. Replace the address with the one you received in your personal account.
After making changes, restart the bot.
Go
go-telegram-bot-api/telegram-bot-api
Repository - https://github.com/go-telegram-bot-api/telegram-bot-api
Use the method SetAPIEndpoint to change the connection host
A full-fledged example
Pay attention to line 17, the address changes in it
tucnak/telebot
Repository - https://github.com/tucnak/telebot
To change the connection host, pass the desired address to the URL parameter
A full-fledged example
Pay attention to line 13, the address changes in it
Java
rubenlagus/TelegramBots
Repository - https://github.com/rubenlagus/TelegramBots
As an example, we used the repository https://github.com/rubenlagus/TelegramBotsExample
To connect incoming traffic, you need to pass the TelegramUrl object to the function TelegramBotsLongPollingApplication.registerBot()
Note line 8, this is the standard method for connecting to the TG Bot API. In the next line, we added 2 parameters to this function, including passing a new address for the connection. Replace it with the address provided by your system.
Possible errors
All errors related to the work of the bot fall into the bot errors section in the personal account.
409
Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
The error occurs when the telegram servers record two simultaneous getUpdates requests. Make sure that you have only one data acquisition thread running
502
502 Bad Gateway
Make sure that you are sending the request with the correct structure. Sometimes problems occur on telegram servers and they may respond with this error.
404
404 Not Found
Make sure you are using the correct address for the connection. Compare it with the address provided by the system. The address tgrasp.co can only be used if a token has been provided.
If you are using tgrasp.co, ensure that the bot ID (the first part of the token) matches the one you provided in graspil. The current bot ID in graspil is displayed below the connection address field.
Last updated