Library link in Maven Central
<dependency>
<groupId>io.github.nazarovctrl</groupId>
<artifactId>telegram-bot-spring</artifactId>
<version>1.0.8</version>
</dependency>
required steps
1.Add bot configuration to application.properties
$\textcolor{red}{\textsf{*}}$
$\textcolor{red}{\textsf{Red line}}$ is always required field
bot.name
your telegram bot username
bot.token
your telegram bot token
bot.uri
uri to send a request to your application. If you are creating telegram bot with webhook
you need to add bot.uri
otherwise you don't need
bot.base_url
url to send reqeust to your Local Bot API Server (by default https://api.telegram.org/bot
). If you are creating telegram bot with Local Bot API Server you need to add bot.base_url
otherwise you don't need
2.Add annotation @EnableTelegramLongPollingBot or @EnableTelegramWebhookBot
$\textcolor{red}{\textsf{*}}$
Use @EnableTelegramLongPollingBot
annotation for creating telegram bot without webhook
Use @EnableTelegramWebhookBot
annotation for telegram bot with webhook
3.Inherit from @AbstractUpdateController abstract class
$\textcolor{red}{\textsf{*}}$
Override handle
method
Make your class as a bean
. In previous picture was used @Component
annonation for making the class as a bean
4.Send messages(text,media etc.) with MessageSender
$\textcolor{green}{\textsf{*}}$
Inject MessageSender
Use execute
method of MessageSender
dasturlash.uz: https://www.dasturlash.uz/article/telegram-bot-spring
upper.uz: https://upper.uz/web/articles/167