H
H
http20002021-06-30 11:59:31
Node.js
http2000, 2021-06-30 11:59:31

How does the Telegram server find my telegram bot written in node.js?

Hello!
I started to learn how to create telegram bots on node.js. I'm new to node.js, maybe I don't understand some basic principle of how this whole thing works.
I'm building a bot using the Telegraf library. I place it on my local or server and the bot starts working. At the same time, I do not specify the ip address of my computer (or server) anywhere, I do not specify anything at all. I just connect the Telegraf library, specify the token and voila - the bot works. But there is one thing I can't understand. Please explain how Telegram finds my bot running on a local or server? How does he know where to turn for an answer to a request? The user sent some message to the bot, the message went to the Telegram server, but how does the Telegram Server - my Server link work? How does the Telegram Server even know about the existence of my server and the request handler (bot) running on it? The IP address of my server may change, but the bot still works. It turns out that ip is not hardcoded anywhere, It's like it's not listed anywhere at all. I have one thought - my server sends n-th number of requests per second to the telegram server and, if a request is found there, it sends a response.
Thanks in advance for your replies!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Ternick, 2021-06-30
@http2000

It's simple)
The cart has an api, the bot has a token.
The token library accesses the api once in a while and receives json, which contains a lot of information, depending on the request, including messages that the bot receives from people, and it also responds to them through the api method.
Nothing is required of you, except for access to the Internet, with this construction of work.
There is a more complex design, a bot on webhooks, then you will need to specify your domain or ip, which the telegram will contact when new messages are received.
Documentation about this:
https://core.telegram.org/bots/api
It describes all possible methods and structures for working with api.

A
Andrey Barbolin, 2021-06-30
@dronmaxman

https://tlgrm.ru/docs/bots/api#getting-updates

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question