rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.77k stars 1.22k forks source link

How to use the library with AbilityBot? #1026

Closed TheCanay closed 2 years ago

TheCanay commented 2 years ago

Discussed in https://github.com/rubenlagus/TelegramBots/discussions/1025

Originally posted by **TheCanay** January 10, 2022 When i'm adding the @Component annotation to my bot class I got an exception: ![Exception](https://user-images.githubusercontent.com/77727402/148824316-7e46c073-9955-4e9f-afc4-b1b4f5c98109.png) Here is my bot class: ``` @Component public class MessageHandlerBot extends AbilityBot { public MessageHandlerBot() { //error occurs here! super(BOT_TOKEN, BOT_USERNAME); } //creatorId method overriding, and some abilities described } ``` Here is servicee that starts the bot: ``` public class BotService { public static void run() { try { TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class); botsApi.registerBot(new MessageHandlerBot()); } catch (TelegramApiException e) { e.printStackTrace(); } } } ``` And the main class that runs the program ``` @SpringBootApplication public class TestTelegramBotApplication { public static void main(String[] args) { SpringApplication.run(TestTelegramBotApplication.class, args); BotService.run(); } } ``` How to fix it? I need to use the @Autowired annotation from Spring boot, but it doesn't work because I can't mark the bot class as a component or service
TheCanay commented 2 years ago

To fix the issue i removed the BotService class and it's usage at main method.