I am using telethon and I have a question that how telegram knows where to send the request?
I have created a bot on telegram. When the user sends a message to the bot then how telegram knows where to redirect that message. I run my program in my local and also on a server. But in the code, we don’t mention anything about the server. But the program is working fine on it also.
Need to understand the flow.
2
Answers
Telethon uses what’s called MTProto to communicate with Telegram servers. It connects just like an actual client would (like TDesktop or Webogram, for instance). Once the connection is made, instead of using a phone number, the authentication is made with the bot token. Then, everything else is standard procedure: Ask Telegram for any new message and Telegram responds with all the messages people sent to the bot or to groups your bot is in (if you have that enabled through BotFather). To cut down on traffic, if there’s an open connection, Telegram may send updates automatically.
That’s the general process flow. For more in-depth explanation of how MTProto works, all the technical information is available on their website. The portion about updates is here: https://core.telegram.org/api/updates
Every handler have an arg, i named it here event , e.g:
This event have all information in it, text of message, message id and etc.