downloadProxying

circle-exclamation

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

The above diagram shows the standard scheme for exchanging data between the bot and Telegram servers.

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.

This is what the scheme looks like after connecting graspi.

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 supportarrow-up-right or fill out the form at the end of this page.

triangle-exclamation

Connection instructions for specific libraries

Select the library you are using

circle-info

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

chevron-rightAiogramhashtag

Repositroy - https://github.com/aiogram/aiogramarrow-up-right

Information on how to change the host in the documentation https://docs.aiogram.dev/en/dev-3.x/api/session/custom_server.htmlarrow-up-right

Полный листинг кода

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

chevron-righteternnoir/pyTelegramBotAPIhashtag

Repository - https://github.com/eternnoir/pyTelegramBotAPIarrow-up-right

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 documentationarrow-up-right

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.pyarrow-up-right

Pay attention to lines 7 and 11. An object is imported into them and the address is changed

chevron-rightpython-telegram-bot/python-telegram-bothashtag

Repository - https://github.com/python-telegram-bot/python-telegram-botarrow-up-right

Information on how to change the host in the documentation https://github.com/python-telegram-bot/python-telegram-bot/wiki/Local-Bot-API-Serverarrow-up-right

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

chevron-righttelegram-bot-sdk/telegram-bot-sdkhashtag

Repository - https://github.com/telegram-bot-sdk/telegram-bot-sdkarrow-up-right

The library supports working with multiple bots, so there are two connection options below

If you have one bot

If you have multiple bots

chevron-rightphp-telegram-bot/corehashtag
chevron-rightTelegramBot/Apihashtag

Repository - https://github.com/TelegramBot/Apiarrow-up-right

Information on how to change the host in the documentation https://github.com/TelegramBot/Api?tab=readme-ov-file#local-bot-api-serverarrow-up-right

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

chevron-rightdefstudio/telegraphhashtag

Repository - https://github.com/defstudio/telegrapharrow-up-right

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 documentationarrow-up-right

JavaScript

chevron-rightyagop/node-telegram-bot-apihashtag

Repository - https://github.com/yagop/node-telegram-bot-apiarrow-up-right

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.jsarrow-up-right

Pay attention to line 12, the address changes in it

chevron-rightgrammyjs/grammYhashtag

Instructions on how to change the address in the official documentation - https://grammy.dev/guide/api#configuring-grammy-to-use-the-local-bot-api-serverarrow-up-right

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.

chevron-righttelegraf/telegrafhashtag

Repository — https://github.com/telegraf/telegraf arrow-up-right

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

chevron-rightgo-telegram-bot-api/telegram-bot-apihashtag

Repository - https://github.com/go-telegram-bot-api/telegram-bot-apiarrow-up-right

Use the method SetAPIEndpoint to change the connection host

A full-fledged example

Pay attention to line 17, the address changes in it

chevron-righttucnak/telebothashtag

Repository - https://github.com/tucnak/telebotarrow-up-right

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

chevron-rightrubenlagus/TelegramBotshashtag

Repository - https://github.com/rubenlagus/TelegramBotsarrow-up-right

As an example, we used the repository https://github.com/rubenlagus/TelegramBotsExamplearrow-up-right

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 sectionarrow-up-right 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

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

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