Answer the question
In order to leave comments, you need to log in
How to connect telegram bot in 2 files?
There is the first js file tbot.js , you need to connect it to 2 other files (1.js & 2.js), but if you connect via require and module.exports.tbot = bot, then 2 bots are launched and everything breaks. The first and second js files cannot be connected to each other, because they will interfere (there are requests in them and while one is making and waiting for a response, the other is just idle), are there any options?
Answer the question
In order to leave comments, you need to log in
In tbot.js, connect the bot and export the already connected bot (the object obtained when connecting the bot)
In the remaining files, require tbot and work with the already connected bot.
PS: but do not forget that all other files using the bot must be run within the same node process.
If you run them separately, it will be equivalent to launching several instances of your bot and everything will break for you again.
There are several ways to solve this problem.
1. Add a proxy server on sockets or web sockets to the bot that will contain the API for the bot functions you need. Further, from any script (including those launched separately), connect to this server and pull the functions you need from the API.
2. Make 2 or more different bots (each with its own token)))
3. As I wrote above, you run all the files that use the bot within the same process, connecting them via require in the main project file.
ZYZY: personally, I would do the third option)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question