tdlib / telegram-bot-api

Telegram Bot API server
https://core.telegram.org/bots
Boost Software License 1.0
3.1k stars 590 forks source link

Issue with launching telegram api on the local server #342

Closed KaRtoHHka closed 1 year ago

KaRtoHHka commented 1 year ago

How to run Telegram IP on a local server?

I write bots and run them on my server, I did not use the common telegram api. I have a static IP running on the router, there is a domain with subdomains, ports are being redirected to the laptop server), nginx is running on the laptop, which, depending on the domain, redirects to various ports on which bots are running. Everything works

Now I want to move my server to another more powerful computer (linux), and I want to run telegram api locally so that there is less restriction on downloading files, etc

But now I'm getting errors. I got the api-id and api-hash, collected and launched the telegram api, an error appears in the bot code when trying to install the webhook

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webHookController' defined in URL [jar:file:/home/kartohhka/bots/portfolio-bot.jar!/BOOT-INF/classes!/kartohhka/bot/WebHookController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'telegramBot' defined in kartohhka.bot.appconfig.BotConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kartohhka.bot.appconfig.botapi.PortfolioTelegramBot]: Factory method 'telegramBot' threw exception; nested exception is Error executing org.telegram.telegrambots.meta.api.methods.updates.GetWebhookInfo query: [404] Not Found

Maybe someone has encountered and knows how to solve the problem

levlam commented 1 year ago

org.telegram.telegrambots.meta.api.methods.updates.GetWebhookInfo query: [404] Not Found

You seems to send the request to a wrong URL.

KaRtoHHka commented 1 year ago

You seems to send the request to a wrong URL.

I understand this, but I can't figure out where to send it, I used to create an instance of a bot, and using the execute method I installed a webhook and this request was sent to the telenramm server. Now, as it is written in the instructions, I have executed the logOut method, and now, as I believe, the bot does not know where to send the request. I think I misunderstand what needs to be added to the baseUrl variable.

levlam commented 1 year ago

Uusually you need to send requests to localhost on port 8081. You need to check documentation of the used library for the correct way to pass "http://localhost:8081" as a base URL.

KaRtoHHka commented 1 year ago

Uusually you need to send requests to localhost on port 8081. You need to check documentation of the used library for the correct way to pass "http://localhost:8081" as a base URL.

You were right, thanks, but now I get another error

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webHookController' defined in URL [jar:file:/home/kartohhka/bots/portfolio-bot.jar!/BOOT-INF/classes!/kartohhka/bot/WebHookController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'telegramBot' defined in kartohhka.bot.appconfig.BotConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kartohhka.bot.appconfig.botapi.PortfolioTelegramBot]: Factory method 'telegramBot' threw exception; nested exception is Error executing setWebook method

I used to have this when I still hadn't figured out SSL certificates. But I kind of read that if you run the server locally, then you don't need a certificate.

levlam commented 1 year ago

You need to run the server with --local argument.

KaRtoHHka commented 1 year ago

You need to run the server with --local argument.

Already done

KaRtoHHka commented 1 year ago

image

Here is the process started

levlam commented 1 year ago

Then you can use an HTTP URL as webhook. You need to check the exact error returned by setWebhook.

KaRtoHHka commented 1 year ago

Then you can use an HTTP URL as webhook. You need to check the exact error returned by setWebhook.

I feel very stupid, and I apologize if my questions are banal. I found what the error was, baseUrl should be http://your.ip.addres.s:8081/bot /, now everything starts up for me, and if I send a message to the bot, getWebHookInfo calls that there are updates. But nothing comes to the bot, but if you send a simple GET request through the browser, then I see it

image

levlam commented 1 year ago

Check that you set a correct URL in setWebhook. getWebhookInfo shows the URL and the error received while trying to send updates to it.

KaRtoHHka commented 1 year ago

I found what the problem is, I hope it will help others, because there is very little information on this topic on the web My option is for Kotlin/Java bots using Spring and Nginx. But I think it can be used for other configurations.

1)The baseUrl variable must be http://your.server.ip.address:8081/bot/ It works for Java

2) The WebHook variable should be http://your.local.ip.adress:

3) You need to logOut for the bot in the cloud with a command in the browser http://api.telegram.org/bot/logOut

Maybe I forgot to mention something, I'm ready to answer questions