-
Notifications
You must be signed in to change notification settings - Fork 610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bot api server general questions #1
Comments
|
This is list of methods from client api which can be called while logged in as bot: |
Hey, Is there an docker version to deploy bot server to any cloud that support docker? |
@Fedorus This is not true. |
@giautm No. You need to build the Bot API server yourself using provided build instructions to use. |
What about limits on sending messages and so on? As far as I know, the limits for bots using the client-api (telethon/pyrogram) are stricter than for bots using official bot-api. Does this depend on whether the |
So, briefly, as far as I understand no new methods for Bots are available? No Recent actions history, or chat members list, right? Any exclusions maybe, or someone can add them by forking and rewriting the current BotAPI server? |
Limits always was server-side and never depended on api_id or something similar.
This is false.
Yes. |
Briefly, you can run Bot API server locally now.
Yes, because that polling of those lists wouldn't work. You can't poll Recent actions for million chats in runtime. Stay tuned for the future updates, though.
|
Just a clarification: as far as I remember, using any MTProto client and logging in as a bot account, the server doesn't forbid you to send a |
@RememberTheAir |
@levlam ah, I see. One should expect mtproto/tdlib to accept just method requests strictly required to what the bot api allows to do - |
Thanks @levlam for proving quick and helpful answers here! Question: What parts of the data transfer between Telegram client, Telegram bot, and local Bot API server are going through official Telegram servers? In the previous version of the Bot API the data flows were pretty clear to me, but now I find it more difficult to see which network host is talking to whom and when. I was searching for details or maybe something like a sequence diagram, but I couldn't find related information so far. I am also asking from a data privacy perspective. So in other words: What data (and metadata) could be still read by official Telegram servers, when a local Bot API server is used? I think including such information in the readme file of this repository would be great in terms of transparency. |
Here is how I understand the network communication between the relevant hosts Telegram client (C), Telegram bot (B), local Bot API server (BAS), and official Telegram servers (OTS). Is the following outline correct? If I missed a section in official documents describing this, please let me know!
And so:
Is this description correct? Thank you! |
Sorry for the low effort diagram. This is a map of how the various involved entities interact with each other. Using your abbreviations, C never directly interact with BAS (that is, the user's Telegram app never directly connects to the server where an instance of telegram-bot-api is running). All the communications go through Telegram's servers (OTS), which forwards them to the two mtproto clients involved: the Telegram app the user C is using on their device, and the tdlib instance telegram-bot-api (BAS) is running under the hood. BAS just acts as a front-end to the Telegram API, which is way more difficult to implement than a common Rest API (which is what BAS is supposed to be - an additional level of abstraction to interact with the Telegram API as a bot account). A rest api is more familiar and friendly to developers, so it's easier to pick up. Note: in the image above, you can see only one telegram-bot-api instance, but there can be a number of these now, each one of them used by a number of bots. Also, the machine where the api is hosted can also be used to host the actual bot code, of course |
Is there anyway to get file upload/download progress? |
@RememberTheAir Thank you very much for the explanation! The diagram also helps a lot, particularly the details that the Bot API server is a |
Why using the bot server api locally should improve performance? There is just one more layer instead to communicate directly with telegram servers.. I don't get why should be better instead using bot api as usual. |
|
Absolutely agree. @RememberTheAir, @funnyflowerpot, could you, please, help me understand, what are the advantages of a local bot API server? |
The regular bot api is also an "extra" layer between bot and Telegram servers. A local bot api can improve performance due to a low ping and an extended limits. |
@gabbhack, does it mean that usual bots interact with Telegram servers via Telegram's instance of this project (global Bot API Server?)? |
Yes.
All files are stored on Telegram servers, not on bot api server, but I think bot api can cache [1] [2] files (or something else) that the bot requested to download. |
@gabbhack ok for the limitation extended with local server, but the lower ping time can be just from you and your bot api, and than you have the "ping time" between bot api server and telegram. I see only one more node that can be slow down communication, because you always speak with a bot api even in the standard configuration, but is a bot api that run on telegram server so the mtptoto communication I think it's faster than which one with local server api and telegram. |
@micheleselea Popular bots have a problem - their servers can handle a large number of requests, but bot api sends maximum of 100 simultaneous requests (see setWebhok max_connections parameter). This causes some users to get a response from the bot later, but it's not about the power of the bot's server. Local bot api can send 100,000 simultaneous requests, which may increases the bot's throughput. These results may not be relevant, but a simple query was faster with a local server. Of course, this depends on the server location: https://t.me/aiogram_ru/334063 |
ok understand, because the MTProto communication between local bot and telegram bot is not limited as direct bot API are. So the local-bot-api implementation is not restricted from the point of view of maximum number of https request? |
So basically the main advantage of this infrastrutture is that the conversion between HTTP BOT API and MTPROTO is done locally and than MTPROTO si used to "multiplex" the BOT API CALL in a already established channel. That way can be interesting to test...I'll try |
@kolayne @micheleselea From another issue:
This is where I see the advantages of a bot API server: In the diagram above we see an official Telegram server, the bot API server and bots. If the bot API server does not run on the same host as an official Telegram server, but bot API server and bots share the same host, then network communication between network hosts does not happen over HTTP, but MTProto. Compared to HTTP the MTProto protocol is most surely providing better performance for network communication with Telegram apps in most cases. And as @gabbhack said web hooks for real-time communication might be a good reason for a local bot API server too. After all HTTP and in particular an additional TLS layer (HTTPS) can provide quite some overhead. Keeping this kind of communication within a host and using MTProto's (builtin) encryption can help a lot I guess. |
I think for certain use cases the choice of using a local API server or not is an advantage for the community. That being said, a decentralised version (as I wondered about above), where Telegram client and bot API server bypass the official Telegram servers, might speed things further up considerably. There would be other advantages too, for example lower load of the official Telegram servers or improved data privacy by giving more control to the bot providers (there are risks too though to be fair). But I am not sure whether MTProto would support that change in network communication anyhow. |
|
@levlam HTTP header is |
Even though I can modify some parameter I can't change how much data can be passed trough callback_data parameter? Or can I? If not, will it be increased in near future? Thanks for reply in advance. |
You can't.
No. It should be as small as possible to minimize client traffic and 64 bytes is more than enough to store unique ID for a data of any size. |
Why should the client see and transmit the date? Why not store the original date on the telegram server and send a minimal ID to the client? When you click on the button, the server would substitute the original date. |
currently bots are limited to 50MB when they send files; could we bypass this limit by running a local API server? |
Is there any way to easily determine what datacenter our bot is bound to? |
ping api.telegram.com and you will see that is somewhere in Nederland. |
@levlam about my question on "delete" requests I posted yesterday: |
@micheleselea #1 (comment) |
ok understand, so I think that I can keep running on api.telegram.org and I'm trying the reuse https connections |
This is not about where the bot is located, but about which telegram data center it is linked to, because users from different regions are linked to different data centers. If I understand correctly, this may cause a situation when a bot linked to an Asian data center, for example, connects to api.telegram.org, which is located in Europe, and after the bot api connects to the Asian data center. |
Ok but just ping api.telegram.org from location where you have bot running and you will find where your bot is connecting to |
@micheleselea a bot using the official bot API (api.telegram.org) will always connect to some Netherlands server, because this is where the api is hosted. Then the Netherlands server will connect to the user Data Center where the bot account is stored (there are 5 across the world, as far as I remember) to pass the request to Telegram. So, let's say I'm hosting the bot in an US server, and I have to send a message to an user - the message my bot sends from my server takes this route: As far as I know (please someone correct me if I'm wrong), each Telegram account has its data stored in a specific datacenter, and it never migrates (or migrates only if some parameters are met, very unlikely nonetheless). Every bot (or supergroup or channel) an account creates, will be stored in the account's datacenter. When you create your account, Telegram picks your datacenter based on proximity (again talking from personal experience and what I'm saying might not be 100% correct). That means that if your account is atored in the US datacenter, your bots will be too, and that means that when you send a request to api.telegram.org, your request will be routed back to the US datacenter. If your account is bound to the European datacenter, which is very near where the bot api is hosted, and you host your bot in an US server, then hosting your own telegram-bot-api won't probably help that much with that, because your requests would do |
They do migrate, if their account connects consistently from a different location. If you move to Europe from the US, after some time, your account will move with you :) |
@Poolitzer No, they don't migrate currently, but this could be implemented in the future. |
Could this be implemented for bot accounts sooner rather than later? Even if we can run an instance of the bot API locally, many people may still prefer to use the official servers. |
For people using the cloud, it shouldn't make a difference. If I understood this correctly (apparently gotta be careful about my formulation here), all the bot API instances hosted by telegram (the cloud) are running on servers in the Netherlands. So changing the home DC of a bot wouldn't bypass the Netherlands if Telegram doesn't also provide cloud instances in places where the other DCs are. But now you are already requesting two things ;P
That would indeed work with local bot API instances, yes. For reasons pointed out further up in the thread. |
how many bots I can run on the local server? I've reached 1789 and start getting this error
|
As stated in #73 you should only be limited by your servers resources |
Add dockerfile and github actions script
The text was updated successfully, but these errors were encountered: