Skip to content

nazarovctrl/telegram-bot-spring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central

Library link in Maven Central

Maven dependency

    <dependency>
        <groupId>io.github.nazarovctrl</groupId>
        <artifactId>telegram-bot-spring</artifactId>
        <version>1.0.8</version>
    </dependency>

How to use library?

$\textcolor{red}{\textsf{*}}$ required steps

1.Add bot configuration to application.properties $\textcolor{red}{\textsf{*}}$

image_2023-08-20_21-00-24
$\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{*}}$

image_2023-08-20_20-52-11
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{*}}$

image
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{*}}$

image_2023-08-20_23-48-20
Inject MessageSender
Use execute method of MessageSender
image_2023-08-20_21-15-45

Article link(uzbek)

dasturlash.uz: https://www.dasturlash.uz/article/telegram-bot-spring

upper.uz: https://upper.uz/web/articles/167

About

Library for telegram-bot with spring.This library is designed to avoid writing repeated codes every time when creating telegrambot and to work with telegrambot easily.

Topics

Resources

License

Stars

13 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages